forked from SGL-UT/gnsstk-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildSetup.cmake
218 lines (194 loc) · 10.7 KB
/
BuildSetup.cmake
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
# gnsstk/BuildSetup.cmake
#========================================
# Try to keep all the platform dependent
# options in this file
#========================================
#----------------------------------------
# Shared(Dynamic) vs. Static libraries
#----------------------------------------
if( UNIX )
set( STADYN "SHARED" )
elseif( WIN32 )
set( STADYN "STATIC" )
endif()
# profiler stuff
if( ${PROFILER} )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -no-pie -static" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg -no-pie -static" )
set( HDF5_USE_STATIC_LIBRARIES ON )
set( AEC_LIBRARIES "aec" )
message(STATUS "Profiler is enabled")
else()
set( AEC_LIBRARIES "" )
message(STATUS "Profiler is disabled")
endif()
#----------------------------------------
# Platform-dependent Compiler flags
#----------------------------------------
if( ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -erroff=hidevf,wvarhidemem,badargtype2w" )
# add -DCMAKE_CXX_FLAGS=-std=c++03 or =-std=c++11 on the CMAKE invocation
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -mt -shared" )
elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
set( CMAKE_SHARED_LIBRARY_SUFFIX .dylib )
set( CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -shared" )
# Do not optimize for debug builds. Do the same for RELWITHDEBINFO ?
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -O2" )
set( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -O3" )
set( CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -O2" )
set( CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -O3" )
elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror=return-type -Werror=deprecated" )
# Do not optimize for debug builds. Do the same for RELWITHDEBINFO ?
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g" )
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -O2" )
set( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -O3" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=return-type -Werror=deprecated" )
set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g" )
set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3" )
set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -O2" )
set( CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS} -O3" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -shared" )
elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
else()
message( ERROR "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}, not supported. Currently supported: Linux, Darwin, SunOS, Windows" )
endif()
#----------------------------------------
# When doing a debug build, enable the
# address sanitizer. This has a 2x slowdown
# but is adept at catching various memory problems.
#----------------------------------------
if( (${CMAKE_BUILD_TYPE} MATCHES "debug") AND (${ADDRESS_SANITIZER} MATCHES "ON") )
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"
OR ((${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER "4.9.0" ) AND CMAKE_COMPILER_IS_GNUCXX))
message(STATUS "Enabling address sanitizer for debug build")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer" )
endif()
endif()
#----------------------------------------
# Windows Visual Studio flags
#----------------------------------------
if( WIN32 )
if( MSVC14 )
#Compiler Options for Microsoft Visual Studio 14 (2015)
add_definitions( /MP /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES /EHsc /GR /wd"4274"
/wd"4503" /wd"4290" /wd"4267" /wd"4250" /wd"4244" /wd"4101" /wd"4800" /wd"4068" )
elseif( MSVC11 )
#Compiler Options for Microsoft Visual Studio 11 (2012)
add_definitions( /MP /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES /EHsc /GR /wd"4274"
/wd"4503" /wd"4290" /wd"4267" /wd"4250" /wd"4244" /wd"4101" /wd"4800" /wd"4068" )
endif( MSVC14 )
endif()
#----------------------------------------
# Set Build path options
#----------------------------------------
if( USE_RPATH )
# Use, i.e. don't skip the full RPATH for the build tree
set( CMAKE_SKIP_BUILD_RPATH FALSE )
# When building, don't use the install RPATH
# (but later on when installing)
set( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}:$ORIGIN/../${CMAKE_INSTALL_LIBDIR}" )
# Add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
# The RPATH to be used when installing, but only if it's not a system directory
list( FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}:$ORIGIN/../${CMAKE_INSTALL_LIBDIR}" isSystemDir )
if( "${isSystemDir}" STREQUAL "-1" )
set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}:$ORIGIN/../${CMAKE_INSTALL_LIBDIR}" )
endif( "${isSystemDir}" STREQUAL "-1" )
else()
set( CMAKE_SKIP_BUILD_RPATH TRUE )
endif()
# Remove hardening-no-relro warnings.
if( (${CMAKE_SYSTEM_NAME} MATCHES "Linux") )
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro -Wl,-z,now ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,relro -Wl,-z,now ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-z,relro -Wl,-z,now ${CMAKE_MODULE_LINKER_FLAGS}")
endif()
#----------------------------------------
if( DEBUG_SWITCH AND NOT DEBUG_VERBOSE )
message( STATUS "CMAKE_SYSTEM = ${CMAKE_SYSTEM}" ) # e.g., Linux-3.2.0
message( STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}" ) # e.g., Linux
message( STATUS "UNIX = ${UNIX}" ) # e.g., is the platform UNIX ?
message( STATUS "APPLE = ${APPLE}" ) # e.g., is the platform OSX?
message( STATUS "WIN32 = ${WIN32}" ) # e.g., is the platform Windows?
message( STATUS "MSVC11 = ${MSVC11}" ) # e.g., is the platform VisualStudio?
message( STATUS "MSVC12 = ${MSVC12}" ) # e.g., is the platform VisualStudio?
message( STATUS "CMAKE_COMMAND = ${CMAKE_COMMAND}" ) # e.g., /usr/bin/cmake
message( STATUS "CMAKE_VERSION = ${CMAKE_VERSION}" ) # e.g., 2.8.9
message( STATUS "CMAKE_BUILD_TOOL = ${CMAKE_BUILD_TOOL}" ) # e.g., /usr/bin/make
message( STATUS "STADYN = ${STADYN}" )
message( STATUS "CMAKE_COMPILER_IS_GNUCC = ${CMAKE_COMPILER_IS_GNUCC}" )
message( STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}" )
message( STATUS "CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}" )
message( STATUS "CMAKE_SKIP_BUILD_RPATH = ${CMAKE_SKIP_BUILD_RPATH}" )
message( STATUS "CMAKE_INSTALL_RPATH = ${CMAKE_INSTALL_RPATH}" )
message( STATUS "CMAKE_BUILD_WITH_INSTALL_RPATH = ${CMAKE_BUILD_WITH_INSTALL_RPATH}" )
message( STATUS "CMAKE_INSTALL_RPATH_USE_LINK_PATH = ${CMAKE_INSTALL_RPATH_USE_LINK_PATH}" )
message( STATUS "CMAKE_CURRENT_LIST_DIR = ${CMAKE_CURRENT_LIST_DIR}" ) # e.g., $HOME/git/gnsstk
message( STATUS "CMAKE_CURRENT_LIST_FILE = ${CMAKE_CURRENT_LIST_FILE}" ) # e.g., $HOME/git/gnsstk/CMakeLists.txt
message( STATUS "CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}" ) # e.g., $HOME/git/gnsstk
message( STATUS "CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}" ) # e.g., $HOME/git/gnsstk
message( STATUS "CMAKE_CURRENT_BINARY_DIR = ${CMAKE_CURRENT_BINARY_DIR}" ) # e.g., $HOME/git/gnsstk/build
message( STATUS "PROJECT_NAME = ${PROJECT_NAME}" ) # e.g., gnsstk
message( STATUS "PROJECT_BINARY_DIR = ${PROJECT_BINARY_DIR}" ) # e.g., $HOME/git/gnsstk/build
message( STATUS "PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}" ) # e.g., $HOME/git/gnsstk
message( STATUS "CMAKE_INSTALL_DIR = ${CMAKE_INSTALL_DIR}" ) # e.g., /usr
message( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" ) # e.g., $HOME/.local/gnsstk
endif()
#----------------------------------------
if( DEBUG_VERBOSE )
get_cmake_property( _variableNames VARIABLES )
foreach( _variableName ${_variableNames} )
message( STATUS "---- ${_variableName} = ${${_variableName}}" )
endforeach()
endif()
#----------------------------------------
if( ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" )
set( CPACK_GENERATOR "TGZ" )
elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
set( CPACK_GENERATOR "TGZ" )
elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
execute_process(COMMAND "/usr/bin/lsb_release" "-is"
TIMEOUT 4
OUTPUT_VARIABLE LINUX_DISTRO
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (${LINUX_DISTRO} MATCHES "RedHatEnterpriseServer")
message( STATUS "Detected a Linux Red Hat machine")
set( CPACK_GENERATOR "DEB;TGZ;RPM")
elseif (${LINUX_DISTRO} MATCHES "Debian")
message( STATUS "Detected a Linux Debian machine")
set( CPACK_GENERATOR "DEB;TGZ" )
else (${LINUX_DISTRO} MATCHES "RedHatEnterpriseServer")
message( STATUS "Detected a Linux machine")
set( CPACK_GENERATOR "DEB;TGZ" )
endif()
elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
set( CPACK_GENERATOR "NSIS;ZIP" )
set( CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE.md")
endif()
set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Applications for the GNSS processing GNSSTk toolkit.")
set( CPACK_PACKAGE_VENDOR "ARL:UT SGL" )
set( CPACK_PACKAGE_CONTACT "David Barber <[email protected]>" )
set( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md" )
set( CPACK_PACKAGE_VERSION_MAJOR "${GNSSTK_VERSION_MAJOR}" )
set( CPACK_PACKAGE_VERSION_MINOR "${GNSSTK_VERSION_MINOR}" )
set( CPACK_PACKAGE_VERSION_PATCH "${GNSSTK_VERSION_PATCH}" )
set( CPACK_INCLUDE_TOPLEVEL_DIRECTORY "OFF" )
set( CPACK_PACKAGE_INSTALL_DIRECTORY "gnsstk-apps${GNSSTK_VERSION_MAJOR}.${GNSSTK_VERSION_MINOR}${GNSSTK_VERSION_PATCH}" )
set( CPACK_TOPLEVEL_TAG "gnsstk-apps" )
set( CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.13), gnsstk (>= 11.0.0)" )
set( CPACK_DEBIAN_SECTION "stable" )
set( CPACK_DEBIAN_PACKAGE_SECTION "science" )
set( CPACK_RPM_PACKAGE_REQUIRES "gnsstk >= 11.0.0" )
set( CPACK_SOURCE_IGNORE_FILES "build/" "build-.*/" "examples/" "ref/" ".*/[.].*" )
set( CPACK_SOURCE_GENERATOR "TGZ")
# Prevents unstripped-binary-or-object Lintian errors.
SET(CPACK_STRIP_FILES "1")
include( CPack )