Skip to content
Snippets Groups Projects
Commit e165c23c authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

Clean up CMake targets

parent a9d57df7
No related branches found
No related tags found
1 merge request!49Resolve "Finish installation and usage instruction on the documentation"
......@@ -2,19 +2,11 @@ cmake_minimum_required(VERSION 3.13)
project(dune-copasi CXX)
cmake_policy(SET CMP0074 NEW)
if(POLICY CMP0087)
cmake_policy(SET CMP0087 OLD)
endif()
# find dune-common
find_package(dune-common REQUIRED)
# make sure to find cmake modules
list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/cmake/modules"
"${dune-common_MODULE_PATH}"
)
# include macros for dune projects
include(DuneMacros)
# define cmake options
option(DUNE_COPASI_SD_EXECUTABLE
"Build SingleDomain executable by default"
OFF
......@@ -23,7 +15,6 @@ option(DUNE_COPASI_SD_LIBRARY
"Include precompiled SingleDomain objects in dune-copasi library (optional)"
${DUNE_COPASI_SD_EXECUTABLE}
)
option(DUNE_COPASI_MD_EXECUTABLE
"Build MultiDimain executable by default"
ON
......@@ -32,18 +23,21 @@ option(DUNE_COPASI_MD_LIBRARY
"Include precompiled MultiDimain objects in dune-copasi library (optional)"
${DUNE_COPASI_MD_EXECUTABLE}
)
option(DUNE_COPASI_COMPILE_3D
"Compile 3D cases in libraries and executables"
OFF
)
# make sure to find our own cmake modules
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
# find dependencies
find_package(dune-common REQUIRED)
find_package(muparser REQUIRED)
find_package(TIFF REQUIRED)
find_package(Filesystem)
# if Filesystem is not found, using a fallback is mandatory
# if Filesystem is not found, using a fallback is mandatory, otherwise, optional
include(CMakeDependentOption)
cmake_dependent_option(USE_FALLBACK_FILESYSTEM
"Use bundled std::filesystem alternative (enable this for macOS older than 10.15)" OFF
......@@ -72,34 +66,37 @@ if(USE_FALLBACK_FILESYSTEM)
endif()
endif()
# start a dune project with information from dune.module
# include macros for dune projects
list(APPEND CMAKE_MODULE_PATH "${dune-common_MODULE_PATH}")
include(DuneMacros)
# start a dune project with information from dune.module, and find dune dependencies
dune_project()
# main target
# create main target
add_library(dune-copasi)
set_target_properties(dune-copasi PROPERTIES LIBRARY_OUTPUT_NAME dunecopasi)
set_target_properties(dune-copasi PROPERTIES ARCHIVE_OUTPUT_NAME dunecopasi)
# add dune dependencies to this target
dune_target_enable_all_packages(dune-copasi)
# add dependencies
target_link_libraries(dune-copasi PUBLIC ${DUNE_LIBS} TIFF::TIFF muparser::muparser)
if (DUNE_COPASI_COMPILE_3D)
target_compile_definitions(dune-copasi PUBLIC DUNE_COPASI_COMPILE_3D)
endif()
# include header files
add_subdirectory(dune)
# include main library set up
add_subdirectory(lib)
# source files for final libraries and executables
add_subdirectory(src)
# documentation files
add_subdirectory(doc)
# finalize the dune project: Generate and install config.h, cmake target and version file
finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
target_compile_definitions(dune-copasi INTERFACE HAVE_DUNE_COPASI_CONFIG_H)
# main library is completely set up, define a read only 'dune::' alias for our main target
add_library(dune::copasi ALIAS dune-copasi)
# install generated config in build and install directories
file(COPY "${CMAKE_CURRENT_BINARY_DIR}/config.h"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/dune/copasi"
......@@ -130,7 +127,7 @@ install(TARGETS dune-copasi
COMPONENT Development
)
# export targets to be used with the installed package
# export targets to be used with installed tree
install(EXPORT dune-copasi-targets
FILE dune-copasi-targets.cmake
NAMESPACE dune-copasi::
......@@ -138,15 +135,12 @@ install(EXPORT dune-copasi-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dune-copasi"
)
# export targets to be used with build directories
# export targets to be used with build tree
export(EXPORT dune-copasi-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/dune-copasi-targets.cmake"
NAMESPACE dune-copasi::
)
# 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
include(CTest)
if(BUILD_TESTING)
......
include(GNUInstallDirs)
target_include_directories(dune-copasi
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
)
# add dune dependencies to main target
dune_target_enable_all_packages(dune-copasi)
# add dependencies
target_link_libraries(dune-copasi PUBLIC ${DUNE_LIBS} TIFF::TIFF muparser::muparser)
if (DUNE_COPASI_COMPILE_3D)
target_compile_definitions(dune-copasi PUBLIC DUNE_COPASI_COMPILE_3D)
endif()
# 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(dune-copasi PUBLIC std::filesystem)
endif()
unset(EXPORTED_DEVELOPMENT_TARGETS)
# define, link and install auxiliary develpment targets for dune-copasi
unset(AUX_DEVELOPMENT_TARGETS)
# SingleDomain library
add_library(singledomain-lib
......@@ -24,7 +41,7 @@ if(DUNE_COPASI_SD_LIBRARY)
set_target_properties(singledomain-lib PROPERTIES EXCLUDE_FROM_ALL OFF)
target_link_libraries(dune-copasi INTERFACE singledomain-lib)
target_compile_definitions(dune-copasi INTERFACE DUNE_COPASI_SD_LIBRARY)
list(APPEND EXPORTED_DEVELOPMENT_TARGETS singledomain-lib)
list(APPEND AUX_DEVELOPMENT_TARGETS singledomain-lib)
endif()
# MultiDomain library
......@@ -45,21 +62,11 @@ if(DUNE_COPASI_MD_LIBRARY)
set_target_properties(multidomain-lib PROPERTIES EXCLUDE_FROM_ALL OFF)
target_link_libraries(dune-copasi INTERFACE multidomain-lib)
target_compile_definitions(dune-copasi INTERFACE DUNE_COPASI_MD_LIBRARY)
list(APPEND EXPORTED_DEVELOPMENT_TARGETS multidomain-lib)
endif()
# 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(dune-copasi PUBLIC std::filesystem)
list(APPEND AUX_DEVELOPMENT_TARGETS multidomain-lib)
endif()
# install development targets
install(TARGETS ${EXPORTED_DEVELOPMENT_TARGETS}
install(TARGETS ${AUX_DEVELOPMENT_TARGETS}
EXPORT dune-copasi-targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT Libraries
......
include(GNUInstallDirs)
# add source files to main library
target_sources(dune-copasi
PRIVATE
dune/copasi/model/base.cc
)
# SingleDomain executable
add_executable(singledomain-exec EXCLUDE_FROM_ALL "${CMAKE_CURRENT_SOURCE_DIR}/dune_copasi_sd.cc")
# set up single-domain executable
add_executable(singledomain-exec EXCLUDE_FROM_ALL dune_copasi_sd.cc)
target_link_libraries(singledomain-exec PRIVATE dune-copasi)
if(DUNE_COPASI_SD_EXECUTABLE)
set_target_properties(singledomain-exec PROPERTIES EXCLUDE_FROM_ALL OFF)
......@@ -18,8 +19,8 @@ if(DUNE_COPASI_SD_EXECUTABLE)
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")
# set up multi-domain executable
add_executable(multidomain-exec EXCLUDE_FROM_ALL dune_copasi_md.cc)
target_link_libraries(multidomain-exec PRIVATE dune-copasi)
if(DUNE_COPASI_MD_EXECUTABLE)
set_target_properties(multidomain-exec PROPERTIES EXCLUDE_FROM_ALL OFF)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment