-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
161 lines (133 loc) · 4.83 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
cmake_minimum_required(VERSION 3.10)
project(larcv VERSION 1.1.0)
#---Install location by default is in the build directory
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/installed" CACHE PATH "${CMAKE_BUILD_DIR}" FORCE )
endif()
#---Module directory
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
## Dependencies
#---CERN ROOT
find_package(ROOT CONFIG REQUIRED)
# we set the compiler version based on the one used for ROOT
execute_process(
COMMAND bash "-c" "root-config --features | awk '{print $1}'"
OUTPUT_VARIABLE ROOT_CXX_STANDARD )
if (${ROOT_CXX_STANDARD} MATCHES "cxx17")
message( STATUS "using cxx17")
set(CMAKE_CXX_STANDARD 17)
elseif (${ROOT_CXX_STANDARD} MATCHES "cxx14")
message( STATUS "ssing cxx14")
set(CMAKE_CXX_STANDARD 14)
else ()
message( STATUS "using cxx11")
set(CMAKE_CXX_STANDARD 11)
endif()
#---OPENCV
if (USE_OPENCV)
set(OpenCV_DIR $ENV{OPENCV_LIBDIR}/../share/OpenCV)
find_package(OpenCV CONFIG REQUIRED)
if (NOT OpenCV_FOUND)
set(USE_OPENCV 0)
endif()
endif()
#---Eigen
#find_package(Eigen3 REQUIRED)
#---PYTHON
if (USE_PYTHON3)
find_package( PythonInterp 3 REQUIRED )
find_package( PythonLibs 3 REQUIRED )
# warning gross hack
execute_process( COMMAND python3 -c "import numpy; print(numpy.get_include())" OUTPUT_VARIABLE NUMPY_INCLUDES OUTPUT_STRIP_TRAILING_WHITESPACE )
#message(${NUMPY_INCLUDES})
set(LARCV_USE_PYTHON 1)
set(LARCV_PYTHON_VERSION 3)
elseif(USE_PYTHON2)
find_package( PythonInterp 2.7 REQUIRED )
find_package( PythonLibs 2.7 REQUIRED )
find_package( Numpy REQUIRED )
set(LARCV_USE_PYTHON 1)
set(LARCV_PYTHON_VERSION 2)
else()
set(LARCV_USE_PYTHON 0)
endif()
#---larbys GEO2D
# use it if env variables defined
if (DEFINED ENV{GEO2D_BASEDIR})
set(LARCV_USE_GEO2D 1)
else()
set(LARCV_USE_GEO2D 0)
endif()
# unless explicitly told no
if (NOT USE_GEO2D)
set(LARCV_USE_GEO2D 0)
endif()
if (LARCV_USE_GEO2D)
set( GEO2D_INC_DIR "$ENV{GEO2D_INCDIR}" )
set( GEO2D_LIB_DIR "$ENV{GEO2D_LIBDIR}" )
file( GLOB GEO2D_LIBS "$ENV{GEO2D_LIBDIR}/*.so" )
endif()
# --- Torch
if (USE_TORCH)
if (ON_FNAL)
# For FNAL
set( Torch_DIR "$ENV{LIBTORCH_FQ_DIR}/lib/python2.7/site-packages/torch/share/cmake/Torch" )
#set( OpenBLAS_DIR "$ENV{OPENBLAS_FQ_DIR}/lib/cmake/openblas" )
#find_package( OpenBLAS REQUIRED )
else()
set( Torch_DIR "$ENV{LIBTORCH_FQ_DIR}/lib/python2.7/site-packages/torch/share/cmake/Torch" )
find_package( CUDA )
endif()
find_package( Torch REQUIRED )
endif()
## Git Submodules
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
#---check json
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/json/CMakeLists.txt")
message(FATAL_ERROR "The json submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
## Setup
#---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
include(${ROOT_USE_FILE})
#---Define Variables for subdirectory cmakelists
set(LARCV_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
## External repos (from submodules)
include_directories(extern/json)
add_subdirectory(extern/json)
set(LARCV_JSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/json/single_include)
## Add Source
#---Add base of source
add_subdirectory(larcv)
#---Configuration export
include(CMakePackageConfigHelpers)
set(LARCV_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include")
set(LARCV_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set(TARGETS_EXPORT_NAME "larcvTargets")
configure_package_config_file("cmake/Config.cmake.in"
"${CMAKE_BINARY_DIR}/cmake/larcvConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/larcv"
PATH_VARS LARCV_INCLUDE_DIR LARCV_LIBRARY_DIR LARCV_BASE_DIR LARCV_USE_GEO2D LARCV_USE_PYTHON LARCV_PYTHON_VERSION)
write_basic_package_version_file("${CMAKE_BINARY_DIR}/cmake/larcvConfigVersion.cmake"
COMPATIBILITY SameMajorVersion)
## Export Targets
#---Create info to include LArCV in other cmake files
install(EXPORT larcv
FILE larcvTargets.cmake
DESTINATION "${CMAKE_BINARY_DIR}/installed/lib/cmake/larcv")
#---Create info to include LArCV in other cmake files
install(FILES "${CMAKE_BINARY_DIR}/cmake/larcvConfig.cmake"
"${CMAKE_BINARY_DIR}/cmake/larcvConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/larcv")