|
| 1 | +# Build AMICI model |
| 2 | +cmake_minimum_required(VERSION 3.22) |
| 3 | +cmake_policy(VERSION 3.22...3.31) |
| 4 | + |
| 5 | +project(model_dirac_py) |
| 6 | + |
| 7 | +set(CMAKE_CXX_STANDARD 17) |
| 8 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 9 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 10 | + |
| 11 | +include(CheckCXXCompilerFlag) |
| 12 | +set(MY_CXX_FLAGS -Wall -Wno-unused-function -Wno-unused-variable) |
| 13 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 14 | + list(APPEND MY_CXX_FLAGS -Wno-unused-but-set-variable) |
| 15 | +endif() |
| 16 | +foreach(flag ${MY_CXX_FLAGS}) |
| 17 | + unset(CUR_FLAG_SUPPORTED CACHE) |
| 18 | + check_cxx_compiler_flag(${flag} CUR_FLAG_SUPPORTED) |
| 19 | + if(${CUR_FLAG_SUPPORTED}) |
| 20 | + string(APPEND CMAKE_CXX_FLAGS " ${flag}") |
| 21 | + endif() |
| 22 | +endforeach() |
| 23 | + |
| 24 | +if(DEFINED ENV{AMICI_CXXFLAGS}) |
| 25 | + message(STATUS "Appending flags from AMICI_CXXFLAGS: $ENV{AMICI_CXXFLAGS}") |
| 26 | + add_compile_options("$ENV{AMICI_CXXFLAGS}") |
| 27 | +endif() |
| 28 | +if(DEFINED ENV{AMICI_LDFLAGS}) |
| 29 | + message(STATUS "Appending flags from AMICI_LDFLAGS: $ENV{AMICI_LDFLAGS}") |
| 30 | + link_libraries("$ENV{AMICI_LDFLAGS}") |
| 31 | +endif() |
| 32 | + |
| 33 | +find_package(Amici 0.33.0 REQUIRED HINTS |
| 34 | + ${CMAKE_CURRENT_LIST_DIR}/../../build) |
| 35 | +message(STATUS "Found AMICI ${Amici_DIR}") |
| 36 | +set_target_properties(Upstream::amici PROPERTIES |
| 37 | + MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo;Release; |
| 38 | + MAP_IMPORTED_CONFIG_RELEASE Release |
| 39 | + MAP_IMPORTED_CONFIG_DEBUG Debug;RelWithDebInfo;) |
| 40 | + |
| 41 | +# Debug build? |
| 42 | +if("$ENV{ENABLE_AMICI_DEBUGGING}" OR "$ENV{ENABLE_GCOV_COVERAGE}") |
| 43 | + add_compile_options(-UNDEBUG) |
| 44 | + if(MSVC) |
| 45 | + add_compile_options(-DEBUG) |
| 46 | + else() |
| 47 | + add_compile_options(-O0 -g) |
| 48 | + endif() |
| 49 | +endif() |
| 50 | + |
| 51 | +# coverage options |
| 52 | +if($ENV{ENABLE_GCOV_COVERAGE}) |
| 53 | + string(APPEND CMAKE_CXX_FLAGS_DEBUG " --coverage") |
| 54 | + string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG " --coverage") |
| 55 | +endif() |
| 56 | + |
| 57 | +set(MODEL_DIR ${CMAKE_CURRENT_LIST_DIR}) |
| 58 | + |
| 59 | +set(SRC_LIST_LIB Jy.cpp |
| 60 | +Jy.h |
| 61 | +create_splines.cpp |
| 62 | +dJydsigma.cpp |
| 63 | +dJydy.cpp |
| 64 | +dJydy.h |
| 65 | +deltaqB.cpp |
| 66 | +deltasx.cpp |
| 67 | +deltax.cpp |
| 68 | +dxdotdp_explicit.cpp |
| 69 | +dxdotdp_explicit.h |
| 70 | +dxdotdx_explicit.cpp |
| 71 | +dxdotdx_explicit.h |
| 72 | +dydx.cpp |
| 73 | +h.h |
| 74 | +model_dirac_py.cpp |
| 75 | +model_dirac_py.h |
| 76 | +my.h |
| 77 | +p.h |
| 78 | +root.cpp |
| 79 | +sigmay.cpp |
| 80 | +sigmay.h |
| 81 | +stau.cpp |
| 82 | +stau.h |
| 83 | +sx.h |
| 84 | +w.h |
| 85 | +wrapfunctions.cpp |
| 86 | +wrapfunctions.h |
| 87 | +x.h |
| 88 | +xB.h |
| 89 | +x_old.h |
| 90 | +x_rdata.cpp |
| 91 | +x_rdata.h |
| 92 | +x_solver.cpp |
| 93 | +x_solver.h |
| 94 | +xdot.cpp |
| 95 | +xdot.h |
| 96 | +xdot_old.h |
| 97 | +y.cpp |
| 98 | +y.h ${MODEL_DIR}/wrapfunctions.cpp) |
| 99 | + |
| 100 | +add_library(${PROJECT_NAME} ${SRC_LIST_LIB}) |
| 101 | + |
| 102 | +# ${PROJECT_NAME} might already be "model" |
| 103 | +if(NOT TARGET model) |
| 104 | + add_library(model ALIAS ${PROJECT_NAME}) |
| 105 | +endif() |
| 106 | + |
| 107 | +# Some special functions require boost |
| 108 | +# |
| 109 | +# TODO: set some flag during code generation whether the given model requires |
| 110 | +# boost. for now, try to find it, add include directories and link against it. |
| 111 | +# let the compiler/linker error if it is required but not found |
| 112 | +find_package(Boost) |
| 113 | + |
| 114 | +target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") |
| 115 | + |
| 116 | +target_link_libraries( |
| 117 | + ${PROJECT_NAME} |
| 118 | + PUBLIC Upstream::amici |
| 119 | + PRIVATE $<$<BOOL:${Boost_FOUND}>:Boost::boost>) |
| 120 | + |
| 121 | +if(NOT "${AMICI_PYTHON_BUILD_EXT_ONLY}") |
| 122 | + set(SRC_LIST_EXE main.cpp) |
| 123 | + add_executable(simulate_${PROJECT_NAME} ${SRC_LIST_EXE}) |
| 124 | + target_link_libraries(simulate_${PROJECT_NAME} ${PROJECT_NAME}) |
| 125 | +endif() |
| 126 | + |
| 127 | +# SWIG |
| 128 | +option(ENABLE_SWIG "Build swig/python library?" ON) |
| 129 | +if(ENABLE_SWIG) |
| 130 | + add_subdirectory(swig) |
| 131 | +endif() |
| 132 | + |
| 133 | +# <Export cmake configuration> |
| 134 | +include(GNUInstallDirs) |
| 135 | +install( |
| 136 | + TARGETS ${PROJECT_NAME} |
| 137 | + EXPORT ${PROJECT_NAME}Targets |
| 138 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 139 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 140 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 141 | + INCLUDES |
| 142 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 143 | + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 144 | +export( |
| 145 | + EXPORT ${PROJECT_NAME}Targets |
| 146 | + FILE ${PROJECT_NAME}Config.cmake |
| 147 | + NAMESPACE Upstream::) |
| 148 | +# </Export cmake configuration> |
0 commit comments