forked from fmela/libdict
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
157 lines (134 loc) · 4.65 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
# require a modern version of cmake.
cmake_minimum_required(VERSION 3.10)
# set the project name and version.
project(libdict VERSION 1.0.0 LANGUAGES C)
# set C standard to C11 without extensions
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# enable verbose compiler warnings.
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Werror -Wall -Wextra -Wno-deprecated-declarations -pedantic )
endif()
# options: should we build static library, shared library, tests, tools?
option(LIBDICT_STATIC "Compile libdict.a" YES)
option(LIBDICT_SHARED "Compile libdict.so" YES)
option(LIBDICT_TOOLS "Compile tools (demo, benchmark, anagram)" YES)
option(LIBDICT_TESTS "Compile tests" YES)
# if we build a shared lib, have the tests and tools link against that,
# otherwise link against static library.
if(LIBDICT_SHARED)
set(DICT_LIB libdict-shared)
else()
set(DICT_LIB libdict-static)
endif()
# list of source files.
set(LIBDICT_SOURCES
src/dict.c
src/hashtable.c
src/hashtable2.c
src/hashtable_common.c
src/hb_tree.c
src/pr_tree.c
src/rb_tree.c
src/skiplist.c
src/sp_tree.c
src/tr_tree.c
src/tree_common.c
src/wb_tree.c
)
# list of header files.
set(LIBDICT_HEADERS
include/dict.h
include/hashtable.h
include/hashtable2.h
include/hb_tree.h
include/pr_tree.h
include/rb_tree.h
include/skiplist.h
include/sp_tree.h
include/tr_tree.h
include/wb_tree.h
)
# adds public include path
include_directories(include)
# adds root project path to module path
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
# build static library libdict.a
add_library(libdict-static ${LIBDICT_SOURCES} ${LIBDICT_HEADERS})
set_target_properties(libdict-static PROPERTIES
OUTPUT_NAME dict)
# build shared library libdict.so
add_library(libdict-shared SHARED ${LIBDICT_SOURCES} ${LIBDICT_HEADERS})
set_target_properties(libdict-shared PROPERTIES
OUTPUT_NAME dict
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
# build libdict demo executable (interactive)
add_executable(libdict-demo demo.c)
target_link_libraries(libdict-demo ${DICT_LIB})
# build libdict benchmark executable
add_executable(libdict-benchmark benchmark.c)
target_link_libraries(libdict-benchmark ${DICT_LIB})
target_include_directories(libdict-benchmark PRIVATE src)
# build libdict anagram executable
add_executable(libdict-anagram anagram.c)
target_link_libraries(libdict-anagram ${DICT_LIB})
target_include_directories(libdict-anagram PRIVATE src)
# unless disabled, build unit tests
if(LIBDICT_TESTS)
find_package(CUnit REQUIRED)
enable_testing()
add_executable(libdict-tests unit_tests.c)
target_include_directories(libdict-tests PRIVATE ${CUNIT_INCLUDE_DIRS})
target_link_libraries (libdict-tests ${DICT_LIB})
target_link_libraries(libdict-tests ${CUNIT_LIBRARIES})
add_test(
NAME libdict-tests
COMMAND libdict-tests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
# disable static library building by default if requested
if(NOT LIBDICT_STATIC)
set_target_properties(libdict-static PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
# disable shared library building by default if requested
if(NOT LIBDICT_SHARED)
set_target_properties(libdict-shared PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
# disable tools building by default if not requested
if(NOT LIBDICT_TOOLS)
set_target_properties(libdict-demo PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(libdict-benchmark PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(libdict-anagram PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
# install headers
install(FILES ${LIBDICT_HEADERS}
DESTINATION include/libdict
COMPONENT dev)
# install libraries, shared library is part of runtime whereas static library
# is only needed for development
install(TARGETS libdict-shared libdict-static
LIBRARY DESTINATION lib COMPONENT lib
ARCHIVE DESTINATION lib COMPONENT dev
OPTIONAL)
# tools are in separate package
install(TARGETS libdict-demo libdict-benchmark libdict-anagram
RUNTIME DESTINATION bin COMPONENT tools
OPTIONAL)
# options for cpack to generate releases
set(CPACK_COMPONENT_TOOLS_DEPENDS "lib")
set(CPACK_COMPONENT_DEV_DEPENDS "lib")
set(CPACK_GENERATOR "DEB")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS YES)
set(CPACK_DEBIAN_LIB_PACKAGE_NAME "libdict")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_PACKAGE_CONTACT "Christian Giese <[email protected]>")
if (NOT DEFINED LIBDICT_VERSION)
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
else()
set(CPACK_PACKAGE_VERSION ${LIBDICT_VERSION})
endif()
include(CPack)