-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
245 lines (205 loc) · 8.37 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
# MIT License
#
# Copyright (c) 2024 Tim Whisonant
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.14)
project(c_lexer C CXX)
set(MYPROJ_INCLUDE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/include
CACHE PATH "Project include directory")
set(MYPROJ_TEST_DIR
${CMAKE_CURRENT_SOURCE_DIR}/tests
CACHE PATH "Project tests directory")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
set(EXECUTABLE_OUTPUT_PATH
${CMAKE_BINARY_DIR}/bin
CACHE PATH "Exe build directory" FORCE)
set(LIBRARY_OUTPUT_PATH
${CMAKE_BINARY_DIR}/lib
CACHE PATH "Lib build directory" FORCE)
# ##############################################################################
# MyProj version
# ##############################################################################
set(MYPROJ_VERSION_LOCAL
""
CACHE STRING "MyProj local version" FORCE)
set(MYPROJ_VERSION_MAJOR
0
CACHE STRING "MyProj major version" FORCE)
set(MYPROJ_VERSION_MINOR
1
CACHE STRING "MyProj minor version" FORCE)
set(MYPROJ_VERSION_REVISION
0${MYPROJ_VERSION_LOCAL}
CACHE STRING "MyProj revision version" FORCE)
set(MYPROJ_VERSION
${MYPROJ_VERSION_MAJOR}.${MYPROJ_VERSION_MINOR}.${MYPROJ_VERSION_REVISION}
CACHE STRING "MyProj version" FORCE)
get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if("${LIB64}" STREQUAL "TRUE")
set(MYPROJ_LIB_INSTALL_DIR
"lib64"
CACHE INTERNAL "arch-specific library path")
else()
set(MYPROJ_LIB_INSTALL_DIR
"lib"
CACHE INTERNAL "arch-specific library path")
endif()
option(MYPROJ_INSTALL_RPATH "Enable RPATH creation during install" OFF)
mark_as_advanced(MYPROJ_INSTALL_RPATH)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
if(MYPROJ_INSTALL_RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${MYPROJ_LIB_INSTALL_DIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
include(MyProjGit)
include(MyProjCompiler)
# ##############################################################################
# install header files
# ##############################################################################
install(DIRECTORY include/${CMAKE_PROJECT_NAME} DESTINATION include)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config/config.h.in"
"${CMAKE_BINARY_DIR}/include/config.h")
# ##############################################################################
# make this project discoverable
# ##############################################################################
install(EXPORT ${CMAKE_PROJECT_NAME}-targets
DESTINATION lib/${CMAKE_PROJECT_NAME}-${MYPROJ_VERSION})
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/export/${CMAKE_PROJECT_NAME}-config.cmake.in"
"${CMAKE_BINARY_DIR}/cmake/export/${CMAKE_PROJECT_NAME}-config.cmake" @ONLY)
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/export/${CMAKE_PROJECT_NAME}-config-version.cmake.in"
"${CMAKE_BINARY_DIR}/cmake/export/${CMAKE_PROJECT_NAME}-config-version.cmake"
@ONLY)
install(
FILES
"${CMAKE_BINARY_DIR}/cmake/export/${CMAKE_PROJECT_NAME}-config.cmake"
"${CMAKE_BINARY_DIR}/cmake/export/${CMAKE_PROJECT_NAME}-config-version.cmake"
DESTINATION "lib/${CMAKE_PROJECT_NAME}-${MYPROJ_VERSION}")
option(MYPROJ_BUILD_TESTS "Enable unit test build" OFF)
mark_as_advanced(MYPROJ_BUILD_TESTS)
include(FetchContent)
set(FETCHCONTENT_QUIET OFF)
# ##############################################################################
# googletest
# ##############################################################################
set(GTEST_URL
https://github.com/google/googletest
CACHE STRING "URL for googletest")
set(GTEST_VERSION
1.11.0
CACHE STRING "Version for googletest")
set(GTEST_TAG
release-${GTEST_VERSION}
CACHE STRING "Tag for googletest")
FetchContent_Declare(
gtest
GIT_REPOSITORY ${GTEST_URL}
GIT_TAG ${GTEST_TAG})
if(MYPROJ_BUILD_TESTS)
enable_testing()
if(NOT GTest_FOUND)
find_package(GTest ${GTEST_VERSION})
endif()
if(NOT GTest_FOUND)
set(GTEST_ROOT
${FETCHCONTENT_BASE_DIR}/gtest-src
CACHE PATH "googletest root directory" FORCE)
set(BUILD_SHARED_LIBS_ORIG ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS ON)
FetchContent_MakeAvailable(gtest)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_ORIG})
set(GTEST_INCLUDE_DIR
${GTEST_ROOT}/googletest/include
CACHE PATH "googletest include directory" FORCE)
set(GTEST_LIBRARY
${LIBRARY_OUTPUT_PATH}/libgtest.so
CACHE PATH "path to googletest library" FORCE)
set(GTEST_MAIN_LIBRARY
${LIBRARY_OUTPUT_PATH}/libgtest_main.so
CACHE PATH "path to googletest main library" FORCE)
set(GTEST_LIBRARY_DEBUG
${LIBRARY_OUTPUT_PATH}/libgtestd.so
CACHE PATH "path to (debug) googletest library" FORCE)
set(GTEST_MAIN_LIBRARY_DEBUG
${LIBRARY_OUTPUT_PATH}/libgtest_maind.so
CACHE PATH "path to (debug) googletest main library" FORCE)
set(GTest_FOUND
TRUE
CACHE BOOL "googletest found by FetchContent" FORCE)
add_library(gtest_IMPORT SHARED IMPORTED)
set_property(TARGET gtest_IMPORT PROPERTY IMPORTED_LOCATION
"${GTEST_LIBRARY}")
add_dependencies(gtest_IMPORT gtest)
add_library(gtest_MAIN_IMPORT SHARED IMPORTED)
set_property(TARGET gtest_MAIN_IMPORT PROPERTY IMPORTED_LOCATION
"${GTEST_MAIN_LIBRARY}")
add_dependencies(gtest_MAIN_IMPORT gtest)
add_library(gtest_IMPORT_DEBUG SHARED IMPORTED)
set_property(TARGET gtest_IMPORT_DEBUG PROPERTY IMPORTED_LOCATION
"${GTEST_LIBRARY_DEBUG}")
add_dependencies(gtest_IMPORT_DEBUG gtest)
add_library(gtest_MAIN_IMPORT_DEBUG SHARED IMPORTED)
set_property(TARGET gtest_MAIN_IMPORT_DEBUG
PROPERTY IMPORTED_LOCATION "${GTEST_MAIN_LIBRARY_DEBUG}")
add_dependencies(gtest_MAIN_IMPORT_DEBUG gtest)
set(GTEST_IMPORTED
TRUE
CACHE BOOL "googletest imported from source" FORCE)
else()
find_library(GTEST_LIBRARY_DEBUG libgtestd.so)
find_library(GTEST_MAIN_LIBRARY_DEBUG libgtest_maind.so)
find_library(GTEST_LIBRARY libgtest.so)
find_library(GTEST_MAIN_LIBRARY libgtest_main.so)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(GTEST_LIBRARIES
${GTEST_LIBRARY_DEBUG} ${GTEST_MAIN_LIBRARY_DEBUG}
CACHE STRING "googletest link libraries" FORCE)
else()
set(GTEST_LIBRARIES
${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY}
CACHE STRING "googletest link libraries" FORCE)
endif()
if(NOT GTEST_LIBRARIES)
if(GTEST_LIBRARY_DEBUG)
set(GTEST_LIBRARIES
${GTEST_LIBRARY_DEBUG} ${GTEST_MAIN_LIBRARY_DEBUG}
CACHE STRING "googletest link libraries" FORCE)
elseif(GTEST_LIBRARY)
set(GTEST_LIBRARIES
${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY}
CACHE STRING "googletest link libraries" FORCE)
endif()
endif()
message(STATUS "GTEST_INCLUDE_DIR: ${GTEST_INCLUDE_DIR}")
message(STATUS "GTEST_LIBRARY: ${GTEST_LIBRARY}")
message(STATUS "GTEST_MAIN_LIBRARY: ${GTEST_MAIN_LIBRARY}")
message(STATUS "GTEST_LIBRARY_DEBUG: ${GTEST_LIBRARY_DEBUG}")
message(STATUS "GTEST_MAIN_LIBRARY_DEBUG: ${GTEST_MAIN_LIBRARY_DEBUG}")
endif()
add_subdirectory(libs)
add_subdirectory(app)
if(MYPROJ_BUILD_TESTS)
add_subdirectory(tests)
endif()