-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCMakeLists.txt
273 lines (235 loc) · 10.4 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
cmake_minimum_required (VERSION 3.10)
project(RECORDER)
include_directories(${PROJECT_BINARY_DIR})
#------------------------------------------------------------------------------
# Version information
#------------------------------------------------------------------------------
set(RECORDER_VERSION_MAJOR "3")
set(RECORDER_VERSION_MINOR "0")
set(RECORDER_VERSION_PATCH "0")
set(RECORDER_PACKAGE "recorder")
set(RECORDER_PACKAGE_NAME "RECORDER")
set(RECORDER_PACKAGE_VERSION "${RECORDER_VERSION_MAJOR}.${RECORDER_VERSION_MINOR}.${RECORDER_VERSION_PATCH}")
set(RECORDER_PACKAGE_VERSION_MAJOR "${RECORDER_VERSION_MAJOR}.${RECORDER_VERSION_MINOR}")
set(RECORDER_PACKAGE_VERSION_MINOR "${RECORDER_VERSION_PATCH}")
set(RECORDER_PACKAGE_STRING "${RECORDER_PACKAGE_NAME} ${RECORDER_PACKAGE_VERSION}")
set(RECORDER_PACKAGE_TARNAME "${RECORDER_PACKAGE}")
# ignore warning message
if(POLICY CMP0074)
cmake_policy(SET CMP0074 OLD)
endif()
#------------------------------------------------------------------------------
# Setup install and output Directories
#------------------------------------------------------------------------------
if(NOT RECORDER_INSTALL_BIN_DIR)
set(RECORDER_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
endif()
if(NOT RECORDER_INSTALL_LIB_DIR)
set(RECORDER_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib)
endif()
if(NOT RECORDER_INSTALL_INCLUDE_DIR)
set(RECORDER_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
endif()
if(NOT RECORDER_INSTALL_DATA_DIR)
set(RECORDER_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share)
endif()
#------------------------------------------------------------------------------
# Setup CMake Environment
#------------------------------------------------------------------------------
if(APPLE)
# We are doing a unix-style install i.e. everything will be installed in
# CMAKE_INSTALL_PREFIX/bin and CMAKE_INSTALL_PREFIX/lib etc. as on other unix
# platforms. We still need to setup CMAKE_INSTALL_NAME_DIR correctly so that
# the binaries point to appropriate location for the libraries.
# 1. Make CMAKE_INSTALL_PREFIX publicly accessible, if it was hidden in
# previous pass
get_property(is_internal CACHE CMAKE_INSTALL_PREFIX PROPERTY TYPE)
if(is_internal STREQUAL "INTERNAL")
set(CMAKE_INSTALL_PREFIX ${CACHED_CMAKE_INSTALL_PREFIX} CACHE PATH "Install prefix" FORCE)
else()
set(CMAKE_INSTALL_PREFIX ${CACHED_CMAKE_INSTALL_PREFIX} CACHE PATH "Install prefix")
endif()
unset(MACOSX_APP_INSTALL_PREFIX CACHE)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
mark_as_advanced(
CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT
)
endif()
if(NOT CMAKE_INSTALL_RPATH)
list( APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib )
list( APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib64 )
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
if(NOT RECORDER_EXTERNALLY_CONFIGURED)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Executables."
)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Libraries"
)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all static libraries."
)
endif()
set(RECORDER_CMAKE_DIR "${RECORDER_SOURCE_DIR}/CMake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RECORDER_CMAKE_DIR})
#------------------------------------------------------------------------------
# Disallow in-source build
#------------------------------------------------------------------------------
if("${RECORDER_SOURCE_DIR}" STREQUAL "${RECORDER_BINARY_DIR}")
message(FATAL_ERROR
"RECORDER requires an out of source Build. "
"Please create a separate binary directory and run CMake there.")
endif()
#------------------------------------------------------------------------------
# Set a default build type if none was specified
#------------------------------------------------------------------------------
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
#if(NOT "${CMAKE_CXX_STANDARD}")
# set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_CXX_EXTENSIONS OFF)
#endif()
#-----------------------------------------------------------------------------
# Targets built within this project are exported at Install time for use
# by other projects.
#-----------------------------------------------------------------------------
if(NOT RECORDER_EXPORTED_TARGETS)
set(RECORDER_EXPORTED_TARGETS "recorder-targets")
endif()
#------------------------------------------------------------------------------
# Build options
#------------------------------------------------------------------------------
option(BUILD_SHARED_LIBS "Build with shared libraries." ON)
option(RECORDER_ENABLE_PARQUET "Build Parquet format converter." OFF)
option(RECORDER_ENABLE_CUDA_TRACE "Enable tracing of CUDA kernels." OFF)
option(RECORDER_ENABLE_FCNTL_TRACE "Enable tracing of fcntl()." ON)
option(RECORDER_INSTALL_TESTS "Enable installation of tests." OFF)
#mark_as_advanced(RECORDER_ENABLE_CUDA_TRACE)
#mark_as_advanced(RECORDER_ENABLE_FCNTL_TRACE)
if(BUILD_SHARED_LIBS)
set(RECORDER_BUILD_SHARED_LIBS 1)
set(RECORDER_LIBTYPE SHARED)
else()
set(RECORDER_BUILD_SHARED_LIBS 0)
set(RECORDER_LIBTYPE STATIC)
endif()
#if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon -Wno-unused-result")
#endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon -Wno-unused-result")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (NOT "${CMAKE_CXX_FLAGS_DEBUG}" MATCHES ".*-g3.*")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3"
CACHE STRING "" FORCE)
endif()
if (NOT "${CMAKE_C_FLAGS_DEBUG}" MATCHES ".*-g3.*")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3"
CACHE STRING "" FORCE)
endif()
endif()
#-------------------------------------------------------------------------------
function(recorder_set_lib_options libtarget libname libtype)
if(${libtype} MATCHES "SHARED")
if(WIN32 AND NOT MINGW)
set(LIB_RELEASE_NAME "${libname}")
set(LIB_DEBUG_NAME "${libname}_D")
set(LIB_VERSION ${RECORDER_PACKAGE_VERSION_MAJOR})
else()
set(LIB_RELEASE_NAME "${libname}")
set(LIB_DEBUG_NAME "${libname}_debug")
set(LIB_VERSION ${RECORDER_PACKAGE_VERSION})
endif()
else()
if(WIN32 AND NOT MINGW)
set(LIB_RELEASE_NAME "lib${libname}")
set(LIB_DEBUG_NAME "lib${libname}_D")
else()
# if the generator supports configuration types or if the CMAKE_BUILD_TYPE has a value
if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
set(LIB_RELEASE_NAME "${libname}")
set(LIB_DEBUG_NAME "${libname}_debug")
else()
set(LIB_RELEASE_NAME "lib${libname}")
set(LIB_DEBUG_NAME "lib${libname}_debug")
endif()
endif()
endif()
set_target_properties(${libtarget}
PROPERTIES
DEBUG_OUTPUT_NAME ${LIB_DEBUG_NAME}
RELEASE_OUTPUT_NAME ${LIB_RELEASE_NAME}
MINSIZEREL_OUTPUT_NAME ${LIB_RELEASE_NAME}
RELWITHDEBINFO_OUTPUT_NAME ${LIB_RELEASE_NAME}
VERSION ${LIB_VERSION}
SOVERSION ${LIB_VERSION}
)
#----- Use MSVC Naming conventions for Shared Libraries
if(MINGW AND ${libtype} MATCHES "SHARED")
set_target_properties(${libtarget}
PROPERTIES
IMPORT_SUFFIX ".lib"
IMPORT_PREFIX ""
PREFIX ""
)
endif()
endfunction()
#-----------------------------------------------------------------------------
# Source
#-----------------------------------------------------------------------------
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/GOTCHA)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/reporter)
#-----------------------------------------------------------------------------
# Testing
#-----------------------------------------------------------------------------
if(CMAKE_PROJECT_NAME STREQUAL RECORDER)
include(CTest)
endif()
if(CMAKE_PROJECT_NAME STREQUAL RECORDER AND BUILD_TESTING)
# include test sub directory
endif()
#-----------------------------------------------------------------------------
# Configure the config.cmake file for the build directory
#-----------------------------------------------------------------------------
configure_file(
${RECORDER_SOURCE_DIR}/CMake/recorder-config.cmake.build.in
${RECORDER_BINARY_DIR}/recorder-config.cmake @ONLY
)
#-----------------------------------------------------------------------------
# Configure the config.cmake file for the install directory
#-----------------------------------------------------------------------------
configure_file(
${RECORDER_SOURCE_DIR}/CMake/recorder-config.cmake.install.in
${RECORDER_BINARY_DIR}/CMakeFiles/recorder-config.cmake @ONLY
)
install(
FILES
${RECORDER_BINARY_DIR}/CMakeFiles/recorder-config.cmake
DESTINATION
${RECORDER_INSTALL_DATA_DIR}/cmake/recorder
)
#-----------------------------------------------------------------------------
# Configure the recorder-config-version .cmake file for the install directory
#-----------------------------------------------------------------------------
configure_file(
${RECORDER_SOURCE_DIR}/CMake/recorder-config-version.cmake.in
${RECORDER_BINARY_DIR}/CMakeFiles/recorder-config-version.cmake @ONLY
)
install(
FILES
${RECORDER_BINARY_DIR}/CMakeFiles/recorder-config-version.cmake
DESTINATION
${RECORDER_INSTALL_DATA_DIR}/cmake/recorder
)