forked from worldforge/wfmath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
232 lines (184 loc) · 6.97 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
cmake_minimum_required(VERSION 3.2)
project(wfmath)
set(CMAKE_CXX_STANDARD 14)
include(GNUInstallDirs)
include(FindPkgConfig)
# Version setup
set(WFMATH_VERSION_MAJOR 1)
set(WFMATH_VERSION_MINOR 0)
set(WFMATH_VERSION_PATCH 3)
set(VERSION ${WFMATH_VERSION_MAJOR}.${WFMATH_VERSION_MINOR}.${WFMATH_VERSION_PATCH})
set(SUFFIX -${WFMATH_VERSION_MAJOR}.${WFMATH_VERSION_MINOR})
set(WFMATH_ABI_CURRENT 1)
set(WFMATH_ABI_REVISION 0)
set(WFMATH_ABI_AGE 0)
math(EXPR WFMATH_SOVERSION ${WFMATH_ABI_CURRENT}-${WFMATH_ABI_AGE})
set(WFMATH_ABI_VERSION ${WFMATH_SOVERSION}.${WFMATH_ABI_AGE}.${WFMATH_ABI_REVISION})
if (WIN32)
set(BUILD_SHARED_LIBS OFF) # On Win32, only static libs are exporting all symbols.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W0") # For now, disable warnings to speed up compile time
else ()
set(BUILD_SHARED_LIBS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif ()
include_directories("${PROJECT_SOURCE_DIR}")
# Meta data
set(DESCRIPTION "A math library for the Worldforge system.")
# This macro defines a library
macro(wf_add_library _LIB_NAME _SOURCE_FILES_VAR _HEADER_FILES_VAR)
add_library(${_LIB_NAME} ${${_SOURCE_FILES_VAR}} ${${_HEADER_FILES_VAR}})
set_target_properties(${_LIB_NAME} PROPERTIES
VERSION ${WFMATH_ABI_VERSION}
SOVERSION ${WFMATH_SOVERSION})
install(TARGETS ${_LIB_NAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
foreach (file ${${_HEADER_FILES_VAR}})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${file} DESTINATION include/${PROJECT_NAME}${SUFFIX}/${dir})
endforeach ()
set(PKG_CONFIG_LIBS "-l${_LIB_NAME} ${PKG_CONFIG_LIBS}")
endmacro()
# Add a "check" target, which builds and runs the tests.
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
#Macro for adding a test. The test name will be extracted from the name of the first submitted file.
#Additional files can be submitted as varargs.
macro(wf_add_test TEST_FILE)
get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE)
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_FILE} ${ARGN})
target_link_libraries(${TEST_NAME} ${PROJECT_NAME}${SUFFIX})
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
add_dependencies(check ${TEST_NAME})
endmacro()
if (!WIN32)
# We only need Atlas for tests
pkg_check_modules(WF atlascpp-0.7>=0.7)
if (WF_FOUND)
wf_add_test(atlas/atlas_0_7_test.cpp)
target_link_libraries(atlas_0_7_test ${WF_LDFLAGS})
target_include_directories(atlas_0_7_test PUBLIC ${WF_INCLUDE_DIRS})
endif (WF_FOUND)
endif (!WIN32)
# Define source files for libraries
set(SOURCE_FILES
wfmath/axisbox.cpp
wfmath/ball.cpp
wfmath/const.cpp
wfmath/int_to_string.cpp
wfmath/intersect.cpp
wfmath/line.cpp
wfmath/point.cpp
wfmath/polygon.cpp
wfmath/polygon_intersect.cpp
wfmath/probability.cpp
wfmath/quaternion.cpp
wfmath/randgen.cpp
wfmath/rotbox.cpp
wfmath/rotmatrix.cpp
wfmath/segment.cpp
wfmath/stream.cpp
wfmath/timestamp.cpp
wfmath/vector.cpp)
set(HEADER_FILES
wfmath/atlasconv.h
wfmath/axisbox.h
wfmath/axisbox_funcs.h
wfmath/ball.h
wfmath/ball_funcs.h
wfmath/basis.h
wfmath/const.h
wfmath/error.h
wfmath/general_test.h
wfmath/int_to_string.h
wfmath/intersect.h
wfmath/intersect_decls.h
wfmath/line.h
wfmath/line_funcs.h
wfmath/MersenneTwister.h
wfmath/miniball.h
wfmath/miniball_funcs.h
wfmath/point.h
wfmath/point_funcs.h
wfmath/polygon.h
wfmath/polygon_funcs.h
wfmath/polygon_intersect.h
wfmath/probability.h
wfmath/quaternion.h
wfmath/randgen.h
wfmath/rotbox.h
wfmath/rotbox_funcs.h
wfmath/rotmatrix.h
wfmath/rotmatrix_funcs.h
wfmath/segment.h
wfmath/segment_funcs.h
wfmath/shuffle.h
wfmath/stream.h
wfmath/timestamp.h
wfmath/vector.h
wfmath/vector_funcs.h
wfmath/wfmath.h
wfmath/wrapped_array.h
wfmath/zero.h)
wf_add_library(${PROJECT_NAME}${SUFFIX} SOURCE_FILES HEADER_FILES)
# pkg-config files
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}${SUFFIX}.pc @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}${SUFFIX}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# RPM spec files
#TODO: fix these
configure_file(${PROJECT_NAME}.spec.in ${PROJECT_NAME}.spec @ONLY)
#TODO: fix these
configure_file(mingw32-${PROJECT_NAME}.spec.in mingw32-${PROJECT_NAME}.spec @ONLY)
# Add test
enable_testing()
wf_add_test(wfmath/ball_test.cpp)
wf_add_test(wfmath/const_test.cpp)
wf_add_test(wfmath/intstring_test.cpp)
wf_add_test(wfmath/line_test.cpp)
wf_add_test(wfmath/point_test.cpp)
wf_add_test(wfmath/polygon_test.cpp)
wf_add_test(wfmath/probability_test.cpp)
wf_add_test(wfmath/quaternion_test.cpp)
wf_add_test(wfmath/randgen_test.cpp)
wf_add_test(wfmath/rotmatrix_test.cpp)
wf_add_test(wfmath/shape_test.cpp)
wf_add_test(wfmath/timestamp_test.cpp)
wf_add_test(wfmath/vector_test.cpp)
# Doxygen support, exports a "docs" target.
find_package(Doxygen)
configure_file(doc/Doxyfile.in Doxyfile @ONLY)
if (DOXYGEN_FOUND)
set(DOXYGEN_INPUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
set(DOXYGEN_OUTPUT doc)
add_custom_command(
OUTPUT ${DOXYGEN_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E echo_append "Building API Documentation..."
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT}
COMMAND ${CMAKE_COMMAND} -E echo "Done."
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${DOXYGEN_INPUT}
)
add_custom_target(docs DEPENDS ${DOXYGEN_OUTPUT})
endif (DOXYGEN_FOUND)
add_custom_command(
OUTPUT ChangeLog
COMMAND ${CMAKE_SOURCE_DIR}/support/generate-ChangeLog.sh ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR} 8bd480b053190ffde2afe33af66f484953036f5a
)
add_custom_target(changelog DEPENDS ChangeLog)
# Packaging (for source tarballs
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${DESCRIPTION})
set(CPACK_PACKAGE_VENDOR "Worldforge")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR "${WFMATH_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${WFMATH_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${WFMATH_VERSION_PATCH}")
#set(CPACK_INSTALL_SCRIPT "sh ${CMAKE_SOURCE_DIR}/support/generate-ChangeLog.sh ${CMAKE_SOURCE_DIR} ${CPACK_PACKAGE_INSTALL_DIRECTORY} 8bd480b053190ffde2afe33af66f484953036f5a")
set(CPACK_SOURCE_GENERATOR TBZ2 ZIP)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION}" CACHE INTERNAL "tarball basename")
set(CPACK_SOURCE_IGNORE_FILES
# no hidden files
"/\\\\..+$"
"~$"
)
include(CPack)