-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
181 lines (149 loc) · 5.15 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
cmake_minimum_required(VERSION 3.12)
project(wows-depack)
# Project version (sematic versionning)
set(wows-depack_VERSION_MAJOR 0)
set(wows-depack_VERSION_MINOR 1)
set(wows-depack_VERSION_PATCH 0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
if(STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(ZLIB_USE_STATIC_LIBS ON)
set(BUILD_SHARED_LIBRARIES OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
else(STATIC)
set(SHARED "SHARED")
endif(STATIC)
find_package(ZLIB REQUIRED)
find_package(PCRE REQUIRED)
find_library(CUNIT_LIBRARY cunit)
set(wows-depack_VERSION
${wows-depack_VERSION_MAJOR}.${wows-depack_VERSION_MINOR}.${wows-depack_VERSION_PATCH}
)
add_custom_target(
tag
COMMAND git tag -a ${wows-depack_VERSION} -m
"tagging version ${wows-depack_VERSION}"
COMMAND git push origin ${wows-depack_VERSION})
# set version as a definition
set(CMAKE_C_FLAGS
"${CMAKE_CXX_FLAGS} -DBFD_VERSION='\"${wows-depack_VERSION}\"'")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -DBFD_VERSION='\"${wows-depack_VERSION}\"'")
# Options
option(DEBUG "compile with debug symbol" OFF)
option(STATIC "compile statically" OFF)
option(COVERAGE "Enable code coverage" OFF)
option(BUILD_DOC "Build documentation" OFF)
option(BUILD_TESTS "Build tests" OFF)
if(DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
set(CMAKE_BUILD_TYPE Debug)
endif(DEBUG)
# Build external dependancies if we are on OSX
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Mac OS X specific code
set(EXTERNAL_ICONV "iconv")
set(EXTERNAL_ARGP "argp")
add_definitions(-DDARWIN)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(UNIX)
link_libraries(m)
endif(UNIX)
# linking directories
link_directories(${CMAKE_BINARY_DIR}/ /usr/local/lib /usr/lib/)
# headers directories
include_directories(./inc/ ${ZLIB_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS}
/usr/include/ /sw/include/)
file(GLOB WOWS_SOURCES lib/*.c)
add_library(wows-depack ${SHARED} ${WOWS_SOURCES})
set_target_properties(
wows-depack PROPERTIES VERSION ${wows-depack_VERSION}
SOVERSION ${wows-depack_VERSION_MAJOR})
# Compile the executable
add_executable(wows-depack-cli wows-depack.c)
target_link_libraries(wows-depack ${ZLIB_LIBRARIES} ${PCRE_LIBRARY})
target_link_libraries(wows-depack-cli wows-depack ${ZLIB_LIBRARIES}
${PCRE_LIBRARY})
if(BUILD_TESTS)
if(CUNIT_LIBRARY)
include(CTest)
add_test(NAME wows-depack-test COMMAND wows-depack-test)
add_test(NAME hashmap-test COMMAND hashmap-test)
add_test(NAME hashmap-bench COMMAND hashmap-test)
set_property(TEST hashmap-bench PROPERTY ENVIRONMENT "BENCH=1")
add_executable(wows-depack-test tests/tests.c)
add_executable(hashmap-test lib/hashmap.c)
set_target_properties(hashmap-test PROPERTIES COMPILE_FLAGS
"-DHASHMAP_TEST")
target_link_libraries(wows-depack-test wows-depack ${ZLIB_LIBRARIES}
${PCRE_LIBRARY} ${CUNIT_LIBRARY})
# Add the test target
add_custom_target(
tests
COMMAND wows-depack-test
COMMAND hashmap-test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests")
add_dependencies(tests wows-depack-test)
if(COVERAGE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
include(CodeCoverage)
setup_target_for_coverage(
NAME
coverage
EXECUTABLE
ctest
-j
${n_cores}
DEPENDENCIES
wows-depack-test
hashmap-test)
add_dependencies(coverage wows-depack-test)
endif(COVERAGE)
else(CUNIT_LIBRARY)
message(WARNING "CUnit not found; not building tests.")
endif(CUNIT_LIBRARY)
endif(BUILD_TESTS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall")
if(NOT LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR lib)
endif()
if(NOT BIN_INSTALL_DIR)
set(BIN_INSTALL_DIR bin)
endif()
if(NOT INCLUDE_INSTALL_DIR)
set(INCLUDE_INSTALL_DIR include)
endif()
# install binaries and library
install(
TARGETS wows-depack wows-depack-cli
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
# check if Doxygen is installed
if(BUILD_DOC)
# set input and output files
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the
# application
add_custom_target(
doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
else(DOXYGEN_FOUND)
message(
"Doxygen need to be installed to generate the doxygen documentation")
endif(DOXYGEN_FOUND)
endif(BUILD_DOC)
# install header file
install(FILES inc/wows-depack.h DESTINATION ${INCLUDE_INSTALL_DIR})