|
1 | 1 | #-------------------------------------------------------------------------------
|
2 |
| -# Copyright Butterfly Energy Systems 2014-2015. |
| 2 | +# Copyright Butterfly Energy Systems 2014-2015, 2018, 2022. |
3 | 3 | # Distributed under the Boost Software License, Version 1.0.
|
4 | 4 | # (See accompanying file LICENSE_1_0.txt or copy at
|
5 | 5 | # http://www.boost.org/LICENSE_1_0.txt)
|
6 | 6 | #-------------------------------------------------------------------------------
|
7 | 7 |
|
8 |
| -cmake_minimum_required (VERSION 2.8) |
9 |
| -project (cppwamp) |
10 |
| - |
11 |
| -# First attempt to find Boost library directories |
12 |
| -set(BOOST_MIN_VERSION 1.58.0) |
13 |
| -set(BOOST_COMPONENTS coroutine context thread system) |
14 |
| -set(BOOST_ROOT ./ext/boost) |
15 |
| -find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${BOOST_COMPONENTS}) |
16 |
| -if(Boost_FOUND) |
17 |
| - set(SUGGESTED_BOOST_INCLUDE_PATH ${Boost_INCLUDE_DIRS}) |
18 |
| - set(SUGGESTED_BOOST_LIBRARY_PATH ${Boost_LIBRARY_DIRS}) |
19 |
| -else() |
20 |
| - set(SUGGESTED_BOOST_INCLUDE_PATH ./ext/boost) |
21 |
| - set(SUGGESTED_BOOST_LIBRARY_PATH ./ext/boost/stage/lib) |
| 8 | +#------------------------------------------------------------------------------- |
| 9 | +# This project defines one of more of the following targets, depending |
| 10 | +# on the how the CPPWAMP_OPT_X options are set: |
| 11 | +# |
| 12 | +# Target | Import alias | All | Description |
| 13 | +# ----------------------- | ------------------------ | --- | ----------- |
| 14 | +# cppwamp-core | CppWAMP::core | Yes | Compiled libcppwamp-core library |
| 15 | +# cppwamp-core-headers | CppWAMP::core-headers | Yes | Header-only usage requirements |
| 16 | +# cppwamp-coro-headers | CppWAMP::coro-headers | Yes | Boost.Coroutine usage requirements |
| 17 | +# cppwamp-json | CppWAMP::json | Yes | Compiled libcppwamp-json library for JSON codec support |
| 18 | +# cppwmap-json-headers | CppWAMP::json-headers | Yes | Header-only RapidJSON usage requirements |
| 19 | +# cppwamp-msgpack | CppWAMP::msgpack | Yes | Compiled libcppwamp-msgpack library for Msgpack codec support |
| 20 | +# cppwamp-msgpack-headers | CppWAMP::msgpack-headers | Yes | Header-only Msgpack usage requirements |
| 21 | +# cppwamp-doc | <none> | No | Doxygen documentation |
| 22 | +# cppwamp-examples | <none> | No | Compiled example programs |
| 23 | +# cppwamp-test | <none> | No | Compiled test suite program |
| 24 | +# |
| 25 | +# 'All' means that the target (if enabled) is built as part of the 'all' target. |
| 26 | +# 'Usage requirements' means that the appropriate compiler flags will be set |
| 27 | +# if you add the target to target_link_libraries in your CMake project. |
| 28 | +# |
| 29 | +# This project supports inclusion into another CMake project via either |
| 30 | +# add_subdirectory(cppwamp) or find_package(CppWAMP ...). |
| 31 | +#------------------------------------------------------------------------------- |
| 32 | + |
| 33 | + |
| 34 | +# Version 3.11 needed for FetchContent |
| 35 | +# Version 3.12 needed for find_path's <PackageName>_ROOT support |
| 36 | +# Version 3.12 needed for install(TARGETS ... NAMELINK_COMPONENT ...) |
| 37 | +# Version 3.12 needed for $<TARGET_EXISTS:target> generator expression |
| 38 | +cmake_minimum_required (VERSION 3.12) |
| 39 | + |
| 40 | +# Include guard in case this project becomes a diamond dependency via multiple |
| 41 | +# add_directory(cppwamp) calls. |
| 42 | +include_guard() |
| 43 | + |
| 44 | +project(CppWAMP |
| 45 | + VERSION 0.7.0 |
| 46 | + LANGUAGES CXX) |
| 47 | + |
| 48 | +include(ProcessorCount) |
| 49 | +ProcessorCount(CPPWAMP_CORE_COUNT) |
| 50 | +if(CPPWAMP_CORE_COUNT EQUAL 0) |
| 51 | + set(CPPWAMP_CORE_COUNT 1) |
22 | 52 | endif()
|
23 | 53 |
|
24 |
| -# Add GUI variables that let the user specify where the Boost directories |
25 |
| -# are, using the above initial search for default locations. |
26 |
| -set(PATH_INCLUDE_BOOST ${SUGGESTED_BOOST_INCLUDE_PATH} CACHE PATH |
27 |
| - "Boost include path") |
28 |
| -set(PATH_LIB_BOOST ${SUGGESTED_BOOST_LIBRARY_PATH} CACHE PATH |
29 |
| - "Boost library path") |
30 |
| - |
31 |
| -# Add GUI variables that let the user specify the include path for other |
32 |
| -# third-party libraries. |
33 |
| -set(PATH_INCLUDE_RAPIDJSON ${PROJECT_SOURCE_DIR}/ext/rapidjson/include CACHE PATH |
34 |
| - "RapidJson include path") |
35 |
| -set(PATH_INCLUDE_MSGPACK ${PROJECT_SOURCE_DIR}/ext/msgpack-c/include CACHE PATH |
36 |
| - "Msgpack-c include path") |
37 |
| -set(PATH_INCLUDE_CATCH ${PROJECT_SOURCE_DIR}/ext/Catch/include CACHE PATH |
38 |
| - "Catch include path") |
39 |
| - |
40 |
| -# Confirm that the user's choices for the Boost library paths are valid. |
41 |
| -unset(BOOST_ROOT) |
42 |
| -set(BOOST_INCLUDEDIR ${PATH_INCLUDE_BOOST}) |
43 |
| -set(BOOST_LIBRARYDIR ${PATH_LIB_BOOST}) |
44 |
| -set(Boost_NO_SYSTEM_PATHS ON) |
45 |
| -find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${BOOST_COMPONENTS}) |
46 |
| - |
47 |
| -# Set a default build type if none was specified. |
48 |
| -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 54 | +get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 55 | + |
| 56 | +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" |
| 57 | + isTopLevel) |
| 58 | + |
| 59 | +#----------------------------- User options ------------------------------------ |
| 60 | + |
| 61 | +if(NOT isMultiConfig AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
49 | 62 | message(STATUS "Setting build type to 'Release' as none was specified.")
|
50 |
| - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) |
51 |
| - # Set the possible values of build type for cmake-gui |
| 63 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "The type of build" FORCE) |
52 | 64 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
|
53 | 65 | "MinSizeRel" "RelWithDebInfo")
|
54 | 66 | endif()
|
55 | 67 |
|
56 |
| -# Add the include paths to third-party libraries |
57 |
| -include_directories( |
58 |
| - ${PATH_INCLUDE_BOOST} |
59 |
| - ${PATH_INCLUDE_RAPIDJSON} |
60 |
| - ${PATH_INCLUDE_MSGPACK} |
61 |
| -) |
| 68 | +option(BUILD_SHARED_LIBS |
| 69 | +"Determines whether a shared or static library will be built. If already set \ |
| 70 | +by a superproject, the CPPWAMP_OPT_SHARED_LIBS non-cache variable may be set \ |
| 71 | +to override the shared/static setting specifically for CppWAMP." |
| 72 | +OFF) |
62 | 73 |
|
63 |
| -# Add the compiler flag for C++11 |
64 |
| -if(UNIX) |
65 |
| - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
66 |
| -endif() |
| 74 | +option(CPPWAMP_OPT_HEADERS_ONLY |
| 75 | +"Don't build libraries/tests/examples and only create targets for \ |
| 76 | +header-only use." |
| 77 | +OFF) |
| 78 | + |
| 79 | +option(CPPWAMP_OPT_VENDORIZE |
| 80 | +"Fetches and builds dependencies during configuration. If disabled, the \ |
| 81 | +dependencies will be searched via find_package. The searching can be \ |
| 82 | +directed by defining <dependency>_ROOT variables. If the dependent targets are \ |
| 83 | +already imported by a superproject, find_package calls will be skipped." |
| 84 | +OFF) |
| 85 | + |
| 86 | +option(CPPWAMP_OPT_WITH_JSON |
| 87 | +"Adds the RapidJSON dependency and builds the cppwamp-json library" |
| 88 | +ON) |
| 89 | + |
| 90 | +option(CPPWAMP_OPT_WITH_MSGPACK |
| 91 | +"Adds the msgpack-c dependency and builds the cppwamp-msgpack library" |
| 92 | +ON) |
| 93 | + |
| 94 | +option(CPPWAMP_OPT_WITH_CORO |
| 95 | +"Adds the Boost.Coroutine dependency and build tests and examples \ |
| 96 | +that depend on it" |
| 97 | +ON) |
| 98 | + |
| 99 | +option(CPPWAMP_OPT_WITH_DOCS |
| 100 | +"Creates a build target for generating documentation" |
| 101 | +${isTopLevel}) |
| 102 | + |
| 103 | +option(CPPWAMP_OPT_WITH_TESTS |
| 104 | +"Adds the Catch2 dependency and creates a build target for unit tests" |
| 105 | +${isTopLevel}) |
| 106 | + |
| 107 | +option(CPPWAMP_OPT_WITH_EXAMPLES |
| 108 | +"Creates a build target for examples" |
| 109 | +${isTopLevel}) |
| 110 | + |
| 111 | +option(CPPWAMP_OPT_WITH_PACKAGING |
| 112 | +"Generates libary packaging rules" |
| 113 | +${isTopLevel}) |
| 114 | + |
| 115 | +#--------------------------- Advanced options ---------------------------------- |
67 | 116 |
|
68 |
| -# Add the -pthread compiler flag, if applicable. |
69 |
| -# Note that ${Boost_LIBRARIES} already includes a linker flag for -lpthread. |
70 |
| -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
71 |
| -find_package(Threads REQUIRED) |
72 |
| -if(CMAKE_USE_PTHREADS_INIT) |
73 |
| - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") |
| 117 | +set(CPPWAMP_OPT_BOOST_CONFIG "" CACHE FILEPATH |
| 118 | + "The user-config file to use when building Boost (optional)") |
| 119 | +mark_as_advanced(CPPWAMP_OPT_BOOST_CONFIG) |
| 120 | + |
| 121 | +set(CPPWAMP_OPT_BOOST_JOBS ${CPPWAMP_CORE_COUNT} CACHE STRING |
| 122 | + "Number of threads (-j option) to use when building Boost") |
| 123 | +mark_as_advanced(CPPWAMP_OPT_BOOST_JOBS) |
| 124 | + |
| 125 | +#------------------------ End of user options ---------------------------------- |
| 126 | + |
| 127 | +set(CPPWAMP_PREVIOUSLY_VENDORIZED OFF CACHE INTERNAL "") |
| 128 | + |
| 129 | +if(DEFINED CPPWAMP_OPT_SHARED_LIBS) |
| 130 | + set(BUILD_SHARED_LIBS "${CPPWAMP_OPT_SHARED_LIBS}") |
74 | 131 | endif()
|
75 | 132 |
|
76 |
| -# Add the appropriate preprocessor macro define if the user specified |
77 |
| -# non-handshaking transports. |
78 |
| -if(CPPWAMP_USE_NON_HANDSHAKING_TRANSPORTS) |
79 |
| - add_definitions(-DCPPWAMP_USE_LEGACY_CONNECTORS) |
| 133 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 134 | + |
| 135 | +# Set default export visibility to hidden for all targets |
| 136 | +if(NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND |
| 137 | + NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN) |
| 138 | + set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
| 139 | + set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) |
80 | 140 | endif()
|
81 | 141 |
|
82 |
| -# Disable Boost.Coroutine deprecation warning |
83 |
| -add_definitions(-DBOOST_COROUTINE_NO_DEPRECATION_WARNING) |
84 |
| -add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING) |
| 142 | +# Fetch or find dependencies |
| 143 | +include(CppWAMPDependencies) |
| 144 | +cppwamp_resolve_dependencies() |
85 | 145 |
|
86 |
| -# Add targets for the cppwamp library itself, units tests, and examples. |
87 | 146 | add_subdirectory(cppwamp)
|
88 |
| -add_subdirectory(test) |
89 |
| -add_subdirectory(examples) |
| 147 | + |
| 148 | +if(CPPWAMP_OPT_WITH_JSON) |
| 149 | + add_subdirectory(cppwamp-json) |
| 150 | +endif() |
| 151 | + |
| 152 | +if(CPPWAMP_OPT_WITH_MSGPACK) |
| 153 | + add_subdirectory(cppwamp-msgpack) |
| 154 | +endif() |
| 155 | + |
| 156 | +if(CPPWAMP_OPT_WITH_CORO) |
| 157 | + add_subdirectory(cppwamp-coro) |
| 158 | +endif() |
| 159 | + |
| 160 | +if(CPPWAMP_OPT_WITH_DOCS AND NOT CPPWAMP_OPT_HEADERS_ONLY) |
| 161 | + add_subdirectory(doc) |
| 162 | +endif() |
| 163 | + |
| 164 | +if(CPPWAMP_OPT_WITH_TESTS AND NOT CPPWAMP_OPT_HEADERS_ONLY) |
| 165 | + add_subdirectory(test) |
| 166 | +endif() |
| 167 | + |
| 168 | +if(CPPWAMP_OPT_WITH_EXAMPLES AND NOT CPPWAMP_OPT_HEADERS_ONLY) |
| 169 | + add_subdirectory(examples) |
| 170 | +endif() |
| 171 | + |
| 172 | +if(CPPWAMP_OPT_WITH_PACKAGING) |
| 173 | + add_subdirectory(packaging) |
| 174 | +endif() |
0 commit comments