-
Notifications
You must be signed in to change notification settings - Fork 36
/
CMakeLists.txt
executable file
·226 lines (195 loc) · 7.33 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
cmake_minimum_required(VERSION 3.14)
cmake_policy(SET CMP0077 NEW)
# set the project name
project(norm VERSION 1.5.10)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(COMMON src/common)
option(NORM_BUILD_EXAMPLES "Enables building of the examples in /examples." OFF)
set(NORM_CUSTOM_PROTOLIB_VERSION OFF CACHE STRING "Set a custom protolib version to use, ./protolib to use the local version")
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(dirfd "dirent.h" HAVE_DIRFD)
if(HAVE_DIRFD)
list(APPEND PLATFORM_DEFINITIONS HAVE_DIRFD)
endif()
check_cxx_symbol_exists(lockf "unistd.h" HAVE_LOCKF)
if(HAVE_LOCKF)
list(APPEND PLATFORM_DEFINITIONS HAVE_LOCKF)
endif()
check_cxx_symbol_exists(flock "sys/file.h" HAVE_FLOCK)
if(HAVE_FLOCK)
list(APPEND PLATFORM_DEFINITIONS HAVE_FLOCK)
endif()
if(NOT NORM_CUSTOM_PROTOLIB_VERSION)
find_package(Git)
if(Git_FOUND)
message("Git found: ${GIT_EXECUTABLE}")
execute_process(
COMMAND
${GIT_EXECUTABLE} ls-tree HEAD
RESULT_VARIABLE
GIT_SUBMODULE_STATUS
OUTPUT_VARIABLE
GIT_SUBMODULE
WORKING_DIRECTORY
${CMAKE_CURRENT_LIST_DIR}
)
string(REGEX MATCH "commit[ \t\r\n]*([a-z0-9]+)[ \t\r\n]*protolib" GIT_SUBMODULE_HASH_MATCH ${GIT_SUBMODULE})
if(GIT_SUBMODULE_HASH_MATCH)
set(NORM_PROTOKIT_GIT_TAG ${CMAKE_MATCH_1})
endif()
endif()
elseif(NOT NORM_CUSTOM_PROTOLIB_VERSION STREQUAL "./protolib")
set(NORM_PROTOKIT_GIT_TAG ${NORM_CUSTOM_PROTOLIB_VERSION})
endif()
if(NORM_PROTOKIT_GIT_TAG)
message(STATUS "Building protokit from ${NORM_PROTOKIT_GIT_TAG}")
include(FetchContent)
FetchContent_Declare(
protokit
GIT_REPOSITORY https://github.com/USNavalResearchLaboratory/protolib.git
GIT_TAG ${NORM_PROTOKIT_GIT_TAG}
)
FetchContent_MakeAvailable(protokit)
else()
message(STATUS "Building protokit from ${NORM_CUSTOM_PROTOLIB_VERSION}")
add_subdirectory(protolib)
endif()
# List header files
list(APPEND PUBLIC_HEADER_FILES
include/galois.h
include/normApi.h
include/normEncoder.h
include/normEncoderMDP.h
include/normEncoderRS16.h
include/normEncoderRS8.h
include/normFile.h
include/normMessage.h
include/normNode.h
include/normObject.h
include/normPostProcess.h
include/normSegment.h
include/normSession.h
include/normSimAgent.h
include/normVersion.h
)
# List platform-independent source files
list(APPEND COMMON_SOURCE_FILES
${COMMON}/galois.cpp
${COMMON}/normApi.cpp
${COMMON}/normEncoder.cpp
${COMMON}/normEncoderMDP.cpp
${COMMON}/normEncoderRS16.cpp
${COMMON}/normEncoderRS8.cpp
${COMMON}/normFile.cpp
${COMMON}/normMessage.cpp
${COMMON}/normNode.cpp
${COMMON}/normObject.cpp
${COMMON}/normSegment.cpp
${COMMON}/normSession.cpp )
# Setup platform independent include directory
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include )
# Setup platform dependent libraries, defines, source file and compiler flags
# (The "post processing" helper source is only needed for normApp build)
#if(MSVC)
# list(APPEND PLATFORM_LIBS Shell32)
# list(APPEND PLATFORM_DEFINITIONS _CONSOLE)
# list(APPEND PLATFORM_SOURCE_FILES src/win32/win32PostProcess.cpp)
#elseif(UNIX)
# list(APPEND PLATFORM_SOURCE_FILES src/unix/unixPostProcess.cpp)
#endif()
include(GNUInstallDirs)
# Setup target
add_library(norm ${PLATFORM_SOURCE_FILES} ${COMMON_SOURCE_FILES} ${PUBLIC_HEADER_FILES})
target_link_libraries(norm PRIVATE protokit::protokit)
target_link_libraries(norm PUBLIC ${PLATFORM_LIBS})
target_compile_definitions(norm PUBLIC ${PLATFORM_DEFINITIONS})
target_compile_options(norm PUBLIC ${PLATFORM_FLAGS})
target_include_directories(norm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(norm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
if(BUILD_SHARED_LIBS)
set_target_properties(norm PROPERTIES SOVERSION 1.5.10)
if(WIN32)
target_compile_definitions(norm PUBLIC NORM_USE_DLL)
endif()
endif()
if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
add_library(norm-static STATIC ${PLATFORM_SOURCE_FILES} ${COMMON_SOURCE_FILES} ${PUBLIC_HEADER_FILES})
target_link_libraries(norm-static PRIVATE protokit::protokit)
target_compile_definitions(norm-static PUBLIC ${PLATFORM_DEFINITIONS})
target_compile_options(norm-static PUBLIC ${PLATFORM_FLAGS})
target_include_directories(norm-static PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(norm-static PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
set_target_properties(norm-static PROPERTIES OUTPUT_NAME "norm" PREFIX "lib")
set(NORM_STATIC "norm-static")
endif()
# Install target
install( TARGETS norm ${NORM_STATIC} protokit EXPORT normTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/norm)
install( EXPORT normTargets
FILE normTargets.cmake
NAMESPACE norm::
DESTINATION ${INSTALL_CONFIGDIR}
)
install(FILES include/normApi.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Create pkg-config file norm.pc
# TODO: once waf is removed, norm.pc.in can be edited to use the variables CMake sets directly, and
# remove these re-definitions
set(VERSION ${PROJECT_VERSION})
set(PREFIX ${CMAKE_INSTALL_PREFIX})
set(LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(STATIC_LIBS "libprotokit.a")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/norm.pc.in ${CMAKE_CURRENT_BINARY_DIR}/norm.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/norm.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Create a ConfigVersion.cmake file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/normConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/normConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/normConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
# Install the config, configversion and custom find modules
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/normConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/normConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
##############################################
# Exporting from the build tree
export(EXPORT normTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/normTargets.cmake
NAMESPACE norm::)
# Register package in user's package registry
export(PACKAGE norm)
if(NORM_BUILD_EXAMPLES)
# Setup examples
list(APPEND examples
#normDataExample
normDataRecv
normDataSend
normFileRecv
normFileSend
normStreamRecv
normStreamSend
normMsgr
normStreamer
normCast
chant
normClient
normServer
#wintest
)
foreach(example ${examples})
add_executable(${example} examples/${example}.cpp examples/normSocket.cpp)
target_link_libraries(${example} PRIVATE norm protokit::protokit)
endforeach()
endif()