forked from NATTools/sockaddrutil
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
67 lines (52 loc) · 2.59 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
cmake_minimum_required(VERSION 3.22)
set(LIB_NAME sockaddrutil)
project(${LIB_NAME} C)
set(CMAKE_C_STANDARD 11)
add_subdirectory(src)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
cmake_minimum_required(VERSION 3.22)
option(SOCKADDRUTIL_BUILD_TESTS "whether or not tests should be built" ON)
option(SOCKADDRUTIL_BUILD_PACKAGE "whether or not the package should be built" ON)
option(SOCKADDRUTIL_INSTALL "whether or not to enable the install rule" ON)
if(SOCKADDRUTIL_BUILD_PACKAGE)
set(package_files include/ src/ cmake/ CMakeLists.txt LICENSE)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sokaddrutil-src.zip
COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_CURRENT_BINARY_DIR}/sokaddrutil-src.zip --format=zip -- ${package_files}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${package_files})
add_custom_target(sokaddrutil_package DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/sokaddrutil-src.zip)
endif()
if(SOCKADDRUTIL_BUILD_TESTS)
set(DOCTEST_NO_INSTALL ON)
enable_testing()
add_subdirectory(test)
endif()
if(SOCKADDRUTIL_ENABLE_INSTALL)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
install(TARGETS sockaddrutil
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${LIB_NAME}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
configure_package_config_file(
cmake/sockaddrutilConfig.cmake.in
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# YYYY.MM.N1 is compatible with YYYY.MM.N2.
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMinorVersion)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(DIRECTORY include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h")
endif()
endif()