diff --git a/CMakeLists.txt b/CMakeLists.txt index f48bf9373d14b886b7a26a799d7c377e8351da46..1c9fdfa2a0eafa04fdc15c29f56bd3be095bed90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,6 @@ list(APPEND CMAKE_MODULE_PATH # include macros for dune projects include(DuneMacros) -option(USE_FALLBACK_FILESYSTEM - "Use bundled std::filesystem alternative (enable this for macOS older than 10.15)" - OFF -) - option(DUNE_COPASI_SD_EXECUTABLE "Build SingleDomain executable by default" OFF @@ -47,8 +42,34 @@ option(DUNE_COPASI_COMPILE_3D find_package(muparser REQUIRED) find_package(TIFF REQUIRED) find_package(Filesystem) + +# if Filesystem is not found, using a fallback is mandatory +include(CMakeDependentOption) +cmake_dependent_option(USE_FALLBACK_FILESYSTEM + "Use bundled std::filesystem alternative (enable this for macOS older than 10.15)" OFF + "Filesystem_FOUND" ON +) + if(USE_FALLBACK_FILESYSTEM) + # let's use ghc_filesystem find_package(ghc_filesystem) + + # ... library not installed, we provide a fallback + if (NOT ghc_filesystem_FOUND) + include(FetchContent) + message("-- Declaring GHC Filesystem") + FetchContent_Declare( + ghc_filesystem + GIT_REPOSITORY https://github.com/gulrak/filesystem + GIT_TAG v1.5.0 + ) + + if(NOT ghc_filesystem_POPULATED) + message("-- Populating GHC Filesystem") + FetchContent_Populate(ghc_filesystem) + add_subdirectory("${ghc_filesystem_SOURCE_DIR}" "${ghc_filesystem_BINARY_DIR}") + endif() + endif() endif() # start a dune project with information from dune.module @@ -123,7 +144,7 @@ export(EXPORT dune-copasi-targets NAMESPACE dune-copasi:: ) -# set a read only alias for our main target +# library is set up, define a read only 'dune::' alias for our main target add_library(dune::copasi ALIAS dune-copasi) # include tests as a sub project diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index bcb53a54f3dfc66ec8c0629eb7a8d02337b2425c..2e779932f0b13d5fc6ff7facb46c90a7a615194e 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -48,56 +48,16 @@ if(DUNE_COPASI_MD_LIBRARY) list(APPEND EXPORTED_DEVELOPMENT_TARGETS multidomain-lib) endif() -# Set up filesystem -add_library(filesystem INTERFACE) -list(APPEND EXPORTED_DEVELOPMENT_TARGETS filesystem) - -# where do we get it from? -if(USE_FALLBACK_FILESYSTEM AND ghc_filesystem_FOUND) - # ... easy, link to the fallback directly - target_link_libraries(filesystem INTERFACE ghcFilesystem::ghc_filesystem) -elseif(USE_FALLBACK_FILESYSTEM) - # ... library not installed, we provide a fallback - include(FetchContent) - message("-- Declaring GHC Filesystem") - FetchContent_Declare( - ghc_filesystem - GIT_REPOSITORY https://github.com/gulrak/filesystem - GIT_TAG v1.4.0 - ) - - if(NOT ghc_filesystem_POPULATED) - message("-- Populating GHC Filesystem") - - FetchContent_Populate(ghc_filesystem) - add_subdirectory("${ghc_filesystem_SOURCE_DIR}" "${ghc_filesystem_BINARY_DIR}") - - file(GLOB GHC_HEADERS "${ghc_filesystem_SOURCE_DIR}/include/ghc/*.hpp") - install(FILES ${GHC_HEADERS} - COMPONENT Development - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ghc" - ) - endif() - - target_include_directories(filesystem INTERFACE - $<BUILD_INTERFACE:${ghc_filesystem_SOURCE_DIR}/include> - $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> - ) - - target_compile_definitions(filesystem INTERFACE DUNE_COPASI_USE_FALLBACK_FILESYSTEM) -elseif(NOT Filesystem_FOUND) - # ... heuston we have a problem. It makes no sense to continue! - message(FATAL_ERROR - "Support for C++ 17 filesystem was not found. Try setting up a " - "fallback implementation by adding the flag USE_FALLBACK_FILESYSTEM=ON") +# Set up filesystem. Where do we get it from? +if(USE_FALLBACK_FILESYSTEM) + # and add ghc_filesystem to our filesystem target + target_link_libraries(dune-copasi PUBLIC ghcFilesystem::ghc_filesystem) + target_compile_definitions(dune-copasi PUBLIC DUNE_COPASI_USE_FALLBACK_FILESYSTEM) else() # ... else we don't need a back up. Link agaist standard library - target_link_libraries(filesystem INTERFACE std::filesystem) + target_link_libraries(dune-copasi PUBLIC std::filesystem) endif() -# main library consumes filesystem definitions -target_link_libraries(dune-copasi PUBLIC filesystem) - # install development targets install(TARGETS ${EXPORTED_DEVELOPMENT_TARGETS} EXPORT dune-copasi-targets diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ccd78c6b5bcac1fa076d54732b1aaf216c36b0a0..93bf919749e32e3307fa59ce21edb686f08693ef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,6 @@ endif() set_property(TARGET singledomain-exec PROPERTY RUNTIME_OUTPUT_NAME dune-copasi-sd) # MultiDomain executable - add_executable(multidomain-exec EXCLUDE_FROM_ALL "${CMAKE_CURRENT_SOURCE_DIR}/dune_copasi_md.cc") target_link_libraries(multidomain-exec PRIVATE dune-copasi) if(DUNE_COPASI_MD_EXECUTABLE)