forked from hpc-maths/ponio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
151 lines (123 loc) · 4.47 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# set version
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.release-please-manifest.json")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/.release-please-manifest.json" PONIO_VERSION_JSON)
string(JSON PONIO_VERSION GET "${PONIO_VERSION_JSON}" ".")
else()
message(FATAL_ERROR "File ${CMAKE_CURRENT_SOURCE_DIR}/.release-please-manifest.json not found")
endif()
# add project_options v0.33.0
# https://github.com/aminya/project_options
include(FetchContent)
set(PROJECT_OPTIONS_VERSION "v0.33.0")
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip)
FetchContent_MakeAvailable(_project_options)
include(${_project_options_SOURCE_DIR}/Index.cmake)
# install vcpkg dependencies: - should be called before defining project()
option(ENABLE_VCPKG "Use vcpkg to install dependencies" OFF)
option(ENABLE_CONAN_OPTION "Use Conan to install dependencies" OFF)
if(${ENABLE_VCPKG})
run_vcpkg()
set(VCPKG_BUILD_TYPE release)
endif()
if(${ENABLE_CONAN_OPTION})
set(ENABLE_CONAN "ENABLE_CONAN")
endif()
# enable sanitizers and static analyzers when running the tests
option(CLANG_TIDY "Activate clang-tidy" OFF)
option(CPPCHECK "Activate cppcheck" OFF)
option(IWYU "Activate include-what-you-use" OFF)
option(SANITIZERS "Activate sanitizers" OFF)
option(ENABLE_COVERAGE "Activate coverage" OFF)
project(ponio VERSION ${PONIO_VERSION} LANGUAGES CXX)
SET(FEATURES)
if(${CLANG_TIDY})
LIST(APPEND FEATURES ENABLE_CLANG_TIDY)
endif()
if(${CPPCHECK})
LIST(APPEND FEATURES ENABLE_CPPCHECK)
endif()
if(${IWYU})
LIST(APPEND FEATURES ENABLE_INCLUDE_WHAT_YOU_USE)
endif()
if(${SANITIZERS})
LIST(APPEND FEATURES ENABLE_SANITIZER_ADDRESS)
LIST(APPEND FEATURES ENABLE_SANITIZER_UNDEFINED_BEHAVIOR)
endif()
if(${COVERAGE})
LIST(APPEND FEATURES ENABLE_COVERAGE)
endif()
message(STATUS "Available FEATURES: ${FEATURES}")
project_options(
${FEATURES}
ENABLE_VS_ANALYSIS
${ENABLE_CONAN}
)
# includes
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ponio/include)
# generate butcher_methods.hpp
find_package(Python COMPONENTS Interpreter REQUIRED)
set(BUTCHER_METHODS "${INCLUDE_DIR}/ponio/runge_kutta/butcher_methods.hpp")
set(Ndigit 36)
file(GLOB json_files
"database/*.json")
set(DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ponio/doc)
option(BUILD_DOC "build the documentation algorithms page" OFF)
set(DOC_ALGO_RST "")
set(DOC_ALGO_CMD "")
if (BUILD_DOC)
set(DOC_ALGO_RST "${DOC_DIR}/source/api/algorithm.rst")
set(DOC_ALGO_CMD -d -do ${DOC_ALGO_RST})
endif()
add_custom_command(
OUTPUT ${BUTCHER_METHODS} ${DOC_ALGO_RST}
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ponio/code_generator.py ${json_files}
-o ${BUTCHER_METHODS}
--Ndigit=${Ndigit}
${DOC_ALGO_CMD}
COMMENT "Generating code..."
VERBATIM
)
add_library(ponio INTERFACE ${BUTCHER_METHODS})
target_include_directories(
ponio
INTERFACE $<BUILD_INTERFACE:${INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(ponio INTERFACE project_options project_warnings)
set_target_properties(ponio PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)
target_compile_features(ponio INTERFACE cxx_std_20)
target_include_directories(ponio INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
# find dependencies:
set(DEPENDENCIES_CONFIGURED "")
if(${ENABLE_VCPKG})
list(APPEND DEPENDENCIES_CONFIGURED hdf5)
endif()
foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED})
find_package(${DEPENDENCY} CONFIG REQUIRED)
endforeach()
set(PONIO_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/ponio/include)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
option(BUILD_TESTS "build the tests" OFF)
option(BUILD_DEMOS "build the examples" OFF)
option(BUILD_SAMURAI_DEMOS "build examples working with samurai" OFF)
if (BUILD_TESTS)
add_subdirectory(ponio/test)
endif()
if (BUILD_DEMOS)
add_subdirectory(ponio/examples)
endif()
# package the project
package_project(
TARGETS ponio project_options project_warnings
INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED}
INTERFACE_INCLUDES ${INCLUDE_DIR}
)