-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
184 lines (150 loc) · 5.1 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
cmake_minimum_required(VERSION 3.12)
project(wows-geometry)
# Project version (sematic versionning)
set(wows-geometry_VERSION_MAJOR 0)
set(wows-geometry_VERSION_MINOR 1)
set(wows-geometry_VERSION_PATCH 0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
find_library(CUNIT_LIBRARY cunit)
set(wows-geometry_VERSION
${wows-geometry_VERSION_MAJOR}.${wows-geometry_VERSION_MINOR}.${wows-geometry_VERSION_PATCH}
)
add_custom_target(
tag
COMMAND git tag -a ${wows-geometry_VERSION} -m
"tagging version ${wows-geometry_VERSION}"
COMMAND git push origin ${wows-geometry_VERSION})
# set version as a definition
set(CMAKE_C_FLAGS
"${CMAKE_CXX_FLAGS} -DBFD_VERSION='\"${wows-geometry_VERSION}\"'")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -DBFD_VERSION='\"${wows-geometry_VERSION}\"'")
# Options
option(DEBUG "compile with debug symbol" OFF)
option(STATIC "compile statically" OFF)
option(USE_CLANG "build application with clang" OFF)
option(USE_GCC "build application with gcc" OFF)
option(FORCELE "force little endian architecture" OFF)
option(COVERAGE "Enable code coverage" OFF)
option(BUILD_DOC "Build documentation" OFF)
option(BUILD_TESTS "Build tests" OFF)
if(USE_CLANG)
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CC_COMPILER "clang")
endif(USE_CLANG)
if(USE_GCC)
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CC_COMPILER "gcc")
endif(USE_GCC)
if(DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
set(CMAKE_BUILD_TYPE Debug)
endif(DEBUG)
if(STATIC)
set(SHARED "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBRARIES OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
else(STATIC)
set(SHARED "SHARED")
endif(STATIC)
if(UNIX)
link_libraries(m)
endif(UNIX)
# 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")
# 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-geometry ${SHARED} ${WOWS_SOURCES})
set_target_properties(
wows-geometry PROPERTIES VERSION ${wows-geometry_VERSION}
SOVERSION ${wows-geometry_VERSION_MAJOR})
# Compile the executable
add_executable(wows-geometry-cli wows-geometry.c)
target_link_libraries(wows-geometry ${ZLIB_LIBRARIES} ${PCRE_LIBRARY})
target_link_libraries(wows-geometry-cli wows-geometry ${ZLIB_LIBRARIES}
${PCRE_LIBRARY})
if(BUILD_TESTS)
if(CUNIT_LIBRARY)
include(CTest)
add_test(NAME wows-geometry-test COMMAND wows-geometry-test)
add_executable(wows-geometry-test tests/tests.c)
target_link_libraries(wows-geometry-test wows-geometry ${ZLIB_LIBRARIES}
${PCRE_LIBRARY} ${CUNIT_LIBRARY})
# Add the test target
add_custom_target(
tests
COMMAND wows-geometry-test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests")
add_dependencies(tests wows-geometry-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-geometry-test)
add_dependencies(coverage wows-geometry-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-geometry wows-geometry-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-geometry.h DESTINATION ${INCLUDE_INSTALL_DIR})