-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
187 lines (142 loc) · 7.34 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
cmake_minimum_required(VERSION 3.0)
project(sight-deps)
# Looking for patch command
include( ${CMAKE_SOURCE_DIR}/cmake/utils/patch.cmake)
include( ${CMAKE_SOURCE_DIR}/cmake/install/install.cmake)
include( CMakeDependentOption )
set(COMMON_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_LINKER=${CMAKE_LINKER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
)
set(SET_COMPILER_ENV export CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} &&)
set(ARCHIVE_DIR ${CMAKE_SOURCE_DIR}/archive CACHE PATH "Archive directory")
# Debug / Release
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND NOT CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
message(SEND_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} (required Debug, Release, RelWithDebInfo or MinSizeRel)")
endif()
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "List of supported configurations." FORCE)
endif()
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/${CMAKE_BUILD_TYPE}" CACHE PATH "Install directory")
# estimate the processor cout
include(ProcessorCount)
ProcessorCount(CPUS_COUNT)
if(CPUS_COUNT EQUAL 0)
# default to 1 if cmake fails
set(CPUS_COUNT 1)
endif()
mark_as_advanced(NUMBER_OF_PARALLEL_BUILD)
set(NUMBER_OF_PARALLEL_BUILD ${CPUS_COUNT} CACHE STRING "Number of parallel build for non-make based subprojects (Boost for instance)")
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
# We can not use '$(MAKE)' with Ninja
set(MAKE make -j${NUMBER_OF_PARALLEL_BUILD})
else()
# This important to use '$(MAKE)' and not just 'make' to forward the flags from the command line (-j for instance)
set(MAKE $(MAKE))
endif()
# Do not set the runtime path in the install step, this allows to get "portable" libraries
list(APPEND COMMON_CMAKE_ARGS
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=ON
-DCMAKE_SKIP_INSTALL_RPATH:BOOL=ON
)
# List all package to build
list(APPEND SUBDIRECTORIES dbow2)
list(APPEND SUBDIRECTORIES g2o)
list(APPEND SUBDIRECTORIES pangolin)
list(APPEND SUBDIRECTORIES openvslam)
macro(createUninstallTarget SUBDIR )
# define an uninstall target for each project
configure_file(
"${CMAKE_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${SUBDIR}_uninstall.dir/${SUBDIR}_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(${SUBDIR}_uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${SUBDIR}_uninstall.dir/${SUBDIR}_uninstall.cmake)
# define the standard location for the intermediate install directory
set(INSTALL_PREFIX_${SUBDIR} ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIR}/${SUBDIR}-prefix/src/${SUBDIR}-install-tmp)
endmacro()
macro(createCleanTarget SUBDIR )
configure_file(
"${CMAKE_SOURCE_DIR}/cmake_clean.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${SUBDIR}_clean.dir/${SUBDIR}_clean.cmake"
IMMEDIATE @ONLY)
add_custom_target(${SUBDIR}_clean
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${SUBDIR}_clean.dir/${SUBDIR}_clean.cmake)
add_dependencies(${SUBDIR}_clean ${SUBDIR}_uninstall)
endmacro()
foreach(subdir ${SUBDIRECTORIES})
# define an uninstall target for each project
createUninstallTarget(${subdir})
# define a clean target for each project
createCleanTarget(${subdir})
add_subdirectory(${subdir})
endforeach()
set(SUBDIRECTORIES "")
# Automatic detection of additional repositories using .sight-deps files
file(GLOB ADDITIONAL_REPOSITORIES_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../*/.sight-deps)
foreach(REPOSITORY ${ADDITIONAL_REPOSITORIES_FILES})
file(READ ${REPOSITORY} REPO_RAW_NAME)
string(STRIP ${REPO_RAW_NAME} REPO_RAW_NAME)
string(TOUPPER ${REPO_RAW_NAME} REPO_NAME)
if(NOT ${REPO_NAME} STREQUAL "SIGHT-DEPS")
get_filename_component(REPO_DIR ${REPOSITORY} DIRECTORY)
get_filename_component(REPO_DIR ${REPO_DIR} ABSOLUTE)
option(BUILD_${REPO_NAME} "Enable ${REPO_NAME} repository" ON)
list(APPEND ADDITIONAL_REPOSITORIES_OPTION BUILD_${REPO_NAME})
list(APPEND ADDITIONAL_REPOSITORIES_NAME ${REPO_RAW_NAME})
list(APPEND ADDITIONAL_REPOSITORIES ${REPO_DIR})
endif()
endforeach()
# parse additional CMakeLists
if(ADDITIONAL_REPOSITORIES)
list(LENGTH ADDITIONAL_REPOSITORIES ADDITIONAL_REPOSITORIES_LEN)
math(EXPR ADDITIONAL_REPOSITORIES_LEN ${ADDITIONAL_REPOSITORIES_LEN}-1)
foreach(REPO_INDEX RANGE ${ADDITIONAL_REPOSITORIES_LEN})
list(GET ADDITIONAL_REPOSITORIES ${REPO_INDEX} ADDITIONAL_REPO)
list(GET ADDITIONAL_REPOSITORIES_OPTION ${REPO_INDEX} ADDITIONAL_REPO_OPTION)
if(EXISTS ${ADDITIONAL_REPO}/CMakeLists.txt AND ${ADDITIONAL_REPO_OPTION})
get_filename_component(DIR_NAME ${ADDITIONAL_REPO} NAME)
add_subdirectory(${ADDITIONAL_REPO} ${CMAKE_BINARY_DIR}/additional_deps/${DIR_NAME})
endif()
endforeach()
endif()
####################################################################################################################
#. Find PYTHON - required for our build process
#
find_program(PYTHON_EXECUTABLE python ${PATH})
####################################################################################################################
#. Install
add_custom_target(fix_path
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/fix_path.py "${CMAKE_INSTALL_PREFIX}"
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}
)
####################################################################################################################
# CPack related code
install(CODE "set(HOST_INSTALL_PATH \"${CMAKE_INSTALL_PREFIX}\")")
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/utils/cpack_install.cmake")
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/utils/fix_path.cmake")
include(${CMAKE_SOURCE_DIR}/cmake/utils/get_git_rev.cmake)
set(CPACK_PACKAGE_VERSION_MAJOR ${GIT_TAG_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${GIT_TAG_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${GIT_TAG_PATCH})
set(CPACK_PACKAGE_VENDOR "IRCAD")
set(CPACK_GENERATOR "TZST")
if(UNIX)
# Find the Linux version
execute_process(COMMAND lsb_release -i -s COMMAND tr -d '\n' OUTPUT_VARIABLE LINUX_DISTRIBUTION)
execute_process(COMMAND lsb_release -r -s COMMAND tr -d '\n' OUTPUT_VARIABLE LINUX_VERSION)
execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE)
# Construct the package name
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}-${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}-${LINUX_DISTRIBUTION}-${LINUX_VERSION}-${CMAKE_BUILD_TYPE}-${ARCHITECTURE}")
else()
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-${CMAKE_BUILD_TYPE}")
endif()
include(CPack)