-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure
262 lines (247 loc) · 7.96 KB
/
configure
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
#! cmake -P
set(GF_GENERATOR "MSYS Makefiles")
set(GF_BUILD_PATH "${CMAKE_SOURCE_DIR}/.build")
set(GF_CMAKE_LIST "${CMAKE_SOURCE_DIR}/CMakeLists.txt")
#
# Prepare the build directory
#
function(init)
if(NOT EXISTS ${GF_BUILD_PATH})
# Make build directory
file(MAKE_DIRECTORY ${GF_BUILD_PATH})
message(">>> New directory '${GF_BUILD_PATH}' created.")
endif()
file(READ ${CMAKE_ARGV2} GF_SETUP_FILE)
string(REGEX MATCHALL "\n#> *[^\n]+" _TMP ${GF_SETUP_FILE})
string(REPLACE ";" "" _TMP "${_TMP}")
string(REPLACE "#>" "" GF_CONFIG_FILE "${_TMP}")
file(WRITE ${GF_CMAKE_LIST} ${GF_CONFIG_FILE})
# Execute CMake command
message(">>> Running CMake ...")
execute_process(
COMMAND
${CMAKE_COMMAND} .. -G ${GF_GENERATOR}
WORKING_DIRECTORY
${GF_BUILD_PATH}
)
endfunction(init)
#
# Clean up the build directory
#
function(clean)
# Clean build path
if(EXISTS ${GF_BUILD_PATH})
file(REMOVE_RECURSE ${GF_BUILD_PATH})
message(">>> Removed '${GF_BUILD_PATH}/'.")
endif()
# Clean CMakeLists.txt
if(EXISTS ${GF_CMAKE_LIST})
file(REMOVE_RECURSE ${GF_CMAKE_LIST})
message(">>> Removed '${GF_CMAKE_LIST}'.")
endif()
endfunction(clean)
#
# Print help message
#
function(help)
message("Usage: configure <command>")
message("command:")
message(" init Prepare the build directory")
message(" clean Clean up the build directory")
message(" help Print this message")
endfunction(help)
#
# Top of the script
#
set(SETUP_COMMAND ${CMAKE_ARGV3})
if("${SETUP_COMMAND}" STREQUAL "init")
init()
elseif("${SETUP_COMMAND}" STREQUAL "clean")
clean()
elseif("${SETUP_COMMAND}" STREQUAL "help")
help()
elseif(NOT "${SETUP_COMMAND}")
help()
else()
message(">>> ERROR: '${SETUP_COMMAND}' is not a command string.")
endif()
#------------------------------------------------------------------------------#
#>
#> #############################################################################
#> ## ##
#> ## CONFIGURATION FILE FOR PROJECT GRAYFISH ##
#> ## ##
#> #############################################################################
#>
#> cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
#>
#> project(GF VERSION 0.0.1 LANGUAGES C)
#>
#> set(CMAKE_BUILD_TYPE Debug)
#>
#> set(GF_MODULE_NAME Grayfish)
#> #---------------------------------------------------------------------------#
#> # DEPENDENCIES #
#> #---------------------------------------------------------------------------#
#>
#> find_package(LibXml2 REQUIRED)
#> find_package(LibXslt REQUIRED)
#> find_package(OpenSSL REQUIRED)
#>
#> #---------------------------------------------------------------------------#
#> # SETTINGS #
#> #---------------------------------------------------------------------------#
#>
#> ##
#> ## Common compiler/linker options
#> ##
#>
#> set(GF_CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Werror -std=c11 -D__USE_MINGW_ANSI_STDIO=1")
#> ##
#> ## Switch flags along with the build mode
#> ##
#> set(CMAKE_C_FLAGS_DEBUG "-coverage -g -O0 -DGF_DEBUG_")
#> set(CMAKE_C_FLAGS_RELEASE "-O3")
#> ##
#> ## Paths
#> ##
#>
#> set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
#> set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#> set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#>
#> #---------------------------------------------------------------------------#
#> # API REFERENCE #
#> #---------------------------------------------------------------------------#
#>
#> set(GF_REFERENCE_DOXYFILE_IN ${CMAKE_SOURCE_DIR}/doc/Doxyfile.in)
#> set(GF_REFERENCE_DOXYFILE ${CMAKE_BINARY_DIR}/doc/Doxyfile)
#> set(GF_REFERENCE_OUTPUT_FILE ${CMAKE_BINARY_DIR}/doc/${GF_MODULE_NAME})
#>
#> configure_file(${GF_REFERENCE_DOXYFILE_IN} ${GF_REFERENCE_DOXYFILE})
#>
#> add_custom_target(
#> doc ALL
#> doxygen ${GF_REFERENCE_DOXYFILE}
#> WORKING_DIRECTORY
#> ${CMAKE_SOURCE_DIR}
#> )
#>
#> #---------------------------------------------------------------------------#
#> # MAIN LIBRARY #
#> #---------------------------------------------------------------------------#
#>
#> set(GF_LIBGF_CONFIG_H_IN ${CMAKE_SOURCE_DIR}/src/libgf/config.h.in)
#> set(GF_LIBGF_CONFIG_H ${CMAKE_BINARY_DIR}/src/libgf/config.h)
#>
#> file(GLOB GF_LIBGF_SOURCE ${CMAKE_SOURCE_DIR}/src/libgf/*.c)
#> file(GLOB GF_LIBGF_HEADER
#> ${CMAKE_SOURCE_DIR}/src/libgf/*.h ${GF_LIBGF_CONFIG_H})
#>
#> configure_file(${GF_LIBGF_CONFIG_H_IN} ${GF_LIBGF_CONFIG_H})
#>
#> set(CMAKE_C_FLAGS ${GF_CMAKE_C_FLAGS} "-DDLL_EXPORT")
#>
#> include_directories(
#> ${LIBXML2_INCLUDE_DIR}
#> ${LIBXSLT_INCLUDE_DIR}
#> ${OPENSSL_INCLUDE_DIR}
#> ${CMAKE_SOURCE_DIR}/src)
#>
#> add_library(gf SHARED ${GF_LIBGF_SOURCE} ${GF_LIBGF_HEADER})
#> target_link_libraries(
#> gf
#> PRIVATE
#> ${LIBXML2_LIBRARIES}
#> ${LIBXSLT_LIBRARIES}
#> ${LIBXSLT_EXSLT_LIBRARY}
#> ${OPENSSL_LIBRARIES}
#> shlwapi
#> advapi32
#> )
#>
#> #---------------------------------------------------------------------------#
#> # MAIN EXECUTABLE MODULE #
#> #---------------------------------------------------------------------------#
#>
#> # Files
#>
#> set(GF_MODULE_NAME gf-bin)
#>
#> set(GF_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/gf)
#> set(GF_BINARY_DIR ${CMAKE_BINARY_DIR}/src/gf)
#> set(GF_MODULE_PATH ${CMAKE_BINARY_DIR}/bin/${GF_MODULE_NAME})
#>
#> file(GLOB GF_SOURCE ${CMAKE_SOURCE_DIR}/src/gf/*.c)
#> file(GLOB GF_HEADER ${CMAKE_SOURCE_DIR}/src/gf/*.h)
#> set(CMAKE_C_FLAGS ${GF_CMAKE_C_FLAGS})
#> include_directories(
#> ${CMAKE_BINARY_DIR}/src
#> ${CMAKE_SOURCE_DIR}/src)
#>
#> add_executable(${GF_MODULE_NAME} WIN32 ${GF_SOURCE})
#> target_link_libraries(
#> gf-bin
#> gf
#> "-Wl,-subsystem,console"
#> )
#> #
#> # now we rename gf-bin executable to gf using target properties
#> #
#> set_target_properties(gf-bin PROPERTIES OUTPUT_NAME gf)
#>
#> #
#> # config files
#> #
#>
#> configure_file(
#> ${CMAKE_SOURCE_DIR}/etc/gf.conf
#> ${CMAKE_BINARY_DIR}/etc/gf.conf
#> COPYONLY
#> )
#>
#> #---------------------------------------------------------------------------#
#> # TESTING MODULE #
#> #---------------------------------------------------------------------------#
#>
#> set(GF_TEST_MODULE_NAME gf-test)
#>
#> set(GF_SOURCE_DIR ${CMAKE_SOURCE_DIR}/test/gf)
#> set(GF_BINARY_DIR ${CMAKE_BINARY_DIR}/test/gf)
#> set(GF_MODULE_PATH ${CMAKE_BINARY_DIR}/bin/${GF_TEST_MODULE_NAME})
#>
#> set(GF_TEST_ROOT_PATH ${CMAKE_BINARY_DIR}/test)
#>
#> file(GLOB GF_SOURCE ${CMAKE_SOURCE_DIR}/test/src/*.c)
#> file(GLOB GF_HEADER ${CMAKE_SOURCE_DIR}/test/src/*.h)
#> set(CMAKE_C_FLAGS ${GF_CMAKE_C_FLAGS})
#> include_directories(
#> ${CMAKE_BINARY_DIR}/src
#> ${CMAKE_SOURCE_DIR}/src
#> ${CMAKE_BINARY_DIR}/test/src
#> ${CMAKE_SOURCE_DIR}/test/src)
#>
#> set(GF_TEST_CONFIG_H_IN ${CMAKE_SOURCE_DIR}/test/src/config.h.in)
#> set(GF_TEST_CONFIG_H ${CMAKE_BINARY_DIR}/test/src/config.h)
#> configure_file(${GF_TEST_CONFIG_H_IN} ${GF_TEST_CONFIG_H})
#>
#> #
#> # data directory
#> #
#>
#> file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/test/data)
#> file(
#> COPY
#> ${CMAKE_SOURCE_DIR}/test/data
#> DESTINATION
#> ${CMAKE_BINARY_DIR}/test
#> )
#>
#> add_executable(${GF_TEST_MODULE_NAME} WIN32 ${GF_SOURCE})
#> target_link_libraries(
#> gf-test
#> gf
#> cunit
#> "-Wl,-subsystem,console"
#> )
#>