-
Notifications
You must be signed in to change notification settings - Fork 81
/
CMakeLists.txt
156 lines (133 loc) · 4.8 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
project(arcus)
cmake_minimum_required(VERSION 3.20)
include(cmake/StandardProjectSettings.cmake)
AssureOutOfSourceBuilds()
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)
generate_export_header(Arcus EXPORT_FILE_NAME src/ArcusExport.h)
option(BUILD_PYTHON "Build " ON)
option(BUILD_EXAMPLES "Build the example programs" OFF)
option(BUILD_STATIC "Build as a static library" OFF)
find_package(Protobuf 3.17.1 REQUIRED)
set(arcus_SRCS
src/Socket.cpp
src/SocketListener.cpp
src/MessageTypeStore.cpp
src/PlatformSocket.cpp
src/Error.cpp
)
set(arcus_HDRS
src/Socket.h
src/SocketListener.h
src/Types.h
src/MessageTypeStore.h
src/Error.h
${CMAKE_CURRENT_BINARY_DIR}/src/ArcusExport.h
)
set(ARCUS_VERSION 5.0.0)
set(ARCUS_SOVERSION 5)
if(BUILD_STATIC)
add_library(Arcus STATIC ${arcus_SRCS})
else()
add_library(Arcus SHARED ${arcus_SRCS})
endif()
set_project_standards(Arcus)
use_threads(Arcus)
set_rpath(TARGETS
Arcus
PATHS
"$<$<PLATFORM_ID:Linux>:usr/bin>"
"$<$<PLATFORM_ID:Linux>:usr/bin/lib>"
"$<$<PLATFORM_ID:Darwin>:../lib>"
RELATIVE)
target_include_directories(Arcus PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${PROTOBUF_INCLUDE_DIR}
)
target_link_libraries(Arcus PUBLIC protobuf::libprotobuf)
if(WIN32)
target_compile_definitions(Arcus PRIVATE -D_WIN32_WINNT=0x0600)
target_link_libraries(Arcus PUBLIC Ws2_32)
endif()
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
target_compile_definitions(Arcus PRIVATE -DARCUS_DEBUG)
endif()
set_target_properties(Arcus PROPERTIES
FRAMEWORK FALSE
VERSION ${ARCUS_VERSION}
SOVERSION ${ARCUS_SOVERSION}
PUBLIC_HEADER "${arcus_HDRS}"
DEFINE_SYMBOL MAKE_ARCUS_LIB
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
install(TARGETS Arcus
EXPORT Arcus-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Arcus
)
install(EXPORT Arcus-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Arcus
)
configure_package_config_file(ArcusConfig.cmake.in ${CMAKE_BINARY_DIR}/ArcusConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Arcus)
write_basic_package_version_file(${CMAKE_BINARY_DIR}/ArcusConfigVersion.cmake VERSION ${ARCUS_VERSION} COMPATIBILITY SameMajorVersion)
install(FILES
${CMAKE_BINARY_DIR}/ArcusConfig.cmake
${CMAKE_BINARY_DIR}/ArcusConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Arcus
)
# Create the Python bindings
if(BUILD_PYTHON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
if(NOT DEFINED Python_VERSION)
set(Python_VERSION
3.10
CACHE STRING "Python Version" FORCE)
message(STATUS "Setting Python version to ${Python_VERSION}. Set Python_VERSION if you want to compile against an other version.")
endif()
if(APPLE)
set(Python_FIND_FRAMEWORK NEVER)
endif()
find_package(cpython ${Python_VERSION} QUIET COMPONENTS Interpreter Development)
if(NOT TARGET cpython::cpython)
find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development)
else()
add_library(Python::Python ALIAS cpython::python)
set(Python_SITEARCH "${CMAKE_INSTALL_PREFIX}/lib/python3.10/site-packages")
set(Python_EXECUTABLE ${cpython_PACKAGE_FOLDER_RELEASE}/bin/python3)
set(ENV{PYTHONPATH} ${Python_SITEARCH})
endif()
message(STATUS "Linking and building ${project_name} against Python ${Python_VERSION}")
find_package(SIP REQUIRED 6.5.0)
add_library(pyArcus INTERFACE ${CMAKE_SOURCE_DIR}/python/PythonMessage.cpp)
set_project_standards(pyArcus)
set_rpath(TARGETS
pyArcus
PATHS
"$<$<PLATFORM_ID:Linux>:usr/bin>"
"$<$<PLATFORM_ID:Linux>:usr/bin/lib>"
"$<$<PLATFORM_ID:Darwin>:../lib>"
"$<$<PLATFORM_ID:Darwin>:../Resources/lib/>"
"../../"
RELATIVE)
use_threads(pyArcus)
target_include_directories(pyArcus
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/python/>
)
target_compile_features(pyArcus INTERFACE cxx_std_17)
target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python)
add_sip_module(pyArcus)
if (DEFINED Python_SITELIB_LOCAL)
install_sip_module(pyArcus ${Python_SITELIB_LOCAL})
else()
install_sip_module(pyArcus)
endif ()
endif()