Path: blob/main/emulators/einstein-newton/files/patch-CMakeLists.txt
46590 views
--- CMakeLists.txt.orig 2025-12-19 16:57:53 UTC1+++ CMakeLists.txt2@@ -56,6 +56,10 @@ elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )34# Linux: nothing to do here56+elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR ${CMAKE_SYSTEM_NAME} STREQUAL "NetBSD" )7+8+ # FreeBSD and NetBSD: nothing to do here9+10elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" )1112set_property ( GLOBAL PROPERTY FIND_LIBRARY_USE_OPENBSD_VERSIONING 1 )13@@ -159,23 +163,37 @@ endif ()14# ---- Setup Google Testing15#1617+include( CTest )18+19# For Windows: Prevent overriding the parent project's compiler/linker settings20set( gtest_force_shared_crt ON CACHE BOOL "" FORCE )2122-# Check if population has already been performed23-FetchContent_GetProperties(googletest)24-if ( NOT googletest_POPULATED )25- # Fetch the content using previously declared details26- FetchContent_MakeAvailable(googletest)27+option( EINSTEIN_FETCH_GTEST "Download googletest if not found" ON )2829- # Bring the populated content into the build30- #add_subdirectory( ${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} )31-endif ()32+set( EINSTEIN_USE_GTEST OFF )33+if ( BUILD_TESTING )34+ # Try to find GTest installed on the system first.35+ find_package( GTest CONFIG QUIET )3637-enable_testing()38+ # Check if population has already been performed39+ if ( NOT GTest_FOUND AND EINSTEIN_FETCH_GTEST )40+ FetchContent_GetProperties(googletest)41+ if ( NOT googletest_POPULATED )42+ # Fetch the content using previously declared details43+ FetchContent_MakeAvailable(googletest)4445-include( GoogleTest )46+ # Bring the populated content into the build47+ #add_subdirectory( ${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} )48+ endif ()49+ endif ()5051+ if ( TARGET GTest::gtest_main OR TARGET gtest_main )52+ set( EINSTEIN_USE_GTEST ON )53+ else ()54+ message( STATUS "GoogleTest not available; tests disabled." )55+ endif ()56+endif ()57+58#59# ---- Newt/64 library ---------------------------------------------------------60#61@@ -322,11 +340,13 @@ if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )62${app_sources}63${cmake_sources}64)65- add_executable ( EinsteinTests66- ${common_sources}67- ${test_sources}68- ${cmake_sources}69- )70+ if ( EINSTEIN_USE_GTEST )71+ add_executable ( EinsteinTests72+ ${common_sources}73+ ${test_sources}74+ ${cmake_sources}75+ )76+ endif ()77if ( EINSTEIN_FLTK_FRONTEND )78add_library ( EinsteinFLGUI STATIC79${fluid_sources}80@@ -337,9 +357,11 @@ if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )81target_compile_options( Einstein PUBLIC82-Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Werror83)84- target_compile_options( EinsteinTests PUBLIC85- -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Werror86- )87+ if ( EINSTEIN_USE_GTEST )88+ target_compile_options( EinsteinTests PUBLIC89+ -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Werror90+ )91+ endif ()92if ( EINSTEIN_FLTK_FRONTEND )93target_compile_options( EinsteinFLGUI PUBLIC94-Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Werror95@@ -357,10 +379,12 @@ if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )96TARGET_OS_MAC=1 NS_BLOCK_ASSERTIONS=197)98endif ()99- target_compile_definitions ( EinsteinTests PRIVATE100- TARGET_UI_FLTK=1 NO_PORT_AUDIO NO_X11 TARGET_OS_OPENSTEP=1101- TARGET_OS_MAC=1 NS_BLOCK_ASSERTIONS=1102- )103+ if ( EINSTEIN_USE_GTEST )104+ target_compile_definitions ( EinsteinTests PRIVATE105+ TARGET_UI_FLTK=1 NO_PORT_AUDIO NO_X11 TARGET_OS_OPENSTEP=1106+ TARGET_OS_MAC=1 NS_BLOCK_ASSERTIONS=1107+ )108+ endif ()109if ( EINSTEIN_FLTK_FRONTEND )110target_compile_definitions ( EinsteinFLGUI PRIVATE111TARGET_UI_FLTK=1 NO_PORT_AUDIO NO_X11 TARGET_OS_OPENSTEP=1112@@ -390,7 +414,7 @@ if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )113$ENV{ANDROID_NDK_HOME}/sysroot/usr/include114)115endif ()116- if ( EINSTEIN_FLTK_FRONTEND )117+ if ( EINSTEIN_USE_GTEST AND EINSTEIN_FLTK_FRONTEND )118target_link_libraries ( EinsteinTests119${system_libs}120fltk::fltk121@@ -423,7 +447,7 @@ if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )122)123endif ()124125-elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" )126+elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES ".*BSD$" )127128# create the application129add_executable ( Einstein130@@ -431,11 +455,13 @@ elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CM131${app_sources}132${cmake_sources}133)134- add_executable ( EinsteinTests135- ${common_sources}136- ${test_sources}137- ${cmake_sources}138- )139+ if ( EINSTEIN_USE_GTEST )140+ add_executable ( EinsteinTests141+ ${common_sources}142+ ${test_sources}143+ ${cmake_sources}144+ )145+ endif ()146add_library ( EinsteinFLGUI STATIC147${fluid_sources}148)149@@ -443,23 +469,34 @@ elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CM150# how to compile and link151target_compile_options ( Einstein PUBLIC152-Wall -Wno-multichar -Wno-misleading-indentation -Wno-unused-result153- -Wno-missing-field-initializers -Wno-stringop-truncation # -Werror154+ -Wno-missing-field-initializers # -Werror155# Werror is disabled for testing purposes. Must reenable as soon as all Linux warnings are fixed.156)157- target_compile_options ( EinsteinTests PUBLIC158- -Wall -Wno-multichar -Wno-misleading-indentation -Wno-unused-result159- -Wno-missing-field-initializers -Wno-stringop-truncation -Werror160- )161+ if ( EINSTEIN_USE_GTEST )162+ target_compile_options ( EinsteinTests PUBLIC163+ -Wall -Wno-multichar -Wno-misleading-indentation -Wno-unused-result164+ -Wno-missing-field-initializers -Werror165+ )166+ endif ()167target_compile_options ( EinsteinFLGUI PUBLIC168-Wall -Wno-multichar -Wno-misleading-indentation -Wno-unused-result169- -Wno-missing-field-initializers -Wno-stringop-truncation -Werror170+ -Wno-missing-field-initializers -Werror171)172+ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")173+ target_compile_options(Einstein PUBLIC -Wno-stringop-truncation)174+ if ( EINSTEIN_USE_GTEST )175+ target_compile_options(EinsteinTests PUBLIC -Wno-stringop-truncation)176+ endif ()177+ target_compile_options(EinsteinFLGUI PUBLIC -Wno-stringop-truncation)178+ endif()179target_compile_definitions ( Einstein PRIVATE180TARGET_UI_FLTK=1 TARGET_OS_LINUX=1181)182- target_compile_definitions ( EinsteinTests PRIVATE183- TARGET_UI_FLTK=1 TARGET_OS_LINUX=1184- )185+ if ( EINSTEIN_USE_GTEST )186+ target_compile_definitions ( EinsteinTests PRIVATE187+ TARGET_UI_FLTK=1 TARGET_OS_LINUX=1188+ )189+ endif ()190target_compile_definitions ( EinsteinFLGUI PRIVATE191TARGET_UI_FLTK=1 TARGET_OS_LINUX=1192)193@@ -469,18 +506,20 @@ elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CM194EinsteinFLGUI195pthread196)197- target_link_libraries ( EinsteinTests198- ${system_libs}199- fltk::fltk200- EinsteinFLGUI201- pthread202- )203+ if ( EINSTEIN_USE_GTEST )204+ target_link_libraries ( EinsteinTests205+ ${system_libs}206+ fltk::fltk207+ EinsteinFLGUI208+ pthread209+ )210+ endif ()211target_link_libraries ( EinsteinFLGUI212fltk::fltk fltk::images fltk::png fltk::z213)214215- if ( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" )216- # Under OpenBSD, libffi is in ports (i.e. /usr/local) not base (i.e. /usr)217+ if ( ${CMAKE_SYSTEM_NAME} MATCHES ".*BSD$" )218+ # Under BSD, libffi is in ports (i.e. /usr/local) not base (i.e. /usr)219find_library ( ffi_lib NAMES ffi )220find_file ( ffi_incl NAMES ffi.h )221if ( ffi_lib MATCHES ".*NOTFOUND" OR ffi_incl MATCHES ".*NOTFOUND" )222@@ -493,7 +532,7 @@ elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CM223target_link_libraries ( Einstein ${ffi_lib} )224endif ()225226- # Under OpenBSD, pulseaudio is in ports (i.e. /usr/local) not base (i.e. /usr)227+ # Under BSD, pulseaudio is in ports (i.e. /usr/local) not base (i.e. /usr)228find_library ( pulse_lib NAMES pulse )229if ( pulse_lib MATCHES ".*NOTFOUND" )230message ( FATAL_ERROR "libpulse not found! " )231@@ -503,7 +542,7 @@ elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CM232target_link_libraries ( Einstein ${pulse_lib} )233endif ()234235- # Under OpenBSD, X11 is in /usr/X11R6236+ # Under BSD, find X11237include ( FindX11 )238if ( X11_FOUND )239target_include_directories ( Einstein SYSTEM PUBLIC ${X11_INCLUDE_DIR} )240@@ -527,30 +566,38 @@ elseif ( WIN32 )241${common_sources} ${app_sources} ${cmake_sources} ${data}242${CMAKE_CURRENT_BINARY_DIR}/Einstein.rc243)244- add_executable ( EinsteinTests245- ${common_sources} ${test_sources}246- )247+ if ( EINSTEIN_USE_GTEST )248+ add_executable ( EinsteinTests249+ ${common_sources} ${test_sources}250+ )251+ endif ()252add_library ( EinsteinFLGUI STATIC253${fluid_sources}254)255256# how to compile and link257target_compile_options( Einstein PUBLIC "/bigobj" )258- target_compile_options( EinsteinTests PUBLIC "/bigobj" )259+ if ( EINSTEIN_USE_GTEST )260+ target_compile_options( EinsteinTests PUBLIC "/bigobj" )261+ endif ()262target_compile_options( EinsteinFLGUI PUBLIC "/bigobj" )263if ( $<CONFIG:Debug> )264target_compile_options( Einstein PUBLIC "/ZI" )265- target_compile_options( EinsteinTests PUBLIC "/ZI" )266+ if ( EINSTEIN_USE_GTEST )267+ target_compile_options( EinsteinTests PUBLIC "/ZI" )268+ endif ()269target_compile_options( EinsteinFLGUI PUBLIC "/ZI" )270endif ()271target_compile_definitions ( Einstein PRIVATE272TARGET_UI_FLTK=1 TARGET_OS_WIN32=1273WIN32_LEAN_AND_MEAN=1 _CRT_SECURE_NO_WARNINGS=1274)275- target_compile_definitions ( EinsteinTests PRIVATE276- TARGET_UI_FLTK=1 TARGET_OS_WIN32=1277- WIN32_LEAN_AND_MEAN=1 _CRT_SECURE_NO_WARNINGS=1278- )279+ if ( EINSTEIN_USE_GTEST )280+ target_compile_definitions ( EinsteinTests PRIVATE281+ TARGET_UI_FLTK=1 TARGET_OS_WIN32=1282+ WIN32_LEAN_AND_MEAN=1 _CRT_SECURE_NO_WARNINGS=1283+ )284+ endif ()285target_compile_definitions ( EinsteinFLGUI PRIVATE286TARGET_UI_FLTK=1 TARGET_OS_WIN32=1287WIN32_LEAN_AND_MEAN=1 _CRT_SECURE_NO_WARNINGS=1288@@ -562,17 +609,19 @@ elseif ( WIN32 )289winmm290gdiplus291)292- target_link_libraries ( EinsteinTests293- ${system_libs}294- fltk::fltk295- EinsteinFLGUI296- gdiplus297- )298- target_link_libraries ( EinsteinTests299- ${system_libs}300- fltk::fltk301- gdiplus302- )303+ if ( EINSTEIN_USE_GTEST )304+ target_link_libraries ( EinsteinTests305+ ${system_libs}306+ fltk::fltk307+ EinsteinFLGUI308+ gdiplus309+ )310+ target_link_libraries ( EinsteinTests311+ ${system_libs}312+ fltk::fltk313+ gdiplus314+ )315+ endif ()316target_link_libraries ( EinsteinFLGUI317fltk::fltk fltk::images fltk::png fltk::z318)319@@ -634,11 +683,13 @@ target_include_directories (320${CMAKE_SOURCE_DIR}321${FLTK_INCLUDE_DIRS}322)323-target_include_directories (324- EinsteinTests PUBLIC325- ${CMAKE_SOURCE_DIR}326- ${FLTK_INCLUDE_DIRS}327-)328+if ( EINSTEIN_USE_GTEST )329+ target_include_directories (330+ EinsteinTests PUBLIC331+ ${CMAKE_SOURCE_DIR}332+ ${FLTK_INCLUDE_DIRS}333+ )334+endif ()335if ( EINSTEIN_FLTK_FRONTEND )336target_include_directories (337EinsteinFLGUI PUBLIC338@@ -648,14 +699,27 @@ target_compile_definitions ( Einstein PUBLIC "$<$<CONF339endif ()340341target_compile_definitions ( Einstein PUBLIC "$<$<CONFIG:DEBUG>:_DEBUG>" USE_CMAKE )342-target_compile_definitions ( EinsteinTests PUBLIC "$<$<CONFIG:DEBUG>:_DEBUG>" USE_CMAKE )343+if ( EINSTEIN_USE_GTEST )344+ target_compile_definitions ( EinsteinTests PUBLIC "$<$<CONFIG:DEBUG>:_DEBUG>" USE_CMAKE )345+endif ()346if ( EINSTEIN_FLTK_FRONTEND )347target_compile_definitions ( EinsteinFLGUI PUBLIC "$<$<CONFIG:DEBUG>:_DEBUG>" USE_CMAKE )348endif ()349350-target_link_libraries ( EinsteinTests gtest_main )351+if ( EINSTEIN_USE_GTEST )352+ include( GoogleTest )353+ if ( TARGET GTest::gtest_main )354+ target_link_libraries ( EinsteinTests GTest::gtest_main )355+ elseif ( TARGET gtest_main )356+ target_link_libraries ( EinsteinTests gtest_main )357+ else ()358+ message ( STATUS "GoogleTest found without a gtest_main target; tests disabled." )359+ endif ()360+endif ()361362-gtest_discover_tests ( EinsteinTests )363+if ( EINSTEIN_USE_GTEST AND ( TARGET GTest::gtest_main OR TARGET gtest_main ) )364+ gtest_discover_tests ( EinsteinTests )365+endif ()366367endif ()368369370371