forked from gocarlos/mdns_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
115 lines (98 loc) · 3.7 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
cmake_minimum_required(VERSION 3.11)
project(
mdns_cpp
VERSION 0.1.0
LANGUAGES CXX)
option(MDNS_CPP_BUILD_EXAMPLE "Build example executables" ON)
# Set the output of the libraries and executables.
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
# ##############################################################################
# library
# ##############################################################################
add_library(${PROJECT_NAME})
target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_sources(
${PROJECT_NAME}
PRIVATE include/mdns_cpp/macros.hpp
include/mdns_cpp/defs.hpp
include/mdns_cpp/logger.hpp
src/logger.cpp
src/mdns.h
src/mdns.cpp
include/mdns_cpp/mdns.hpp
src/utils.cpp
include/mdns_cpp/utils.hpp)
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
else()
target_compile_options(
${PROJECT_NAME}
PRIVATE -Wall -Wextra -pedantic
# mdns.h uses static functions in the header file
-Wno-unused-function)
endif()
if(WIN32)
target_link_libraries(${PROJECT_NAME} INTERFACE iphlpapi ws2_32)
endif()
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
# ##############################################################################
# example
# ##############################################################################
find_package(Threads REQUIRED)
if(MDNS_CPP_BUILD_EXAMPLE)
add_executable(${PROJECT_NAME}_service_example
${CMAKE_CURRENT_LIST_DIR}/example/service.cpp)
target_link_libraries(${PROJECT_NAME}_service_example ${PROJECT_NAME}
Threads::Threads)
add_executable(${PROJECT_NAME}_discovery_example
${CMAKE_CURRENT_LIST_DIR}/example/discovery.cpp)
target_link_libraries(${PROJECT_NAME}_discovery_example ${PROJECT_NAME}
Threads::Threads)
add_executable(${PROJECT_NAME}_query_example
${CMAKE_CURRENT_LIST_DIR}/example/query.cpp)
target_link_libraries(${PROJECT_NAME}_query_example ${PROJECT_NAME}
Threads::Threads)
endif()
# ##############################################################################
# install
# ##############################################################################
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(
EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
COMPONENT dev)
install(
FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
COMPONENT dev)
install(
DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
FILES_MATCHING
PATTERN "*.hpp")