-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
204 lines (176 loc) · 6.98 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
#SET(BUILD_CGI_APP 1)
#SET(BUILD_COVERAGE 1)
IF (BUILD_COVERAGE)
SET(CMAKE_BUILD_TYPE Debug)
ELSE ()
IF (BUILD_CGI_APP)
SET(CMAKE_BUILD_TYPE MinSizeRel)
ELSE ()
SET(CMAKE_BUILD_TYPE Release)
ENDIF ()
ENDIF ()
IF (CMAKE_BUILD_TYPE)
SET (BUILD_TYPE ${CMAKE_BUILD_TYPE})
ELSE ()
SET (BUILD_TYPE RelWithDebInfo) # options are: Release, Debug, RelWithDebInfo, MinSizeRel
ENDIF ()
IF (BUILD_CGI_APP)
SET(project_build_static 1)
ELSE ()
SET(project_build_shared 1)
ENDIF ()
IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/output)
FILE (MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/output)
ENDIF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/output)
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12)
PROJECT (bcpost CXX)
SET (APPLICATION_NAME "BeeCAM Postprocessor")
SET (APPLICATION_CODENAME "${PROJECT_NAME}")
SET (APPLICATION_COPYRIGHT_YEARS "2019-2020")
SET (APPLICATION_VERSION_MAJOR 0)
SET (APPLICATION_VERSION_MINOR 1)
SET (APPLICATION_VERSION_PATCH 0)
SET (APPLICATION_VERSION_TYPE "${BUILD_TYPE}")
SET (APPLICATION_VENDOR_ID "BCS")
SET (APPLICATION_VENDOR_NAME "BeeCAM Solutions")
SET (APPLICATION_VENDOR_URL "beecamsolutions.com")
SET (APPLICATION_ID "${APPLICATION_VENDOR_ID}.${PROJECT_NAME}")
INCLUDE (${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/DetectDistro.cmake)
IF (CMAKE_CROSSCOMPILING)
SET (AUTORUN_TESTS FALSE)
ENDIF (CMAKE_CROSSCOMPILING)
MESSAGE( STATUS "Running on ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_PROCESSOR}" )
MESSAGE( STATUS "Build type: " ${BUILD_TYPE} )
MESSAGE( STATUS "CMake Build type: " ${CMAKE_BUILD_TYPE} )
SET (SHOW_STATS FALSE)
#
# Process and Library Names
#
SET (LIBPARSER_NAME pp)
SET (LIBPARSER_NAME_SHARED ${LIBPARSER_NAME}-shared)
SET (LIBPARSER_NAME_STATIC ${LIBPARSER_NAME}-static)
SET (LIBPARSER_NAME_UNITTEST ${LIBPARSER_NAME}-unittest)
SET (LIBPARSER_NAME_UT ${LIBPARSER_NAME}-ut)
SET (BCPOST_NAME bcpost)
#
# Build verbose mode
#
SET (CMAKE_VERBOSE_MAKEFILE 0) # Set 1 for debugging or "make VERBOSE=1"
#
# Project Output Paths
#
SET (MAINFOLDER ${PROJECT_SOURCE_DIR})
IF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
SET (EXECUTABLE_OUTPUT_PATH "${MAINFOLDER}/bin")
SET (LIBRARY_OUTPUT_PATH "${MAINFOLDER}/bin")
ELSE()
SET (EXECUTABLE_OUTPUT_PATH "${MAINFOLDER}/x64/Debug")
SET (LIBRARY_OUTPUT_PATH "${MAINFOLDER}/x64/Debug")
ENDIF()
#
# Project Install Paths
#
SET (EXECUTABLE_INSTALL_PATH "bin")
SET (LIBRARY_INSTALL_PATH "bin")
#
# Project Search Paths
#
LIST (APPEND CMAKE_PREFIX_PATH "${MAINFOLDER}")
LIST (APPEND CMAKE_PREFIX_PATH "${MAINFOLDER}/tools")
LIST (APPEND CMAKE_MODULE_PATH "${MAINFOLDER}/tools/cmake")
INCLUDE_DIRECTORIES("${MAINFOLDER}/pp")
#INCLUDE_DIRECTORIES("${MAINFOLDER}/pp/interface")
#INCLUDE_DIRECTORIES("${MAINFOLDER}/pp/parser")
#
# Locate Project Prerequisites
#
FIND_PACKAGE (GCCVersion 6.0.0 REQUIRED)
FIND_PACKAGE (Threads REQUIRED)
FIND_PACKAGE (Boost 1.56 REQUIRED)
IF (NOT project_build_static)
ADD_DEFINITIONS(-DBOOST_ALL_DYN_LINK)
ENDIF ()
IF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
FIND_PACKAGE(VALGRIND REQUIRED)
SET(VALGRIND_CONFIG --leak-check=full)
ENDIF()
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})
#
# Verify the compiler supports C++17
#
INCLUDE (CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
IF (COMPILER_SUPPORTS_CXX17)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
ELSE (COMPILER_SUPPORTS_CXX17)
MESSAGE (FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
ENDIF(COMPILER_SUPPORTS_CXX17)
#
# Use ccache
#
IF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
ENDIF ()
#
# Set compiler flags and build type
#
IF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -fmessage-length=0 -rdynamic -Wno-multichar -Wfatal-errors -Wno-write-strings")
ELSE()
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -fmessage-length=0 -Wno-multichar -Wfatal-errors -Wno-write-strings -Wno-maybe-uninitialized")
ENDIF()
IF (project_build_static)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -s -ffunction-sections -fdata-sections -Wl,--gc-sections")
ENDIF (project_build_static)
IF (SHOW_STATS)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftime-report")
ENDIF (SHOW_STATS)
IF (NOT BUILD_CGI_APP)
SET (CMAKE_CXX_OPTIMIZATION_FLAGS "-mavx2")
ENDIF ()
#SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
IF (NOT BUILD_COVERAGE)
SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_OPTIMIZATION_FLAGS}")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_OPTIMIZATION_FLAGS}")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${CMAKE_CXX_OPTIMIZATION_FLAGS}")
ENDIF ()
SET (CMAKE_BUILD_TYPE "${BUILD_TYPE}") # options are: Release, Debug, RelWithDebInfo, MinSizeRel
# To run i.e. Debug build from command-line: "cd build;cmake -D CMAKE_BUILD_TYPE=Debug ..;cd ..;make;"
#
# Add Build Targets
#
IF (CMAKE_COMPILER_IS_GNUCXX)
IF (BUILD_COVERAGE)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME ${LIBPARSER_NAME_UNITTEST}-coverage-lcov
EXECUTABLE ${MAINFOLDER}/bin/${LIBPARSER_NAME_UNITTEST}
DEPENDENCIES ${MAINFOLDER}/bin/${LIBPARSER_NAME_UNITTEST}
EXCLUDE "/usr/include/*" "${PROJECT_SOURCE_DIR}/pp_test/*" "${PROJECT_SOURCE_DIR}/pp_ut/*")
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME ${LIBPARSER_NAME_UT}-coverage-lcov
EXECUTABLE ${MAINFOLDER}/bin/${LIBPARSER_NAME_UT}
DEPENDENCIES ${MAINFOLDER}/bin/${LIBPARSER_NAME_UT}
EXCLUDE "/usr/include/*" "${PROJECT_SOURCE_DIR}/pp_test/*" "${PROJECT_SOURCE_DIR}/pp_ut/*")
setup_target_for_coverage_gcovr_html(NAME ${LIBPARSER_NAME_UNITTEST}-coverage-gcovr
EXECUTABLE ${MAINFOLDER}/bin/${LIBPARSER_NAME_UNITTEST}
DEPENDENCIES ${MAINFOLDER}/bin/${LIBPARSER_NAME_UNITTEST}
EXCLUDE "/usr/include/*" "${PROJECT_SOURCE_DIR}/pp_test/*" "${PROJECT_SOURCE_DIR}/pp_ut/*")
setup_target_for_coverage_gcovr_html(NAME ${LIBPARSER_NAME_UT}-coverage-gcovr
EXECUTABLE ${MAINFOLDER}/bin/${LIBPARSER_NAME_UT}
DEPENDENCIES ${MAINFOLDER}/bin/${LIBPARSER_NAME_UT}
EXCLUDE "/usr/include/*" "${PROJECT_SOURCE_DIR}/pp_test/*" "${PROJECT_SOURCE_DIR}/pp_ut/*")
ENDIF (BUILD_COVERAGE)
ENDIF (CMAKE_COMPILER_IS_GNUCXX)
# Libraries
ADD_SUBDIRECTORY(pp)
# Processes
ADD_SUBDIRECTORY(bcpost)
enable_testing ()
# Library unit tests
ADD_SUBDIRECTORY(pp_test)
ADD_SUBDIRECTORY(pp_ut)
# When "clean" target is run, remove the following directories/files
SET_PROPERTY(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${MAINFOLDER}/bin/.debug")