-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
168 lines (145 loc) · 5.39 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
cmake_minimum_required(VERSION 3.3)
cmake_policy(VERSION 3.3)
if(NOT SONATA_REPORT_VERSION)
execute_process(COMMAND git describe --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_VERSION_FAILED
OUTPUT_VARIABLE GIT_PKG_VERSION_FULL
ERROR_VARIABLE GIT_VERSION_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(GIT_VERSION_FAILED)
message(
STATUS
"Could not retrieve version from command 'git describe --tags'\n"
${GIT_VERSION_ERROR})
else()
# keep last line of command output
string(REPLACE "\n"
";"
GIT_PKG_VERSION_FULL
"${GIT_PKG_VERSION_FULL}")
list(GET GIT_PKG_VERSION_FULL -1 SONATA_REPORT_VERSION)
endif()
endif()
if(SONATA_REPORT_VERSION)
# keep MAJOR.MINOR.PATCH (PATCH being optional)
string(REGEX
REPLACE "v?([0-9]+\\.[0-9]+(\\.[0-9]+)?).*"
"\\1"
SONATA_REPORT_VERSION
"${SONATA_REPORT_VERSION}")
# Get "major.minor" from string "major.minor.version"
string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${SONATA_REPORT_VERSION})
set(SONATA_REPORT_VERSION_ABI ${CMAKE_MATCH_1})
project(libsonatareport VERSION ${SONATA_REPORT_VERSION})
else()
project(libsonatareport)
endif()
option(SONATA_REPORT_ENABLE_SUBMODULES "Use Git submodules for header-only dependencies" OFF)
option(SONATA_REPORT_ENABLE_WARNING_AS_ERROR "Compile C++ with warnings as errors" OFF)
option(SONATA_REPORT_ENABLE_MPI "Enable MPI-based execution" ON)
option(SONATA_REPORT_ENABLE_TEST "Enable tests" ON)
option(SONATA_REPORT_ENABLE_CONVERTER "Enable binary report converter" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SONATA_REPORT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(SONATA_REPORT_SRC_DIR ${PROJECT_SOURCE_DIR}/src)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ENABLE_COVERAGE ON)
set(SONATA_REPORT_ENABLE_WARNING_AS_ERROR ON)
else()
set(ENABLE_COVERAGE OFF)
endif()
if(SONATA_REPORT_ENABLE_WARNING_AS_ERROR)
set(SONATA_REPORT_COMPILE_OPTIONS -Wall -Wextra -pedantic -Werror)
else()
set(SONATA_REPORT_COMPILE_OPTIONS -Wall -Wextra -pedantic)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DSONATA_REPORT_CHECK_IME)
endif()
# =============================================================================
# Dependencies
# =============================================================================
find_package(HDF5)
if(SONATA_REPORT_ENABLE_MPI)
find_package(MPI REQUIRED)
if (MPI_FOUND)
# With MPI we prefer HDF5 parallel
set(HDF5_PREFER_PARALLEL "ON")
endif()
if (MPI_FOUND)
if (HDF5_FOUND)
if (HDF5_IS_PARALLEL)
set(SONATA_REPORT_HAVE_MPI TRUE) # For integration tests
add_definitions(-DSONATA_REPORT_HAVE_MPI)
message(STATUS "Both MPI and HDF5 parallel found, using reporting parallel implementation")
else()
message(STATUS "MPI and HDF5 found, but no parallel IO support for HDF5, using reporting serial implementation")
endif()
endif()
else()
if (HDF5_FOUND)
# Avoid NOTFOUND error
set(MPI_C_LIBRARIES "")
message(STATUS "HDF5 found, Using reporting serial implementation")
else()
message(FATAL_ERROR "No MPI or HDF5 found")
endif()
endif()
else()
if (HDF5_IS_PARALLEL)
message(FATAL_ERROR "HDF5 parallel IO found without MPI")
else()
message(STATUS "MPI disabled, using reporting serial implementation")
endif()
endif()
if (SONATA_REPORT_ENABLE_SUBMODULES)
add_subdirectory(extlib EXCLUDE_FROM_ALL)
else()
find_package(spdlog REQUIRED)
endif()
# =============================================================================
# Targets
# =============================================================================
add_subdirectory(src)
install(DIRECTORY ${SONATA_REPORT_INCLUDE_DIR}/bbp
DESTINATION include
)
install(FILES CMake/sonata-config.cmake
DESTINATION share/sonata/CMake
)
install(EXPORT sonata-targets
DESTINATION share/sonata/CMake
NAMESPACE sonata::
)
# =============================================================================
# Testing
# =============================================================================
if(SONATA_REPORT_ENABLE_TEST)
if (SONATA_REPORT_ENABLE_SUBMODULES)
include(extlib/Catch2/contrib/Catch.cmake)
else()
find_package(Catch2 REQUIRED)
include(Catch)
endif()
enable_testing()
add_subdirectory(tests)
if (ENABLE_COVERAGE)
include(CodeCoverage)
set(COVERAGE_LCOV_EXCLUDES '/usr/*' '${PROJECT_SOURCE_DIR}/include/*' '${PROJECT_SOURCE_DIR}/extlib/*')
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage
EXECUTABLE ctest
DEPENDENCIES reports_unit_tests reports_integration_test
)
endif()
endif()
# =============================================================================
# Converter of binary to SONATA reports
# =============================================================================
if(SONATA_REPORT_ENABLE_CONVERTER)
add_subdirectory(tools/converter)
endif()