forked from ebertolazzi/Splines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
199 lines (176 loc) · 6.88 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
############################################################################
# #
# file: CMakeLists.txt #
# Copyright (C) 2016 #
# Enrico Bertolazzi #
# Dipartimento di Ingegneria Industriale #
# Universita` degli Studi di Trento #
# email: [email protected] #
# #
############################################################################
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_VERBOSE_MAKEFILE OFF)
# set(CMAKE_INSTALL_MESSAGE NEVER)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
if(ENABLE_CTEST)
enable_testing()
endif()
# get version from the git tag
execute_process(COMMAND git describe --tags --abbrev=0 OUTPUT_VARIABLE VERSION)
string(REGEX REPLACE "\n$" "" VERSION "${VERSION}")
project(
Splines
VERSION ${VERSION}
HOMEPAGE_URL "https://ebertolazzi.github.io/Clothoids/"
)
# NOTE: Predictable target name
set(STATIC_PROJECT "${PROJECT_NAME}Static")
set(DYNAMIC_PROJECT "${PROJECT_NAME}")
include(./CPackConfig.cmake)
include(./CMakeLists-cflags.txt)
include(./CMakeUtilities.txt)
# Evaluating the suffix to append to target built by this CMake file
ebertolazzi_artifacts_suffix(ARTIFACTS_STATIC_SUFFIX TRUE)
if(BUILD_SHARED)
ebertolazzi_artifacts_suffix(ARTIFACTS_DYNAMIC_SUFFIX FALSE)
endif()
# DEPENDENCIES (TRY TO USE ALREADY COMPILED SUBMODULE IN LARGE PROJECT)
set(UPDIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(DEPEND_TARGETS)
if( EXISTS "${UPDIR}/GC/lib" )
include_directories(${UPDIR}/GC/lib/include)
find_library( GC GenericContainer${ARTIFACTS_STATIC_SUFFIX} HINTS ${UPDIR}/GC/lib/lib )
else()
add_subdirectory(./submodules/GenericContainer)
set( GC GenericContainerStatic )
set(DEPEND_TARGETS ${DEPEND_TARGETS} GenericContainerStatic)
endif()
if( EXISTS "${UPDIR}/Utils/lib" )
include_directories(${UPDIR}/Utils/lib/include)
find_library( UTILS Utils${ARTIFACTS_STATIC_SUFFIX} HINTS ${UPDIR}/Utils/lib/lib )
else()
add_subdirectory(./submodules/Utils)
set( UTILS UtilsStatic )
set(DEPEND_TARGETS ${DEPEND_TARGETS} UtilsStatic)
endif()
if( EXISTS "${UPDIR}/quarticRootsFlocke/lib" )
include_directories(${UPDIR}/quarticRootsFlocke/lib/include)
find_library( QUARTIC quartic${ARTIFACTS_STATIC_SUFFIX} HINTS ${UPDIR}/quarticRootsFlocke/lib/lib )
else()
add_subdirectory(./submodules/quarticRootsFlocke)
set( QUARTIC QuarticStatic )
set(DEPEND_TARGETS ${DEPEND_TARGETS} QuarticStatic)
endif()
include_directories(lib3rd/include)
message( STATUS "Compiler used: ${CMAKE_CXX_COMPILER_ID}")
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
# NOTE: Glob shall be avoided. Headers and sources shall be declared
# manually in order to rebuild cmake-cache automatically.
# Ref: https://cmake.org/cmake/help/v3.15/command/file.html?highlight=glob#filesystem
set(Splines_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set( SOURCES )
file( GLOB S ./src/*.cc )
foreach (F ${S})
file( RELATIVE_PATH RF ${CMAKE_CURRENT_SOURCE_DIR} "${F}" )
list( APPEND SOURCES ${RF} )
endforeach (F ${S})
set( HEADERS )
FILE( GLOB S ./src/*.hh )
foreach (F ${S})
file( RELATIVE_PATH RF ${CMAKE_CURRENT_SOURCE_DIR} "${F}" )
list( APPEND HEADERS ${RF} )
endforeach (F ${S})
FILE( GLOB S ./src/*.h* )
foreach (F ${S})
file( RELATIVE_PATH RF ${CMAKE_CURRENT_SOURCE_DIR} "${F}" )
list( APPEND HEADERS ${RF} )
endforeach (F ${S})
set( HEADERS2 )
FILE( GLOB S ./src/Splines/*.h* )
foreach (F ${S})
file( RELATIVE_PATH RF ${CMAKE_CURRENT_SOURCE_DIR} "${F}" )
list( APPEND HEADERS2 ${RF} )
endforeach (F ${S})
add_library(${STATIC_PROJECT} STATIC ${SOURCES})
target_include_directories(
${STATIC_PROJECT} PUBLIC
"$<BUILD_INTERFACE:${Splines_DIR}>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)
set_target_properties(
${STATIC_PROJECT} PROPERTIES
OUTPUT_NAME "${PROJECT_NAME}${ARTIFACTS_STATIC_SUFFIX}"
# FIXME: I'm not sure if this is required for OSX Framework
#PUBLIC_HEADER "${HEADERS}"
POSITION_INDEPENDENT_CODE ON
)
if(BUILD_SHARED)
add_library(${DYNAMIC_PROJECT} SHARED ${SOURCES})
set_target_properties(
${DYNAMIC_PROJECT} PROPERTIES
OUTPUT_NAME "${PROJECT_NAME}${ARTIFACTS_DYNAMIC_SUFFIX}"
# FIXME: I'm not sure if this is required for OSX Framework
# PUBLIC_HEADER "${HEADERS}"
POSITION_INDEPENDENT_CODE ON
)
target_include_directories(
${DYNAMIC_PROJECT} PUBLIC
"$<BUILD_INTERFACE:${Splines_DIR}>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)
target_link_libraries( ${DYNAMIC_PROJECT} PUBLIC ${UTILS} ${QUARTIC} ${GC} )
if(WIN32)
set_target_properties(
${DYNAMIC_PROJECT} PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
)
endif()
endif()
if ( NOT ( "${DEPEND_TARGETS}" STREQUAL "" ) )
add_dependencies( ${STATIC_PROJECT} ${DEPEND_TARGETS} )
endif()
if(BUILD_EXECUTABLE OR ENABLE_CTEST)
enable_testing()
set(TEST_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(
EXECUTABLES
test1 test2 test3 test4 test5
test6 test8 test9 test10
)
foreach(EXE ${EXECUTABLES})
add_executable(${EXE} tests-cpp/${EXE}.cc)
target_link_libraries(
${EXE}
PRIVATE ${STATIC_PROJECT} ${UTILS} ${QUARTIC} ${GC} ${CMAKE_DL_LIBS}
)
set_target_properties(
${EXE} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${TEST_OUTPUT_PATH}"
)
add_test(${EXE} "${CMAKE_CURRENT_SOURCE_DIR}/bin/${EXE}")
endforeach()
endif()
# INSTALL TARGETS
set(INSTALL_TARGETS ${STATIC_PROJECT})
if(BUILD_SHARED)
set(INSTALL_TARGETS ${INSTALL_TARGETS} ${DYNAMIC_PROJECT})
endif()
include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeInstall.txt")
MESSAGE( STATUS "Using ${SSE_FLAGS} extensions")
MESSAGE( STATUS "C compiler = ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER}" )
MESSAGE( STATUS "C++ compiler = ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER}" )
MESSAGE( STATUS "CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}" )
MESSAGE( STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}" )
MESSAGE( STATUS "CMAKE_C_FLAGS_RELEASE = ${CMAKE_C_FLAGS_RELEASE}" )
MESSAGE( STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}" )
MESSAGE( STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}" )
MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}" )
IF(APPLE)
MESSAGE( STATUS "CMAKE_OSX_SYSROOT = ${CMAKE_OSX_SYSROOT}" )
MESSAGE( STATUS "CMAKE_OSX_ARCHITECTURES = ${CMAKE_OSX_ARCHITECTURES}" )
MESSAGE( STATUS "CMAKE_OSX_DEPLOYMENT_TARGET = ${CMAKE_OSX_DEPLOYMENT_TARGET}" )
ENDIF()
MESSAGE( STATUS "Sources = ${SOURCES}" )
MESSAGE( STATUS "Headers = ${HEADERS}" )
MESSAGE( STATUS "GC_LIB = ${GC_LIB}" )