-
Notifications
You must be signed in to change notification settings - Fork 377
/
CMakeLists.txt
142 lines (116 loc) · 5.48 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
cmake_minimum_required( VERSION 3.22.0 FATAL_ERROR )
project( "restbed" VERSION 4.8.0 LANGUAGES CXX )
message( " " )
message( "##############################################################" )
message( "# #" )
message( "# Copyright 2013-2024, Corvusoft Ltd, All Rights Reserved. #" )
message( "# #" )
message( "# Restbed is dual-licensed requiring commerical entities #" )
message( "# to acquire a Corvusoft Permissive License, Contact #" )
message( "# [email protected] for details. #" )
message( "# #" )
message( "##############################################################" )
message( " " )
#
# Build Options
#
option( BUILD_TESTS "Build unit tests." ON )
option( BUILD_SSL "Build secure socket layer support." ON )
option( BUILD_IPC "Build unix domain socket layer support." OFF )
option( BUILD_STATIC_LIBRARY "Build static library" ON )
option( BUILD_SHARED_LIBRARY "Build shared library" ON )
option( BUILD_DEVEL_PACKAGE "Build development package (including C++ header files)" ON )
#
# Configuration
#
set( CMAKE_CXX_STANDARD 14 )
set( INCLUDE_DIR "${PROJECT_SOURCE_DIR}/source" )
set( SOURCE_DIR "${PROJECT_SOURCE_DIR}/source/corvusoft/${PROJECT_NAME}" )
if ( NOT DEFINED CMAKE_INSTALL_LIBDIR )
set( CMAKE_INSTALL_LIBDIR "library")
endif ( )
if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set( CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/distribution" CACHE PATH "Install path prefix" FORCE )
endif ( )
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_WIN32_WINNT=0x0A00 /W4 /wd4068 /wd4702 /wd4996 /wd4265" )
endif ( )
if( NOT WIN32 )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Weffc++ -pedantic -Wno-unknown-pragmas -Wno-deprecated-declarations -Wno-non-virtual-dtor" )
endif ( )
if ( UNIX AND NOT APPLE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
endif ( )
if ( APPLE )
set( CMAKE_MACOSX_RPATH ON )
endif ( )
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake" )
find_package( asio REQUIRED )
if ( BUILD_SSL )
add_definitions( "-DBUILD_SSL" )
find_package( openssl REQUIRED )
endif ( )
if ( BUILD_IPC )
add_definitions( "-DBUILD_IPC" )
endif ( )
if ( WIN32 )
add_definitions( -DWIN_DLL_EXPORT )
endif ( )
#
# Build
#
file( GLOB_RECURSE MANIFEST "${SOURCE_DIR}/*.cpp" )
if ( BUILD_STATIC_LIBRARY )
set( STATIC_LIBRARY_NAME "${PROJECT_NAME}-static" )
add_library( ${STATIC_LIBRARY_NAME} STATIC ${MANIFEST} )
set_property( TARGET ${STATIC_LIBRARY_NAME} PROPERTY CXX_STANDARD 14 )
set_property( TARGET ${STATIC_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON )
set_target_properties( ${STATIC_LIBRARY_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} )
target_include_directories(${STATIC_LIBRARY_NAME} SYSTEM PUBLIC ${asio_INCLUDE} ${ssl_INCLUDE} ${INCLUDE_DIR})
if ( BUILD_SSL )
target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_STATIC} ${crypto_LIBRARY_STATIC} ${CMAKE_DL_LIBS} )
else ( )
target_link_libraries( ${STATIC_LIBRARY_NAME} ${CMAKE_DL_LIBS} )
endif ( )
endif ( )
if ( BUILD_SHARED_LIBRARY )
set( SHARED_LIBRARY_NAME "${PROJECT_NAME}-shared" )
add_library( ${SHARED_LIBRARY_NAME} SHARED ${MANIFEST} )
set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_STANDARD 14 )
set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON )
if ( WIN32 )
# Workaround to avoid name clash of static lib and dynamic import lib under windows.
set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}-shared" )
else ( )
set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} )
endif ( )
set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} )
target_include_directories(${SHARED_LIBRARY_NAME} SYSTEM PUBLIC ${asio_INCLUDE} ${ssl_INCLUDE} ${INCLUDE_DIR})
if ( BUILD_SSL )
target_link_libraries( ${SHARED_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_SHARED} ${crypto_LIBRARY_SHARED} )
else ( )
target_link_libraries( ${SHARED_LIBRARY_NAME} )
endif ( )
endif ( )
if ( BUILD_TESTS )
find_package( catch REQUIRED )
enable_testing( )
add_subdirectory( "${PROJECT_SOURCE_DIR}/test/unit" )
add_subdirectory( "${PROJECT_SOURCE_DIR}/test/feature" )
add_subdirectory( "${PROJECT_SOURCE_DIR}/test/regression" )
add_subdirectory( "${PROJECT_SOURCE_DIR}/test/integration" )
endif ( )
#
# Install
#
if ( BUILD_DEVEL_PACKAGE )
file( GLOB ARTIFACTS "${SOURCE_DIR}/*.hpp" )
install( FILES "${INCLUDE_DIR}/${PROJECT_NAME}" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" )
install( FILES ${ARTIFACTS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/corvusoft/${PROJECT_NAME}" )
endif ( )
if ( BUILD_STATIC_LIBRARY )
install( TARGETS ${STATIC_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
endif ( )
if ( BUILD_SHARED_LIBRARY )
install( TARGETS ${SHARED_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
endif ( )