-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
131 lines (101 loc) · 4.05 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
#
# Copyright © 2019 CZ.NIC, z. s. p. o.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
cmake_minimum_required(VERSION 3.5)
project(cdns VERSION 1.3.0)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(Boost REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LibLZMA REQUIRED)
find_package(Doxygen)
option(BUILD_TESTS "Set to ON to build tests that use Google Test framework" OFF)
option(BUILD_DOC "Generate Doxygen documentation" ON)
option(BUILD_CLI_TOOLS "Build a set of command line tools to inspect C-DNS files" ON)
option(BUILD_PYTHON_BINDINGS "Generate Python bindings" OFF)
file(GLOB sources "src/*.cpp")
file(GLOB headers "src/*.h")
add_library(cdns SHARED
${sources}
)
target_link_libraries(cdns ${Boost_LIBRARIES} ZLIB::ZLIB ${LIBLZMA_LIBRARIES})
target_include_directories(cdns PUBLIC ${Boost_INCLUDE_DIRS} ${LIBLZMA_INCLUDE_DIRS})
include(CheckCCompilerFlag)
check_c_compiler_flag(-msse4 SSE4_FLAG)
if(SSE4_FLAG)
target_compile_options(cdns PUBLIC -msse4)
else()
message(FATAL_ERROR "SSE4 is required for compilation!")
endif()
set_target_properties(cdns PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(cdns PROPERTIES SOVERSION 1)
set_target_properties(cdns PROPERTIES PUBLIC_HEADER "${headers}")
configure_file(src/cdns.pc.in src/cdns.pc @ONLY)
target_include_directories(cdns PRIVATE .)
install(TARGETS cdns
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cdns
)
install(FILES ${CMAKE_BINARY_DIR}/src/cdns.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
if (BUILD_CLI_TOOLS)
# cdns-merge cli tool
add_executable(cdns-merge src/bin/cdns_merge.cpp)
target_link_libraries(cdns-merge PUBLIC cdns)
# cdns-itemcount cli tool
add_executable(cdns-itemcount src/bin/cdns_itemcount.cpp)
target_link_libraries(cdns-itemcount PUBLIC cdns)
# cdns-preamble cli tool
add_executable(cdns-preamble src/bin/cdns_preamble.cpp)
target_link_libraries(cdns-preamble PUBLIC cdns)
# cdns-blocks cli tool
add_executable(cdns-blocks src/bin/cdns_blocks.cpp)
target_link_libraries(cdns-blocks PUBLIC cdns)
# cdns-items cli tool
add_executable(cdns-items src/bin/cdns_items.cpp)
target_link_libraries(cdns-items PUBLIC cdns)
install(TARGETS cdns-merge cdns-itemcount cdns-preamble cdns-blocks cdns-items RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(BUILD_CLI_TOOLS)
if (BUILD_PYTHON_BINDINGS)
find_package(Python3 REQUIRED)
find_package(pybind11 REQUIRED)
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/python/setup.py.in")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
set(PYPROJECT "${CMAKE_CURRENT_SOURCE_DIR}/python/pyproject.toml")
file(COPY ${PYPROJECT} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
configure_file(${SETUP_PY_IN} ${SETUP_PY})
add_custom_target(pycdns ALL
COMMAND pip3 install --prefix=${CMAKE_CURRENT_BINARY_DIR}/build_python/ ${CMAKE_CURRENT_BINARY_DIR}
)
add_dependencies(pycdns cdns)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build_python/
DESTINATION ${CMAKE_INSTALL_PREFIX}
PATTERN "*"
)
endif(BUILD_PYTHON_BINDINGS)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
add_test(NAME UnitTests COMMAND tests)
endif(BUILD_TESTS)
if (BUILD_DOC)
if(DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API Doxygen documentation"
VERBATIM)
else(DOXYGEN_FOUND)
message("Install Doxygen to generate documentation")
endif(DOXYGEN_FOUND)
endif(BUILD_DOC)