-
Notifications
You must be signed in to change notification settings - Fork 48
/
CMakeLists.txt
179 lines (148 loc) · 6.8 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
# use cmake 3.12 or later
cmake_minimum_required(VERSION 3.12 FATAL_ERROR) ### MIGRATE-NO-ACTION
# To disable even if available, add
# -DCMAKE_DISABLE_FIND_PACKAGE_cetmodules:BOOL=ON to CMake command line.
find_package(cetmodules 3.13.00 QUIET) # Handling for CET-VAR
set(LAR_CONTENT_SOURCE_DIRNAME larpandoracontent)
set(LAR_DL_CONTENT_SOURCE_DIRNAME larpandoradlcontent)
if (cetmodules_FOUND)
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
set(LAR_CONTENT_LIBRARY_NAME LArPandoraContent)
set(LAR_PROJECT_NAME larpandoracontent) ## CET-VAR
#set(PANDORA_LIBTORCH_DEF ON)
set(CET_EXPORT EXPORT)
set(LAR_CONTENT_SOURCE_SHUNT ${LAR_CONTENT_SOURCE_DIRNAME})
set(LAR_DL_CONTENT_SOURCE_SHUNT ${LAR_DL_CONTENT_SOURCE_DIRNAME})
set(PANDORA_MONITORING TRUE)
else() # Configure for standalone build.
if (NOT LAR_CONTENT_LIBRARY_NAME STREQUAL "LArPandoraContent")
set(LAR_CONTENT_LIBRARY_NAME LArContent)
endif()
set(LAR_PROJECT_NAME ${LAR_CONTENT_LIBRARY_NAME})
cmake_policy(SET CMP0033 OLD)
endif()
# Single project() call with/without Cetmodules (CMake >=3.0, CMP0048).
project(${LAR_PROJECT_NAME} VERSION 04.11.00)
# Build options.
#option(PANDORA_LIBTORCH "Flag for building against LibTorch" ${PANDORA_LIBTORCH_DEF})
if (EXISTS "${CMAKE_PROJECT_BINARY_DIR}/doc")
option(LArContent_BUILD_DOCS "Build documentation for ${PROJECT_NAME}" OFF)
endif()
if (cetmodules_FOUND)
include(CetCMakeEnv)
cet_cmake_env()
cet_set_compiler_flags(DIAGS CAUTIOUS
WERROR
NO_UNDEFINED
EXTRA_FLAGS -pedantic
)
cet_report_compiler_flags(REPORT_THRESHOLD VERBOSE)
find_package(Torch QUIET ${CET_EXPORT})
if (Torch_FOUND)
set(PANDORA_LIBTORCH_DEF ON)
else()
set(PANDORA_LIBTORCH_DEF OFF)
endif()
option(PANDORA_LIBTORCH "Flag for building against LibTorch" ${PANDORA_LIBTORCH_DEF})
cet_cmake_module_directories(Modules)
add_subdirectory(Modules)
endif()
# Dependencies and other common configuration.
find_package(PandoraSDK 03.04.00 REQUIRED ${CET_EXPORT})
if (PANDORA_MONITORING)
find_package(PandoraMonitoring 03.05.00 REQUIRED ${CET_EXPORT})
endif()
find_package(Eigen3 3.3 REQUIRED)
set(${PROJECT_NAME}_SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
file(GLOB_RECURSE ${PROJECT_NAME}_SRCS RELATIVE "${PROJECT_SOURCE_DIR}/${LAR_CONTENT_SOURCE_SHUNT}"
"${LAR_CONTENT_SOURCE_DIRNAME}/*.cc")
if (PANDORA_LIBTORCH)
if (NOT cetmodules_FOUND)
find_package(Torch REQUIRED ${CET_EXPORT})
else()
find_package(TBB REQUIRED EXPORT)
endif()
string(REGEX REPLACE "^(LAr(Pandora)?)(Content)$" "\\1DL\\3"
LAR_DL_CONTENT_LIBRARY_NAME "${LAR_CONTENT_LIBRARY_NAME}")
set(DL_PROJECT_NAME "${LAR_DL_CONTENT_LIBRARY_NAME}")
foreach (bit IN ITEMS "" _MAJOR _MINOR _PATCH _TWEAK)
set(${DL_PROJECT_NAME}_VERSION${bit}
${${PROJECT_NAME}_VERSION${bit}})
endforeach()
set(${DL_PROJECT_NAME}_SOVERSION "${${DL_PROJECT_NAME}_VERSION_MAJOR}.${${DL_PROJECT_NAME}_VERSION_MINOR}")
file(GLOB_RECURSE ${DL_PROJECT_NAME}_SRCS RELATIVE "${PROJECT_SOURCE_DIR}/${LAR_DL_CONTENT_SOURCE_SHUNT}"
"${LAR_DL_CONTENT_SOURCE_DIRNAME}/*.cc")
message(STATUS "Building against LibTorch")
endif()
if (cetmodules_FOUND)
add_subdirectory(${LAR_CONTENT_SOURCE_DIRNAME})
if (PANDORA_LIBTORCH)
add_subdirectory(${LAR_DL_CONTENT_SOURCE_DIRNAME})
endif()
cet_cmake_config()
### MIGRATE-NO-ACTION # No nagging beyond this point.
else()
####################################################################
# Standalone build instructions (no Cetmodules).
####################################################################
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "${CMAKE_PROJECT_NAME} requires an out-of-source build.")
endif()
set(${PROJECT_NAME}_TOP_LEVEL_DIR "./${LAR_CONTENT_SOURCE_DIRNAME}")
if(PANDORA_LIBTORCH)
set(${DL_PROJECT_NAME}_TOP_LEVEL_DIR "./${LAR_DL_CONTENT_SOURCE_DIRNAME}")
endif()
#-------------------------------------------------------------------------------------------------------------------------------------------
# Dependencies
include(PandoraCMakeSettings)
# Prefer local include directory to any paths to installed header files
include_directories(./)
include_directories(${PandoraSDK_INCLUDE_DIRS})
link_libraries(${PandoraSDK_LIBRARIES})
add_definitions(${PandoraSDK_DEFINITIONS})
if(PANDORA_MONITORING)
include_directories(${PandoraMonitoring_INCLUDE_DIRS})
link_libraries(${PandoraMonitoring_LIBRARIES})
add_definitions(${PandoraMonitoring_DEFINITIONS})
add_definitions("-DMONITORING")
endif()
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIRS})
if(PANDORA_LIBTORCH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
include_directories(${TORCH_INCLUDE_DIRS})
link_libraries(${TORCH_LIBRARIES})
endif()
#-------------------------------------------------------------------------------------------------------------------------------------------
# Low level settings - compiler etc
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -pedantic -Wno-long-long -Wshadow -fno-strict-aliasing -std=c++17 ${CMAKE_CXX_FLAGS}")
include(CheckCXXCompilerFlag)
unset(COMPILER_SUPPORTS_CXX_FLAGS CACHE)
CHECK_CXX_COMPILER_FLAG(${CMAKE_CXX_FLAGS} COMPILER_SUPPORTS_CXX_FLAGS)
if(NOT COMPILER_SUPPORTS_CXX_FLAGS)
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} does not support cxx flags ${CMAKE_CXX_FLAGS}")
endif()
#-------------------------------------------------------------------------------------------------------------------------------------------
# Build products
foreach(PROJ IN LISTS PROJECT_NAME DL_PROJECT_NAME)
# - Add library and properties
add_library(${PROJ} SHARED ${${PROJ}_SRCS})
set_target_properties(${PROJ} PROPERTIES VERSION ${${PROJ}_VERSION} SOVERSION ${${PROJ}_SOVERSION})
endforeach()
# - Optional documents
if(LArContent_BUILD_DOCS)
add_subdirectory(doc)
endif()
#-------------------------------------------------------------------------------------------------------------------------------------------
# Install products
foreach(PROJ IN LISTS PROJECT_NAME DL_PROJECT_NAME)
# - library
install(TARGETS ${PROJ} DESTINATION lib COMPONENT Runtime)
# - headers
install(DIRECTORY ${${PROJ}_TOP_LEVEL_DIR} DESTINATION include COMPONENT Development FILES_MATCHING PATTERN "*.h")
# - support files
PANDORA_GENERATE_PACKAGE_CONFIGURATION_FILES(${PROJ}Config.cmake ${PROJ}ConfigVersion.cmake ${PROJ}LibDeps.cmake)
endforeach()
#-------------------------------------------------------------------------------------------------------------------------------------------
# display some variables and write them to cache
PANDORA_DISPLAY_STD_VARIABLES()
endif()