3
3
#####################################
4
4
cmake_minimum_required (VERSION 3.15.0 FATAL_ERROR )
5
5
6
- # Define the Project Name and Description
7
- project (crow_all LANGUAGES CXX )
6
+ # Define the project name and language
7
+ project (Crow
8
+ LANGUAGES CXX
9
+ )
8
10
9
- # Define the module path
10
- set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR} /cmake/" )
11
+ # Check if Crow is the main project
12
+ set (CROW_IS_MAIN_PROJECT OFF )
13
+ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
14
+ set (CROW_IS_MAIN_PROJECT ON )
15
+ endif ()
11
16
12
- # Set required C++ Standard
17
+ # Set required C++ standard
13
18
set (CMAKE_CXX_STANDARD 11 )
14
19
set (CMAKE_CXX_STANDARD_REQUIRED TRUE )
15
20
16
- if (NOT CMAKE_BUILD_TYPE )
17
- message (STATUS "No build type selected, default to Release" )
18
- set (CMAKE_BUILD_TYPE "Release" )
21
+ # Default to build type "Release" unless tests are being built
22
+ if (NOT CMAKE_BUILD_TYPE )
23
+ if (NOT CROW_BUILD_TESTS )
24
+ message (STATUS "No build type selected, default to Release" )
25
+ set (CMAKE_BUILD_TYPE "Release" )
26
+ else ()
27
+ message (STATUS "No build type selected but tests are being built, default to Debug" )
28
+ set (CMAKE_BUILD_TYPE "Debug" )
29
+ endif ()
19
30
endif ()
20
31
21
32
#####################################
22
33
# Define Options
23
34
#####################################
24
- option (BUILD_EXAMPLES "Builds the examples in the project" ON )
25
- option (BUILD_TESTING "Builds the tests in the project" ON )
35
+ option (CROW_BUILD_EXAMPLES "Build the examples in the project" ${CROW_IS_MAIN_PROJECT} )
36
+ option (CROW_BUILD_TESTS "Build the tests in the project" ${CROW_IS_MAIN_PROJECT} )
37
+ option (CROW_AMALGAMATE "Combine all headers into one" OFF )
38
+ option (CROW_INSTALL "Add install step for Crow" ON )
26
39
27
- #####################################
28
- # Define CMake Module Imports
29
- #####################################
30
- include (${CMAKE_CURRENT_SOURCE_DIR} /cmake/dependencies.cmake )
31
- include (${CMAKE_CURRENT_SOURCE_DIR} /cmake/compiler_options.cmake )
40
+ option (CROW_ENABLE_SSL "Enable SSL capabilities (OpenSSL)" OFF )
41
+ option (CROW_ENABLE_COMPRESSION "Enable compression capabilities (ZLIB)" OFF )
32
42
33
43
#####################################
34
- # Define project-wide imports
44
+ # Define Targets
35
45
#####################################
36
- # this can be alternatively (and as recommended way) done with target_include_directories()
37
- if (BUILD_EXAMPLES OR BUILD_TESTING )
38
- set (PROJECT_INCLUDE_DIR
39
- ${CMAKE_CURRENT_SOURCE_DIR} /include
40
- )
46
+ add_library (Crow INTERFACE )
47
+ add_library (Crow::Crow ALIAS Crow )
41
48
42
- include_directories ("${PROJECT_INCLUDE_DIR} " )
43
- include_directories ("${CMAKE_CURRENT_SOURCE_DIR} " )
44
- include_directories ("${CMAKE_CURRENT_BINARY_DIR} " ) # To include crow_all.h
45
- endif ()
49
+ target_include_directories (Crow
50
+ INTERFACE
51
+ $< BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include>
52
+ $< INSTALL_INTERFACE:include>
53
+ )
46
54
47
- #####################################
48
- # Define Targets
49
- #####################################
50
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /crow_all.h
51
- COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR} /scripts/merge_all.py
52
- ${CMAKE_CURRENT_SOURCE_DIR} /include
53
- ${CMAKE_CURRENT_BINARY_DIR} /crow_all.h
54
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
55
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR} /include/*.h ${CMAKE_CURRENT_SOURCE_DIR} /include/crow/*.h ${CMAKE_CURRENT_SOURCE_DIR} /include/crow/middlewares/*.h
55
+ find_package (Boost 1.64 COMPONENTS system date_time REQUIRED )
56
+ find_package (Threads REQUIRED )
57
+
58
+ target_link_libraries (Crow
59
+ INTERFACE
60
+ Boost::boost Boost::system Boost::date_time
61
+ Threads::Threads
56
62
)
57
63
58
- # Amalgamation
59
- add_custom_target (amalgamation ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /crow_all.h )
64
+ if (CROW_ENABLE_COMPRESSION )
65
+ find_package (ZLIB REQUIRED )
66
+ target_link_libraries (Crow INTERFACE ZLIB::ZLIB )
67
+ target_compile_definitions (Crow INTERFACE CROW_ENABLE_COMPRESSION )
68
+ endif ()
69
+
70
+ if (CROW_ENABLE_SSL )
71
+ find_package (OpenSSL REQUIRED )
72
+ target_link_libraries (Crow INTERFACE OpenSSL::SSL )
73
+ target_compile_definitions (Crow INTERFACE CROW_ENABLE_SSL )
74
+ endif ()
75
+
76
+ if (CROW_AMALGAMATE )
77
+ add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /crow_all.h
78
+ COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR} /scripts/merge_all.py
79
+ ${CMAKE_CURRENT_SOURCE_DIR} /include
80
+ ${CMAKE_CURRENT_BINARY_DIR} /crow_all.h
81
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
82
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR} /include/*.h ${CMAKE_CURRENT_SOURCE_DIR} /include/crow/*.h ${CMAKE_CURRENT_SOURCE_DIR} /include/crow/middlewares/*.h
83
+ )
84
+
85
+ add_custom_target (crow_amalgamated ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /crow_all.h )
86
+ endif ()
60
87
61
88
# Examples
62
- if (BUILD_EXAMPLES )
89
+ if (CROW_BUILD_EXAMPLES )
63
90
add_subdirectory (examples )
64
91
endif ()
65
92
66
93
# Tests
67
- if (NOT MSVC AND BUILD_TESTING )
94
+ if (NOT MSVC AND CROW_BUILD_TESTS )
95
+ if (NOT CROW_ENABLE_COMPRESSION )
96
+ message (STATUS "Compression tests are omitted. (Configure with CROW_ENABLE_COMPRESSION=ON to enable them)" )
97
+ endif ()
98
+ if (NOT CROW_ENABLE_SSL )
99
+ message (STATUS "SSL tests are omitted. (Configure with CROW_ENABLE_SSL=ON to enable them)" )
100
+ else ()
101
+ add_test (NAME ssl_test COMMAND ${CMAKE_CURRENT_BINARY_DIR} /tests/ssl/ssltest )
102
+ endif ()
103
+
68
104
add_subdirectory (tests )
69
105
enable_testing ()
70
106
add_test (NAME crow_test COMMAND ${CMAKE_CURRENT_BINARY_DIR} /tests/unittest )
@@ -74,10 +110,35 @@ endif()
74
110
#####################################
75
111
# Install Files
76
112
#####################################
77
- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /crow_all.h DESTINATION include )
113
+ if (CROW_INSTALL )
114
+ install (TARGETS Crow EXPORT CrowTargets )
115
+ install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /include/ DESTINATION include )
116
+
117
+ install (EXPORT CrowTargets
118
+ FILE CrowTargets.cmake
119
+ NAMESPACE Crow::
120
+ DESTINATION lib/cmake/Crow
121
+ )
122
+
123
+ include (CMakePackageConfigHelpers )
124
+ configure_package_config_file (
125
+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake/CrowConfig.cmake.in"
126
+ "${CMAKE_CURRENT_BINARY_DIR} /CrowConfig.cmake"
127
+ INSTALL_DESTINATION lib/cmake/Crow
128
+ )
129
+ install (FILES
130
+ "${CMAKE_CURRENT_BINARY_DIR} /CrowConfig.cmake"
131
+ DESTINATION lib/cmake/Crow
132
+ )
133
+ endif ()
78
134
79
135
set (CPACK_GENERATOR "DEB" )
136
+ set (CPACK_PACKAGE_NAME "Crow" )
80
137
set (CPACK_DEBIAN_PACKAGE_MAINTAINER "CrowCpp" )
138
+ set (CPACK_PACKAGE_VENDOR "CrowCpp" )
139
+ set (CPACK_PACKAGE_DESCRIPTION "A Fast and Easy to use C++ microframework for the web." )
140
+ set (CPACK_PACKAGE_HOMEPAGE_URL "https://crowcpp.org" )
141
+ set (CPACK_DEBIAN_PACKAGE_DEBUG OFF )
81
142
set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON )
82
143
83
144
include (CPack )
0 commit comments