forked from OpenCMISS-Dependencies/cellml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
103 lines (94 loc) · 3.9 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
cmake_minimum_required(VERSION 3.1)
PROJECT(cellml-api VERSION 1.1 LANGUAGES Fortran CXX)
option(BUILD_TESTS "${PROJECT_NAME} - Build tests" ON)
option(PACKAGE_CONFIG_DIR "Directory for package config files (relative to CMAKE_INSTALL_PREFIX)" "lib/cmake")
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran)
# Is this the best place for this?
# FIXME: Need to get this to work with DYNAMIC_COMPILE
option(CELLML_USE_CSIM "${PROJECT_NAME} - Use CSim to handle CellML models." ON)
# This is our own package
if(CELLML_USE_CSIM)
find_package(CSim ${CSIM_VERSION} CONFIG REQUIRED)
else()
find_package(LIBCELLML ${LIBCELLML_VERSION} REQUIRED) # gives ccgs
find_package(LibXml2 ${LIBXML2_VERSION} REQUIRED)
endif()
# Use common include directory
set(LIBCELLML_INCLUDE_DEST include)
# Probably better to not do this as it probably overrides and external value?
if( MSVC )
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWINVER=0x0600)
elseif(NOT MINGW)
add_definitions(-DDYNAMIC_COMPILE)
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-Wall" W_FLAGS)
if (W_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
SET(cellml-api-src
src/CellMLModelDefinitionF.cpp
src/CellMLModelDefinition.cpp
src/ccgs_required_functions.cpp
)
add_library(cellml_api ${cellml-api-src})
if (CELLML_USE_CSIM)
target_compile_definitions(cellml_api PUBLIC $<BUILD_INTERFACE:CELLML_USE_CSIM>)
target_link_libraries(cellml_api PUBLIC csim)
else()
target_link_libraries(cellml_api PUBLIC ccgs xml2)
endif()
add_library(cellml_model_definition src/cellml_model_definition.f90)
target_link_libraries(cellml_model_definition INTERFACE cellml_api)
# Testing executables
if(BUILD_TESTS)
enable_testing()
add_executable(test_cellml_model_definition tests/src/test_cellml_model_definition.f90)
set_target_properties(test_cellml_model_definition PROPERTIES LINKER_LANGUAGE Fortran)
target_link_libraries(test_cellml_model_definition
cellml_api
cellml_model_definition
)
# for now, add a simple test that just checks we can load a model (with some imports)
add_test(test_cellml_model_definition test_cellml_model_definition ${CMAKE_SOURCE_DIR}/tests/input/noble-1962/experiments/free-running.xml)
#find_program(DIFF_EXEC diff)
#if (DIFF_EXEC)
# add_test(check_results ${DIFF_EXEC} ${CMAKE_SOURCE_DIR}/tests/input/test_cellml_model_definition_results results)
#endif()
endif()
# Install part
install(TARGETS cellml_model_definition
EXPORT cellml-config
DESTINATION lib
INCLUDES DESTINATION ${LIBCELLML_INCLUDE_DEST})
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/
DESTINATION ${LIBCELLML_INCLUDE_DEST}
FILES_MATCHING PATTERN "cellml_model_definition.mod"
)
install(TARGETS cellml_api EXPORT cellml-config
DESTINATION lib
INCLUDES DESTINATION include)
install(EXPORT cellml-config DESTINATION ${PACKAGE_CONFIG_DIR})
include(CMakePackageConfigHelpers)
WRITE_BASIC_PACKAGE_VERSION_FILE(${CMAKE_CURRENT_BINARY_DIR}/cellml-config-version.cmake
COMPATIBILITY AnyNewerVersion)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cellml-config-dependencies.cmake
"include(CMakeFindDependencyMacro)\r\n"
"set(${PROJECT_NAME}_IMPORT_PREFIX \${_IMPORT_PREFIX})\r\n")
if (CELLML_USE_CSIM)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/cellml-config-dependencies.cmake
"find_dependency(CSim ${CSIM_VERSION})\r\n"
)
else()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/cellml-config-dependencies.cmake
"find_dependency(LIBCELLML ${LIBCELLML_VERSION})\r\n"
"find_dependency(LibXml2 ${LIBXML2_VERSION})\r\n"
)
endif()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/cellml-config-dependencies.cmake
"set(_IMPORT_PREFIX \${${PROJECT_NAME}_IMPORT_PREFIX})"
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/cellml-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/cellml-config-dependencies.cmake
DESTINATION ${PACKAGE_CONFIG_DIR})