-
Notifications
You must be signed in to change notification settings - Fork 32
/
CMakeLists.txt
134 lines (96 loc) · 5.25 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
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
###################################################################################################
## These variables are passed to oatpp-module-install.cmake script
## use these variables to configure module installation
set(OATPP_THIS_MODULE_NAME oatpp-websocket) ## name of the module (also name of folders in installation dirs)
set(OATPP_THIS_MODULE_VERSION "1.4.0") ## version of the module (also sufix of folders in installation dirs)
set(OATPP_THIS_MODULE_LIBRARIES oatpp-websocket) ## list of libraries to find when find_package is called
set(OATPP_THIS_MODULE_TARGETS oatpp-websocket) ## list of targets to install
set(OATPP_THIS_MODULE_DIRECTORIES oatpp-websocket) ## list of directories to install
###################################################################################################
project(${OATPP_THIS_MODULE_NAME}
VERSION ${OATPP_THIS_MODULE_VERSION}
LANGUAGES CXX
## HOMEPAGE_URL "https://github.com/oatpp/oatpp-websocket"
## DESCRIPTION "Something about websocket"
)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(OATPP_DIR_SRC "Path to oatpp module directory (sources)")
option(OATPP_DIR_LIB "Path to directory with liboatpp (directory containing ex: liboatpp.so or liboatpp.dynlib)")
option(OATPP_BUILD_TESTS "Build tests for this module" ON)
option(OATPP_LINK_TEST_LIBRARY "Link oat++ test library" ON)
option(OATPP_INSTALL "Install module binaries" ON)
option(OATPP_MSVC_LINK_STATIC_RUNTIME "MSVC: Link with static runtime (/MT and /MTd)." OFF)
set(OATPP_MODULES_LOCATION "INSTALLED" CACHE STRING "Location where to find oatpp modules. can be [INSTALLED|EXTERNAL|CUSTOM]")
set(OATPP_EXTERNAL_SOURCE "GIT" CACHE STRING "Source of downloading external oatpp modules. can be [GIT|URL]")
###################################################################################################
## get oatpp main module in specified location
set(OATPP_MODULES_LOCATION_INSTALLED INSTALLED)
set(OATPP_MODULES_LOCATION_EXTERNAL EXTERNAL)
set(OATPP_MODULES_LOCATION_CUSTOM CUSTOM)
set(OATPP_EXTERNAL_SOURCE_GIT GIT)
set(OATPP_EXTERNAL_SOURCE_URL URL)
if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_INSTALLED)
message("Finding oatpp in location=INSTALLED")
find_package(oatpp ${OATPP_THIS_MODULE_VERSION} REQUIRED)
get_target_property(OATPP_INCLUDE oatpp::oatpp INTERFACE_INCLUDE_DIRECTORIES)
message("OATPP_INCLUDE=${OATPP_INCLUDE}")
if(OATPP_BUILD_TESTS)
get_target_property(OATPP_TEST_INCLUDE oatpp::oatpp-test INTERFACE_INCLUDE_DIRECTORIES)
message("OATPP_TEST_INCLUDE=${OATPP_TEST_INCLUDE}")
endif()
elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL)
message("Finding oatpp in location=EXTERNAL")
include(ExternalProject)
set(MODULE_WAIT_DEPS ON)
set(LIB_OATPP_EXTERNAL "lib_oatpp_external")
if(OATPP_EXTERNAL_SOURCE STREQUAL OATPP_EXTERNAL_SOURCE_GIT)
ExternalProject_Add(${LIB_OATPP_EXTERNAL}
GIT_REPOSITORY "https://github.com/oatpp/oatpp.git"
GIT_TAG origin/master
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DOATPP_INSTALL=OFF -DOATPP_BUILD_TESTS=OFF
INSTALL_COMMAND cmake -E echo "SKIP INSTALL '${LIB_OATPP_EXTERNAL}'"
)
elseif(OATPP_EXTERNAL_SOURCE STREQUAL OATPP_EXTERNAL_SOURCE_URL)
ExternalProject_Add(${LIB_OATPP_EXTERNAL}
URL "https://github.com/oatpp/oatpp/archive/refs/heads/master.zip"
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DOATPP_INSTALL=OFF -DOATPP_BUILD_TESTS=OFF
INSTALL_COMMAND cmake -E echo "SKIP INSTALL '${LIB_OATPP_EXTERNAL}'"
)
endif()
ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} BINARY_DIR)
set(OATPP_DIR_LIB ${BINARY_DIR}/src)
ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} SOURCE_DIR)
set(OATPP_DIR_SRC ${SOURCE_DIR}/src)
include_directories(${OATPP_DIR_SRC})
message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'")
message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'")
elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_CUSTOM)
message("Finding oatpp in location=CUSTOM")
message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'")
message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'")
else()
message("FATAL_ERROR Unknown location to find oatpp '${OATPP_MODULES_LOCATION}'")
endif()
if(OATPP_DIR_LIB)
link_directories(${OATPP_DIR_LIB})
endif()
###################################################################################################
## get dependencies
message("\n############################################################################")
message("## ${OATPP_THIS_MODULE_NAME} module. Resolving dependencies...\n")
## TODO find dependecies here (if some)
message("\n############################################################################\n")
###################################################################################################
## define targets
if(UNIX AND NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif()
include(cmake/module-utils.cmake)
include(cmake/msvc-runtime.cmake)
configure_msvc_runtime()
add_subdirectory(src)
if(OATPP_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()