From b9e00906e6ed580eb0e16bad0221db49c6df7033 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 9 Feb 2024 21:26:19 +0100 Subject: [PATCH] Modern CMake, next try --- .github/workflows/macos_fltk.yml | 25 ------- .github/workflows/mswindows.yml | 18 ----- .github/workflows/ubuntu.yml | 25 ------- CMakeLists.txt | 116 +++++++++++++++---------------- 4 files changed, 58 insertions(+), 126 deletions(-) diff --git a/.github/workflows/macos_fltk.yml b/.github/workflows/macos_fltk.yml index e57b17d6..ae7c84c5 100644 --- a/.github/workflows/macos_fltk.yml +++ b/.github/workflows/macos_fltk.yml @@ -18,31 +18,6 @@ jobs: run: brew install clang-format - name: Get sources uses: actions/checkout@v4 - - name: Get FLTK - uses: actions/checkout@v4 - with: - repository: fltk/fltk - path: fltk - - name: Get newt64 - uses: actions/checkout@v4 - with: - repository: MatthiasWM/NEWT64 - path: newt64 - - name: Compile FLTK - run: | - cmake -S fltk -B fltk/build \ - -D FLTK_USE_SYSTEM_LIBJPEG=Off \ - -D FLTK_USE_SYSTEM_ZLIB=Off \ - -D FLTK_USE_SYSTEM_LIBPNG=Off \ - -D FLTK_BUILD_TEST=Off \ - -D FLTK_BUILD_GL=Off - cmake --build fltk/build - sudo cmake --install fltk/build - - name: Compile newt64 - run: | - cmake -S newt64 -B newt64/build - cmake --build newt64/build - sudo cmake --install newt64/build - name: Configure Einstein run: | cmake -S . -B _Build_/Makefiles diff --git a/.github/workflows/mswindows.yml b/.github/workflows/mswindows.yml index 33da88c6..48c8bd71 100644 --- a/.github/workflows/mswindows.yml +++ b/.github/workflows/mswindows.yml @@ -16,24 +16,6 @@ jobs: steps: - name: Get sources uses: actions/checkout@v4 - - name: Get FLTK - uses: actions/checkout@v4 - with: - repository: fltk/fltk - path: fltk - - name: Get newt64 - uses: actions/checkout@v4 - with: - repository: MatthiasWM/NEWT64 - path: newt64 - - name: Compile FLTK - run: | - cmake -S fltk -B fltk/build -D FLTK_USE_SYSTEM_LIBJPEG=Off -D FLTK_USE_SYSTEM_ZLIB=Off -D FLTK_USE_SYSTEM_LIBPNG=Off -D FLTK_BUILD_TEST=Off -D FLTK_BUILD_GL=Off -D CMAKE_BUILD_TYPE=Release - cmake --build fltk/build --config Release - - name: Compile newt64 - run: | - cmake -S newt64 -B newt64/build -D CMAKE_BUILD_TYPE=Release - cmake --build newt64/build --config Release - name: Configure run: | cmake -S . -B _Build_/Makefiles -D CMAKE_BUILD_TYPE=Release diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 0d367369..90efd983 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -23,31 +23,6 @@ jobs: sudo apt-get install clang-format-13 - name: Get sources uses: actions/checkout@v4 - - name: Get FLTK - uses: actions/checkout@v4 - with: - repository: fltk/fltk - path: fltk - - name: Get newt64 - uses: actions/checkout@v4 - with: - repository: MatthiasWM/NEWT64 - path: newt64 - - name: Compile FLTK - run: | - cmake -S fltk -B fltk/build \ - -D FLTK_USE_SYSTEM_LIBJPEG=Off \ - -D FLTK_USE_SYSTEM_ZLIB=Off \ - -D FLTK_USE_SYSTEM_LIBPNG=Off \ - -D FLTK_BUILD_TEST=Off \ - -D FLTK_BUILD_GL=Off - cmake --build fltk/build - sudo cmake --install fltk/build - - name: Compile newt64 - run: | - cmake -S newt64 -B newt64/build - cmake --build newt64/build - sudo cmake --install newt64/build - name: Configure Einstein run: | cmake -S . -B _Build_/Makefiles diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ec68123..3c498a4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,29 +27,6 @@ include( CheckFunctionExists ) include( CheckIncludeFile ) include( FetchContent ) -# ---- Setup Google Testing - -FetchContent_Declare ( - googletest - URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set( gtest_force_shared_crt ON CACHE BOOL "" FORCE ) - -# Check if population has already been performed -FetchContent_GetProperties(googletest) -if ( NOT googletest_POPULATED ) - # Fetch the content using previously declared details - FetchContent_Populate(googletest) - - # Bring the populated content into the build - add_subdirectory( ${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} ) -endif () - -enable_testing() - -include( GoogleTest ) - # ---- Configuration per platform if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) @@ -86,56 +63,78 @@ endif () # # ==== External Dependencies =================================================== # -# ---- Newt/64 library --------------------------------------------------------- +# ---- Declare dependencies on outside content # -if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" ) - # Generates Newt64_FOUND, Newt64_DIR - find_package( Newt64 CONFIG HINTS ${CMAKE_CURRENT_SOURCE_DIR}/newt64/build ) -endif() +FetchContent_Declare ( + googletest + URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip +) -find_library ( newt64_lib NAMES newt64 - HINTS - ${CMAKE_CURRENT_SOURCE_DIR}/newt64/build/Release - ${CMAKE_CURRENT_SOURCE_DIR}/newt64/build/Debug - ${CMAKE_CURRENT_SOURCE_DIR}/newt64/build +FetchContent_Declare( + FLTK + GIT_REPOSITORY https://github.com/fltk/fltk + GIT_TAG master + GIT_SHALLOW TRUE ) -find_file( newt64_incl NAMES NewtCore.h PATH_SUFFIXES newt64 HINTS ${CMAKE_CURRENT_SOURCE_DIR}/newt64/src/newt_core/incs ) -if ( newt64_lib MATCHES ".*NOTFOUND" OR newt64_incl MATCHES ".*NOTFOUND" ) - message( WARNING "Newt64 not found!" ) - set( NEWT64_FOUND false ) -else () - set( NEWT64_FOUND true ) - get_filename_component( newt64_lib_path ${newt64_lib} DIRECTORY ) - get_filename_component( newt64_incl_path ${newt64_incl} DIRECTORY ) - message( STATUS "Newt64 found in " ${newt64_lib_path} ) -endif () +FetchContent_Declare( + NEWT64 + GIT_REPOSITORY https://github.com/MatthiasWM/NEWT64 + GIT_TAG master + GIT_SHALLOW TRUE +) # -# ---- FLTK library ------------------------------------------------------------ +# ---- Setup Google Testing # -# TODO: update this to automatically download and build in .../Einstein/fltk -set( FLTK_SKIP_OPENGL true ) -find_program( LOCAL_FLTK_FLUID_EXECUTABLE fluid - HINTS - ${CMAKE_SOURCE_DIR}/fltk/build/bin/Release - ${CMAKE_SOURCE_DIR}/fltk/build/bin/Debug - ${CMAKE_SOURCE_DIR}/fltk/build/bin -) -find_package( FLTK REQUIRED NO_MODULE HINTS ${CMAKE_SOURCE_DIR}/fltk/build ) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set( gtest_force_shared_crt ON CACHE BOOL "" FORCE ) -if ( ${LOCAL_FLTK_FLUID_EXECUTABLE} MATCHES ".*NOTFOUND" ) - message( WARNING "Fluid (FLTK User Interface Designer) not found!" ) -else () - message( STATUS "Fluid (FLTK User Interface Designer) found at " ${LOCAL_FLTK_FLUID_EXECUTABLE}) +# Check if population has already been performed +FetchContent_GetProperties(googletest) +if ( NOT googletest_POPULATED ) + # Fetch the content using previously declared details + FetchContent_Populate(googletest) + + # Bring the populated content into the build + add_subdirectory( ${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} ) endif () +enable_testing() + +include( GoogleTest ) + +# +# ---- Newt/64 library --------------------------------------------------------- +# + +message(STATUS "Downloading and configuring NEWT64 if necessary, please wait...") +FetchContent_MakeAvailable(NEWT64) +message(STATUS "Downloading and configuring NEWT64 - done.") +# Newt64_BINARY_DIR +set( NEWT64_FOUND true ) + +# +# ---- FLTK library ------------------------------------------------------------ +# + +message(STATUS "Downloading and configuring FLTK if necessary, please wait...") +set( FLTK_USE_SYSTEM_LIBJPEG OFF ) +set( FLTK_USE_SYSTEM_ZLIB OFF ) +set( FLTK_USE_SYSTEM_LIBPNG OFF ) +set( FLTK_BUILD_TEST OFF ) +set( FLTK_BUILD_GL OFF ) +set( FLTK_BUILD_FORMS OFF ) +set( FLTK_BUILD_FLTK_OPTIONS OFF ) +FetchContent_MakeAvailable(FLTK) +message(STATUS "Downloading and configuring FLTK - done.") + function ( build_with_fluid name dir ) add_custom_command ( WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${dir}" - COMMAND ${LOCAL_FLTK_FLUID_EXECUTABLE} -c ${name}.fl + COMMAND fltk::fluid -c ${name}.fl DEPENDS "${CMAKE_SOURCE_DIR}/${dir}/${name}.fl" DEPENDS "${ARGN}" OUTPUT "${CMAKE_SOURCE_DIR}/${dir}/${name}.cpp" @@ -238,6 +237,7 @@ if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" ) target_link_libraries ( Einstein ${system_libs} fltk::fltk fltk::images fltk::png fltk::z + libnewt64 pthread "-framework AddressBook" "-framework AudioUnit"