-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
188 lines (164 loc) · 5.47 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
cmake_minimum_required(VERSION 3.5)
# Export mcr::Libmacro as the library target.
option(MCR_NOEXTRAS "Do not include extra functionality, or any C++. Not yet possible on Windows because of threading." OFF)
option(MCR_NOQT "Do not include any QT functionality. Implied by the MCR_NOEXTRAS option." OFF)
if (MCR_NOEXTRAS)
set(MCR_NOQT ON)
endif (MCR_NOEXTRAS)
# stl_off not supported
if (CMAKE_BUILD_TYPE MATCHES "^[Rr]el" OR CMAKE_BUILD_TYPE MATCHES "^[Mm]in")
option(BUILD_PACKAGE "Also build installer or package requirements." ON)
else ()
option(BUILD_PACKAGE "Also build installer or package requirements." OFF)
endif ()
option(BUILD_SHARED_LIBS "Build all libraries shared." ON)
if (BUILD_SHARED_LIBS)
unset(MCR_STATIC)
else ()
set(MCR_STATIC ON)
endif (BUILD_SHARED_LIBS)
# Defines MCR_VER, MCR_VER_MAJ, MCR_VER_MIN, MCR_DEBUG, MCR_PLATFORM
include(libmacro.cmake)
# Defines GIT_EXECUTABLE, GIT_REVISION, GIT_BRANCH
include(git.cmake)
# Create documentation: build + install targets if BUILD_DOC
include(doxygen.cmake)
project(libmacro VERSION ${MCR_VER}.${GIT_REVISION} HOMEPAGE_URL "https://sites.google.com/view/newparadigmsoftware" LANGUAGES C CXX)
# lib is not prepended to library file name on windows
if (windows)
set(LIBMACRO_TARGET libmacro)
set(LIBMACRO_TARGET libmacro PARENT_SCOPE)
else ()
set(LIBMACRO_TARGET macro)
set(LIBMACRO_TARGET macro PARENT_SCOPE)
endif (windows)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT MCR_NOQT)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
endif (NOT MCR_NOQT)
# Openssl static
if (MCR_STATIC)
set(OPENSSL_USE_STATIC_LIBS ON)
add_definitions(-DMCR_STATIC)
endif (MCR_STATIC)
# Openssl use multithreaded
set(OPENSSL_MSVC_STATIC_RT ON)
# TODO Thread optional with event loop
find_package(Threads REQUIRED)
if (NOT MCR_NOEXTRAS)
find_package(OpenSSL REQUIRED)
endif (NOT MCR_NOEXTRAS)
if (NOT MCR_NOQT)
find_package(Qt5 COMPONENTS Core Test REQUIRED)
endif (NOT MCR_NOQT)
# Lib sources
file(GLOB LIBMACRO_SRC
src/util/*.c
src/base/*.c
src/standard/*.c
src/intercept/*.c
src/*.c
src/*/${MCR_PLATFORM}/*.c
src/extras/*.cpp
src/extras/references/*.cpp
src/extras/signals/*.cpp
src/extras/triggers/*.cpp
src/extras/util/*.cpp
src/extras/${MCR_PLATFORM}/*.cpp
src/extras/ssl/p_safe_string.cpp
)
file(GLOB_RECURSE COMMON_HEADERS mcr/*.h)
set(COMMON_DEFINES
-DVERSION=${MCR_VER}.${GIT_REVISION}
-DGIT_BRANCH=${GIT_BRANCH}
-DGIT_REVISION=${GIT_REVISION}
)
# Windows requires C++ threads. Try not to spin threads in C because of this.
if (windows)
# Mingw and VC <= 2017 do not have C threads
list(APPEND LIBMACRO_SRC src/util/cppthread.cpp)
endif (windows)
# Remove extras module
if (MCR_NOEXTRAS)
list(FILTER LIBMACRO_SRC EXCLUDE REGEX
src/extras/
)
# Remove the classes that use QT
elseif (MCR_NOQT)
list(FILTER LIBMACRO_SRC EXCLUDE REGEX
signal_functions.cpp|trigger_functions.cpp
)
endif (MCR_NOEXTRAS)
# Library config files
if (windows)
if (MCR_STATIC)
set(TARGET_FILENAME libmacro.lib)
else ()
set(TARGET_FILENAME libmacro.dll)
endif (MCR_STATIC)
set(LIBMACRO_EXTRA_FILES "${CMAKE_CURRENT_BINARY_DIR}/libmacro.rc")
configure_file(libmacro.rc.in "${LIBMACRO_EXTRA_FILES}" @ONLY)
else ()
set(LIBMACRO_EXTRA_FILES "")
endif ()
# Library
add_library(${LIBMACRO_TARGET} ${LIBMACRO_SRC}
${COMMON_HEADERS} "${LIBMACRO_EXTRA_FILES}"
)
add_library(mcr::Libmacro ALIAS ${LIBMACRO_TARGET})
# TODO PUBLIC_HEADER on OSX
set_target_properties(${LIBMACRO_TARGET} PROPERTIES
SOVERSION ${MCR_VER})
# Export includes
target_include_directories(${LIBMACRO_TARGET} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
# Library link
if (NOT MCR_NOEXTRAS)
target_link_libraries(${LIBMACRO_TARGET} OpenSSL::Crypto Threads::Threads)
if (NOT MCR_NOQT)
target_link_libraries(${LIBMACRO_TARGET} Qt5::Core)
endif (NOT MCR_NOQT)
endif (NOT MCR_NOEXTRAS)
# Be aware msvc may require linking to Advapi32 and user32
# Library defines
target_compile_definitions(${LIBMACRO_TARGET} PRIVATE -DLIBMACRO_LIBRARY ${COMMON_DEFINES})
# Tests use QT for test framework and CLI options
if (BUILD_TESTING AND NOT MCR_NOQT)
file(GLOB_RECURSE TEST_SRC test/*.h test/*.cpp)
list(FILTER TEST_SRC EXCLUDE REGEX test/tst_.*\.cpp)
add_executable(tst_libmacro ${TEST_SRC})
add_dependencies(tst_libmacro ${LIBMACRO_TARGET})
target_link_libraries(tst_libmacro ${LIBMACRO_TARGET} Qt5::Test)
target_compile_definitions(tst_libmacro PRIVATE ${COMMON_DEFINES})
add_executable(tst_intercept test/tst_intercept.h test/tst_intercept.cpp)
add_dependencies(tst_intercept ${LIBMACRO_TARGET})
target_link_libraries(tst_intercept ${LIBMACRO_TARGET} OpenSSL::Crypto Threads::Threads Qt5::Core)
target_compile_definitions(tst_intercept PRIVATE ${COMMON_DEFINES})
# add_executable(Profile profile.c)
# add_executable(Profile profile.cpp)
endif (BUILD_TESTING AND NOT MCR_NOQT)
# Make files visible in editor, and use astyle in-editor.
add_custom_target(DISTFILES SOURCES
libmacro.astylerc
README.md
style
)
# Windows package everything to base directory, otherwise lib is separate.
if (windows)
install(TARGETS ${LIBMACRO_TARGET} DESTINATION /)
else ()
install(TARGETS ${LIBMACRO_TARGET} DESTINATION lib)
endif (windows)
install(DIRECTORY mcr DESTINATION include)
# Option to build tests
include(coverage.cmake)
# Platform variables and MCR_DEBUG required from libmacro.cmake
# Requires DEPLOYQT_TARGET
set(DEPLOYQT_TARGET ${LIBMACRO_TARGET})
include(deployqt.cmake)
include(cpack.cmake)