-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
304 lines (259 loc) · 9.22 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# The ENVE project #
# #
# Copyright (c) 2020, Davide Stocco and Enrico Bertolazzi. #
# #
# The ENVE project and its components are supplied under the terms of #
# the open source BSD 3-Clause License. The contents of the ENVE #
# project and its components may not be copied or disclosed except in #
# accordance with the terms of the BSD 3-Clause License. #
# #
# URL: https://opensource.org/licenses/BSD-3-Clause #
# #
# Davide Stocco #
# Department of Industrial Engineering #
# University of Trento #
# e-mail: davide.stocco@unitn.it #
# #
# Enrico Bertolazzi #
# Department of Industrial Engineering #
# University of Trento #
# e-mail: enrico.bertolazzi@unitn.it #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
cmake_minimum_required(VERSION 3.14)
project( enve )
include(./cmake_utils/CMakeLists-common.txt)
project(
${PROJECT_NAME}
VERSION ${UTILS_PROJECT_VERSION}
HOMEPAGE_URL "https://StoccoDavide.github.io/enve/"
)
include(./CMakeLists-cflags.txt)
include(./cmake_utils/CMakeLists-utilities.txt)
# Evaluating the suffix to append to target built by this CMake file
utils_artifacts_suffix(ARTIFACTS_STATIC_SUFFIX TRUE)
if( UTILS_BUILD_SHARED )
utils_artifacts_suffix(ARTIFACTS_DYNAMIC_SUFFIX FALSE)
endif()
message( STATUS "Compiler used: ${CMAKE_CXX_COMPILER_ID}" )
message( STATUS "BASE SUFFIXES = ${ARTIFACTS_STATIC_SUFFIX} ${ARTIFACTS_DYNAMIC_SUFFIX}" )
# ____
# / ___| ___ _ _ _ __ ___ ___ ___
# \___ \ / _ \| | | | '__/ __/ _ \/ __|
# ___) | (_) | |_| | | | (_| __/\__ \
# |____/ \___/ \__,_|_| \___\___||___/
#
set( SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" )
set( SOURCES )
file( GLOB S ${SOURCES_DIR}/*.cc )
foreach(F ${S})
# Build relative path respect to source directory
file( RELATIVE_PATH RF ${SOURCES_DIR} "${F}" )
list( APPEND SOURCES ${RF} )
endforeach(F ${S})
# _ _ _
# | | | | ___ __ _ __| | ___ _ __ ___
# | |_| |/ _ \/ _` |/ _` |/ _ \ '__/ __|
# | _ | __/ (_| | (_| | __/ | \__ \
# |_| |_|\___|\__,_|\__,_|\___|_| |___/
#
set( HEADERS )
file( GLOB S
${SOURCES_DIR}/*.h*
${SOURCES_DIR}/enve/*.h*
)
foreach (F ${S})
# Build relative path respect to include directory
file( RELATIVE_PATH RF ${SOURCES_DIR} "${F}" )
list( APPEND HEADERS ${RF} )
endforeach(F ${S})
# Extra include directory for compilation
include_directories( ./lib3rd/include )
include_directories( ./sfun/include_sfun )
# ____ __
# / ___| / _|_ _ _ __
# \___ \| |_| | | | '_ \
# ___) | _| |_| | | | |
# |____/|_| \__,_|_| |_|
#
set( ENVE_BUILD_SFUN TRUE )
if( ENVE_BUILD_SFUN )
# S-function sources
set( SFUN_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/sfun/src_sfun" )
file( GLOB S ${SFUN_SOURCES_DIR}/*.cc )
foreach( F ${S} )
# Build relative path with respect to source directory
file( RELATIVE_PATH RF ${CMAKE_CURRENT_SOURCE_DIR} "${F}" )
list( APPEND SOURCES "../${RF}" )
endforeach( F ${S} )
# S-function headers
set( SFUN_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/sfun/include_sfun" )
set( SFUN_HEADERS )
file( GLOB S ${SFUN_HEADERS_DIR}/*.h ${SFUN_HEADERS_DIR}/*.hh )
foreach( F ${S} )
# Build relative path with respect to source directory
file( RELATIVE_PATH RF ${CMAKE_CURRENT_SOURCE_DIR} "${F}" )
list( APPEND SFUN_HEADERS ${RF} )
endforeach( F ${S} )
install( FILES ${SFUN_HEADERS} DESTINATION ${PROJECT_PUBLIC_HEADER_DESTINATION} )
endif()
# _____ _
# | ____(_) __ _ ___ _ __
# | _| | |/ _` |/ _ \ '_ \
# | |___| | (_| | __/ | | |
# |_____|_|\__, |\___|_| |_|
# |___/
find_package(Eigen3 REQUIRED)
include_directories( ${EIGEN3_INCLUDE_DIR} )
message("Eigen include directories: ${EIGEN3_INCLUDE_DIR}")
message("Eigen include directories: ${EIGEN3_FOUND}")
# ____ _ _
# | _ \ ___ _ __ ___ _ __ __| | ___ _ __ ___(_) ___ ___
# | | | |/ _ \ '_ \ / _ \ '_ \ / _` |/ _ \ '_ \ / __| |/ _ \/ __|
# | |_| | __/ |_) | __/ | | | (_| | __/ | | | (__| | __/\__ \
# |____/ \___| .__/ \___|_| |_|\__,_|\___|_| |_|\___|_|\___||___/
# |_|
set( DEPEND_TARGETS )
# Dependencies (try to use already compiled submodule in large project)
set(
UPDIR ${CMAKE_CURRENT_SOURCE_DIR}/..
)
# Acme library
find_library(
ACME acme${ARTIFACTS_STATIC_SUFFIX}
HINTS ${UPDIR}/acme/lib/lib
NO_DEFAULT_PATH
)
if( ACME )
message( STATUS "Found acme${ARTIFACTS_STATIC_SUFFIX}" )
utils_copy_directory(
"${UPDIR}/acme/lib"
"${CMAKE_CURRENT_SOURCE_DIR}/lib3rd"
)
else()
message( STATUS "NOT Found acme${ARTIFACTS_STATIC_SUFFIX} use submodule" )
add_subdirectory( ./submodules/acme )
include_directories( ./submodules/acme/src )
set( ACME ${UTILS_NAMESPACE}_acme_Static )
set( DEPEND_TARGETS ${DEPEND_TARGETS} ${ACME} )
endif()
message( STATUS "SOURCES = ${SOURCES}" )
message( STATUS "HEADERS = ${HEADERS}" )
# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
# | |/ _` | '__/ _` |/ _ \ __/ __|
# | | (_| | | | (_| | __/ |_\__ \
# |_|\__,_|_| \__, |\___|\__|___/
# |___/
# Define target
utils_setup_target(
${PROJECT_NAME}
TRUE # Build static
"${SOURCES_DIR}"
"${SOURCES}"
"${SOURCES_DIR}"
"${HEADERS}"
)
if( UTILS_BUILD_SHARED )
utils_setup_target(
${PROJECT_NAME}
FALSE # Build dynamic
"${SOURCES_DIR}"
"${SOURCES}"
"${SOURCES_DIR}"
"${HEADERS}"
)
target_link_libraries( ${UTILS_NAMESPACE}_${PROJECT_NAME} ${UTILS} ${ACME} )
endif()
if( DEPEND_TARGETS )
add_dependencies( ${UTILS_NAMESPACE}_${PROJECT_NAME}_Static ${DEPEND_TARGETS} )
endif()
# _____ _
# |_ _|__ ___| |_ ___
# | |/ _ \/ __| __/ __|
# | | __/\__ \ |_\__ \
# |_|\___||___/\__|___/
#
if( UTILS_ENABLE_TESTS )
enable_testing()
if( APPLE OR UNIX OR MINGW )
find_package( ZLIB REQUIRED )
else()
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
find_library( ZLIB_LIBRARIES zlibstaticd HINTS ./lib3rd/lib )
else()
find_library( ZLIB_LIBRARIES zlibstatic HINTS ./lib3rd/lib )
endif()
set( ZLIB_SOURCES_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/zlib/include" )
endif()
set( LIBS ${UTILS_NAMESPACE}_${PROJECT_NAME}_Static ${UTILS} ${ACME} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} )
if( UNIX )
if( NOT APPLE )
set( THREADS_PREFER_PTHREAD_FLAG ON )
find_package( Threads REQUIRED )
set( LIBS ${LIBS} Threads::Threads )
endif()
else()
#libcmt.lib
#find_library( WS2 ws2_32 REQUIRED )
#find_library( IPH iphlpapi REQUIRED )
#find_library( KER kernel32 REQUIRED )
#find_library( IPP ippsmt REQUIRED )
#find_library( WPTH pthread REQUIRED )
#set( LIBS ${LIBS} ${WS2} ${IPH} ${KER} )
set( LIBS ${LIBS} ws2_32 iphlpapi kernel32 )
if( UTILS_BUILD_SHARED )
target_link_libraries( ${UTILS_NAMESPACE}_${PROJECT_NAME} ${LIBS} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} )
endif()
endif()
set(
# List of tests to be executed
EXELISTCPP
enve_rtf_00
enve_test_00
enve_test_01
enve_test_02
enve_test_03
enve_test_04
enve_test_05
enve_test_06
enve_test_sfun_00
enve_timing_00
enve_timing_01
)
add_custom_target( "${PROJECT_NAME}_all_tests" ALL )
# Set bin folder
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin )
# Set tests folder
foreach( S ${EXELISTCPP} )
add_executable( ${S} ${CMAKE_CURRENT_SOURCE_DIR}/tests/${S}.cc )
target_link_libraries( ${S} ${LIBS} )
set_target_properties( ${S} PROPERTIES SUFFIX ".exe" )
add_test( NAME "${S}" COMMAND ./bin/${S}.exe WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
add_dependencies( "${PROJECT_NAME}_all_tests" ${S} )
endforeach()
endif()
# ___ _ _ _
# |_ _|_ __ ___| |_ __ _| | |
# | || '_ \/ __| __/ _` | | |
# | || | | \__ \ || (_| | | |
# |___|_| |_|___/\__\__,_|_|_|
#
install(
TARGETS ${TARGETS_TO_BE_INSTALLED}
# Export (to be defined)
LIBRARY DESTINATION ${INSTALL_PREFIX}/dll
ARCHIVE DESTINATION ${INSTALL_PREFIX}/lib
RUNTIME DESTINATION ${INSTALL_PREFIX}/bin
PUBLIC_HEADER DESTINATION ${PROJECT_PUBLIC_HEADER_DESTINATION}
)
# ____ _
# | _ \ __ _ ___| | ____ _ __ _ ___
# | |_) / _` |/ __| |/ / _` |/ _` |/ _ \
# | __/ (_| | (__| < (_| | (_| | __/
# |_| \__,_|\___|_|\_\__,_|\__, |\___|
# |___/
include( ./cmake_utils/CMakeLists-cpack.txt )
utils_final_messages()