-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
153 lines (136 loc) · 3.49 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
#
# Cmake project settings
#
cmake_minimum_required(VERSION 3.12)
project(dnssd)
include(CMakeToolsHelpers OPTIONAL)
include(CMakePackageConfigHelpers)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(_PROJECT_ROOT ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "Root" FORCE)
enable_testing()
#
# output paths
#
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
set(source_c_files
src/DebugServices.c
src/dnssd_clientlib.c
src/dnssd_clientstub.c
src/dnssd_ipc.c
src/GenLinkedList.c
)
if(WIN32)
set(shared_c_files
src/dllmain.c
src/dnssd.def
)
add_definitions(
-D_WINDOWS=1
-D_WINSOCK_DEPRECATED_NO_WARNINGS=1
-DMDNS_DEBUGMSGS=0
-DWIN32_LEAN_AND_MEAN=1
-DNOT_HAVE_SA_LEN=1
-DUSE_TCP_LOOPBACK=1
-D_CRT_SECURE_NO_DEPRECATE=1
-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1
)
else()
# todo
endif()
# Shared library
add_library(dnssd SHARED ${source_c_files} ${shared_c_files})
set_property(TARGET dnssd PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(dnssd
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
PUBLIC
$<INSTALL_INTERFACE:include>
)
if(WIN32)
target_link_libraries(dnssd
PRIVATE ws2_32
PRIVATE iphlpapi
PRIVATE secur32
PRIVATE crypt32
)
set_target_properties(dnssd PROPERTIES PREFIX "")
else()
# todo
endif()
# Static library
add_library(dnssd-static STATIC ${source_c_files})
set_property(TARGET dnssd-static PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(dnssd-static
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
PUBLIC
$<INSTALL_INTERFACE:include>
)
if(WIN32)
target_sources(dnssd-static
PRIVATE
src/dllmain.c
)
target_compile_definitions(dnssd-static
PRIVATE
mdns_STATIC
)
target_link_libraries(dnssd-static
PUBLIC ws2_32
PUBLIC iphlpapi
PUBLIC secur32
PUBLIC crypt32
)
set_target_properties(dnssd-static PROPERTIES PREFIX "")
else()
# todo
endif()
add_executable(dns-sd test/dns-sd.c test/ClientCommon.c)
set_property(TARGET dns-sd PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(dns-sd PUBLIC src PUBLIC test)
target_compile_definitions(dns-sd
PRIVATE _CONSOLE
PRIVATE NOT_HAVE_GETOPT
PRIVATE NOT_HAVE_SETLINEBUF
)
target_link_libraries(dns-sd PRIVATE dnssd)
target_link_libraries(dns-sd
PRIVATE ws2_32
)
# Create and install a config file for making the library useable from CMake
configure_package_config_file(
cmake/DNSSDConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DNSSDConfig.cmake"
INSTALL_DESTINATION lib/cmake
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/DNSSDConfigVersion.cmake"
VERSION 1.0.0
COMPATIBILITY SameMajorVersion
)
install(
TARGETS dnssd dnssd-static
EXPORT DNSSDTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(
FILES
src/dns_sd.h
DESTINATION include
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/DNSSDConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/DNSSDConfigVersion.cmake"
DESTINATION lib/cmake
)
install(EXPORT DNSSDTargets
DESTINATION lib/cmake
NAMESPACE DNSSD::
)