-
Notifications
You must be signed in to change notification settings - Fork 60
/
CMakeLists.txt
216 lines (178 loc) · 8.76 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# HSF recommends 3.3 to support C/C++ compile features for C/C++11 across all
# platforms
cmake_minimum_required(VERSION 3.12)
#--- Project name --------------------------------------------------------------
project(podio)
#--- Version -------------------------------------------------------------------
SET( ${PROJECT_NAME}_VERSION_MAJOR 1 )
SET( ${PROJECT_NAME}_VERSION_MINOR 1 )
SET( ${PROJECT_NAME}_VERSION_PATCH 99 )
SET( ${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}" )
#--- Define basic build settings -----------------------------------------------
# Provides install directory variables as defined for GNU software
include(GNUInstallDirs)
# Define a default build type can be overridden by passing
# ``-DCMAKE_BUILD_TYPE=<type>`` when invoking CMake
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo
CACHE STRING "Choose the type of build, options are: None Release MinSizeRel Debug RelWithDebInfo"
FORCE
)
else()
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}"
CACHE STRING "Choose the type of build, options are: None Release MinSizeRel Debug RelWithDebInfo"
FORCE
)
endif()
endif()
# Set up C++ Standard
# ``-DCMAKE_CXX_STANDARD=<standard>`` when invoking CMake
set(CMAKE_CXX_STANDARD 20 CACHE STRING "")
if(NOT CMAKE_CXX_STANDARD MATCHES "17|20")
message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}")
endif()
if(CMAKE_CXX_STANDARD EQUAL 17)
message(WARNING "C++17 is deprecated and support for it will be removed in v01-03. Please use at least C++20.")
endif()
# Prevent CMake falls back to the latest standard the compiler does support
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Disables the use of compiler-specific extensions, hence makes sure the code
# works for a wider range of compilers
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "Setting C++ standard: '${CMAKE_CXX_STANDARD}'.")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
option(PODIO_SET_RPATH "Link libraries with built-in RPATH (run-time search path)" OFF)
include(cmake/podioBuild.cmake)
podio_set_compiler_flags()
podio_set_rpath()
set(USE_SANITIZER ""
CACHE STRING "Compile with a sanitizer. Options are Address, Memory, MemoryWithOrigin, Undefined, Thread, Leak, Address;Undefined")
ADD_SANITIZER_FLAGS()
option(FORCE_RUN_ALL_TESTS "Run all the tests even those with known problems" OFF)
option(CLANG_TIDY "Run clang-tidy after compilation." OFF)
ADD_CLANG_TIDY()
#--- Declare options -----------------------------------------------------------
option(CREATE_DOC "Whether or not to create doxygen doc target." OFF)
option(ENABLE_SIO "Build SIO I/O support" OFF)
option(PODIO_RELAX_PYVER "Do not require exact python version match with ROOT" OFF)
option(ENABLE_RNTUPLE "Build with support for the new ROOT NTtuple format" OFF)
option(ENABLE_DATASOURCE "Build podio's ROOT DataSource" OFF)
option(PODIO_USE_CLANG_FORMAT "Use clang-format to format the code" OFF)
option(ENABLE_JULIA "Enable Julia support. When enabled, Julia datamodels will be generated, and Julia tests will run." OFF)
#--- Declare ROOT dependency ---------------------------------------------------
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(root_components_needed RIO Tree)
if(ENABLE_RNTUPLE)
list(APPEND root_components_needed ROOTNTuple)
endif()
if(ENABLE_DATASOURCE)
list(APPEND root_components_needed ROOTDataFrame)
endif()
find_package(ROOT REQUIRED COMPONENTS ${root_components_needed})
if((ENABLE_RNTUPLE) AND (${ROOT_VERSION} VERSION_LESS 6.28.02))
message(FATAL_ERROR "You are trying to build podio with support for the new ROOT NTuple format, but your ROOT version is too old. Please update ROOT to at least version 6.28.02")
endif()
# ROOT_CXX_STANDARD was introduced in https://github.com/root-project/root/pull/6466
# before that it's an empty variable so we check if it's any number > 0
if(NOT DEFINED ROOT_CXX_STANDARD)
message(STATUS "ROOT c++ standard not yet available. Determining from compile features")
get_target_property(ROOT_COMPILE_FEATURES ROOT::Core INTERFACE_COMPILE_FEATURES)
foreach(cxxstd IN ITEMS 20;17;14;11)
if ("cxx_std_${cxxstd}" IN_LIST ROOT_COMPILE_FEATURES)
set(ROOT_CXX_STANDARD ${cxxstd})
break()
endif()
endforeach()
endif()
if(NOT DEFINED ROOT_CXX_STANDARD)
message(WARNING "ROOT c++ standard could not be detected")
else()
message(STATUS "Determined ROOT c++ standard: " ${ROOT_CXX_STANDARD})
endif()
if(ROOT_CXX_STANDARD VERSION_LESS 17)
message(FATAL_ERROR "You are trying to build podio against a version of ROOT that has not been built with a sufficient c++ standard. podio requires c++17 or higher")
endif()
if(NOT ROOT_CXX_STANDARD VERSION_EQUAL CMAKE_CXX_STANDARD)
message(WARNING "You are trying to build podio with a different c++ standard than ROOT. C++${CMAKE_CXX_STANDARD} was required but ROOT was built with C++${ROOT_CXX_STANDARD}")
endif()
# ROOT only sets usage requirements from 6.14, so for
# earlier versions need to hack in INTERFACE_INCLUDE_DIRECTORIES
if(ROOT_VERSION VERSION_LESS 6.14)
set_property(TARGET ROOT::Core APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}")
endif()
list(APPEND PODIO_IO_HANDLERS ROOT)
# python setup (including python package discovery and install dir)
podio_python_setup()
#--- enable podio macros--------------------------------------------------------
include(cmake/podioMacros.cmake)
# optionally build with SIO -------------------------------------------------
if(ENABLE_SIO)
find_package( SIO REQUIRED)
# Targets from SIO only become available with v00-01 so we rig them here to be
# able to use them
if (SIO_VERSION VERSION_LESS 0.1)
message(STATUS "Found SIO without Targets, creating them on the fly")
add_library(SIO::sio SHARED IMPORTED)
set_target_properties(SIO::sio PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${SIO_INCLUDE_DIRS}
INTERFACE_LINK_LIBRARIES ${SIO_LIBRARIES}
IMPORTED_LOCATION ${SIO_LIBRARIES})
endif()
if (SIO_FOUND)
MESSAGE( STATUS "Found SIO library - will build SIO I/O support" )
list(APPEND PODIO_IO_HANDLERS SIO)
endif()
endif()
#--- enable unit testing capabilities ------------------------------------------
include(CTest)
set(USE_EXTERNAL_CATCH2 AUTO CACHE STRING "Link against an external Catch2 v3 static library, otherwise build it locally")
set_property(CACHE USE_EXTERNAL_CATCH2 PROPERTY STRINGS AUTO ON OFF)
#--- enable CPack --------------------------------------------------------------
option(ENABLE_CPACK "Whether or not to use cpack config" OFF)
if(ENABLE_CPACK)
include(cmake/podioCPack.cmake)
endif()
#--- target for Doxygen documentation ------------------------------------------
if(CREATE_DOC)
include(cmake/podioDoxygen.cmake)
endif()
#--- add version files ---------------------------------------------------------
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/podioVersion.in.h
${CMAKE_CURRENT_SOURCE_DIR}/include/podio/podioVersion.h )
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/podio/podioVersion.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/podio )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/__version__.py.in
${CMAKE_CURRENT_SOURCE_DIR}/python/podio/__version__.py)
# Quality of life improvement to be able to use podio-dump --help
# without having to import ROOT
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/__version__.py.in
${CMAKE_CURRENT_SOURCE_DIR}/python/podio_version.py)
#--- add license files ---------------------------------------------------------
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/NOTICE
DESTINATION ${CMAKE_INSTALL_DOCDIR})
#--- project specific subdirectories -------------------------------------------
add_subdirectory(src)
# Set the podio_PYTHON_DIR manually here because the macros in tests expect it
# If testing is not build this helps when building together with other packages
SET(podio_PYTHON_DIR ${PROJECT_SOURCE_DIR}/python CACHE PATH "Path to the podio python directory")
if(BUILD_TESTING)
include(ExternalData)
list(APPEND ExternalData_URL_TEMPLATES
"https://key4hep.web.cern.ch:443/testFiles/podio/%(hash)"
)
include(cmake/podioTest.cmake)
add_subdirectory(tests)
endif()
add_subdirectory(tools)
add_subdirectory(python)
if(BUILD_TESTING)
# Make sure to fetch all data, after all legacy test cases have been added
ExternalData_Add_Target(legacy_test_cases)
message(STATUS "Test inputs will be stored in: ${ExternalData_OBJECT_STORES} if they are not already present")
endif()
#--- add CMake infrastructure --------------------------------------------------
include(cmake/podioCreateConfig.cmake)
#--- code format targets -------------------------------------------------------
include(cmake/pythonFormat.cmake)