From 90579e94ff8c9f66f2f6a801205138e1c34bd59a Mon Sep 17 00:00:00 2001 From: Gulliver Date: Wed, 21 Feb 2024 00:25:30 +0100 Subject: [PATCH] splitted crow features into two options --- .github/workflows/build_and_test.yml | 11 +++++++---- CMakeLists.txt | 17 +++++++++-------- cmake/CrowConfig.cmake.in | 8 ++++---- docs/getting_started/setup/linux.md | 9 +++++++-- docs/getting_started/setup/macos.md | 5 ++++- docs/guides/compression.md | 2 +- docs/guides/ssl.md | 5 +++-- tests/CMakeLists.txt | 2 +- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index cd8978064..5e6fa544d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -24,8 +24,8 @@ jobs: matrix: os: [ ubuntu-latest, windows-latest, - ubuntu-20.04, macos-latest, + ubuntu-20.04, macos-11 ] # ubuntu-18.04 does not work due to compile error on asio @@ -55,7 +55,8 @@ jobs: if [ "$RUNNER_OS" == "Windows" ]; then cmake \ -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \ - -DCROW_FEATURES="ssl;compression" \ + -DCROW_ENABLE_SSL=ON \ + -DCROW_ENABLE_COMPRESSION=ON \ -DCROW_AMALGAMATE=ON \ -DCROW_BUILD_TESTS=ON \ -B build @@ -63,13 +64,15 @@ jobs: LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" \ CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" \ cmake \ - -DCROW_FEATURES="ssl;compression" \ + -DCROW_ENABLE_SSL=ON \ + -DCROW_ENABLE_COMPRESSION=ON \ -DCROW_AMALGAMATE=ON \ -DCROW_BUILD_TESTS=ON \ -B build else cmake \ - -DCROW_FEATURES="ssl;compression" \ + -DCROW_ENABLE_SSL=ON \ + -DCROW_ENABLE_COMPRESSION=ON \ -DCROW_AMALGAMATE=ON \ -DCROW_BUILD_TESTS=ON \ -B build diff --git a/CMakeLists.txt b/CMakeLists.txt index f02d9c489..2c08bde2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,8 +48,9 @@ option(CROW_AMALGAMATE "Combine all headers into one" OFF) option(CROW_INSTALL "Add install step for Crow" ON ) option(CROW_USE_BOOST "Use Boost.Asio for Crow" OFF) -# Possible values: ssl, compression -option(CROW_FEATURES "Enable features extending Crow's abilities" "") +option(CROW_ENABLE_SSL "Enable Crow's SSL feature for supporting https" OFF) +option(CROW_ENABLE_COMPRESSION "Enable Crow's Compression feature for supporting compressed http content" OFF) + ##################################### # Define Targets @@ -80,13 +81,13 @@ endif() target_compile_definitions(Crow INTERFACE "") -if("compression" IN_LIST CROW_FEATURES) +if(CROW_ENABLE_COMPRESSION) find_package(ZLIB REQUIRED) target_link_libraries(Crow INTERFACE ZLIB::ZLIB) target_compile_definitions(Crow INTERFACE CROW_ENABLE_COMPRESSION) endif() -if("ssl" IN_LIST CROW_FEATURES) +if(CROW_ENABLE_SSL) find_package(OpenSSL REQUIRED) target_link_libraries(Crow INTERFACE OpenSSL::SSL) target_compile_definitions(Crow INTERFACE CROW_ENABLE_SSL) @@ -119,11 +120,11 @@ if(CROW_BUILD_TESTS) COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unittest ) - if(NOT "compression" IN_LIST CROW_FEATURES) - message(STATUS "Compression tests are omitted. (Configure with CROW_FEATURES containing 'compression' to enable them)") + if(NOT CROW_ENABLE_COMPRESSION) + message(STATUS "Compression tests are omitted. (Configure with CROW_ENABLE_COMPRESSION to enable them)") endif() - if(NOT "ssl" IN_LIST CROW_FEATURES) - message(STATUS "SSL tests are omitted. (Configure with CROW_FEATURES containing 'ssl' to enable them)") + if(NOT CROW_ENABLE_SSL) + message(STATUS "SSL tests are omitted. (Configure with CROW_ENABLE_SSL to enable them)") else() if(NOT MSVC) add_test( diff --git a/cmake/CrowConfig.cmake.in b/cmake/CrowConfig.cmake.in index 1a0dddf71..4c553c9a6 100644 --- a/cmake/CrowConfig.cmake.in +++ b/cmake/CrowConfig.cmake.in @@ -14,11 +14,11 @@ if(NOT DEFINED CROW_FEATURES) set(CROW_FEATURES ${CROW_INSTALLED_FEATURES}) endif() -if("compression" IN_LIST CROW_FEATURES) +if(CROW_ENABLE_COMPRESSION) find_dependency(ZLIB) endif() -if("ssl" IN_LIST CROW_FEATURES) +if(CROW_ENABLE_SSL) find_dependency(OpenSSL) endif() @@ -38,12 +38,12 @@ endif() list(REMOVE_ITEM _CROW_ILL "ZLIB::ZLIB" "OpenSSL::SSL") list(REMOVE_ITEM _CROW_ICD "CROW_ENABLE_SSL" "CROW_ENABLE_COMPRESSION") -if("compression" IN_LIST CROW_FEATURES) +if(CROW_ENABLE_COMPRESSION) list(APPEND _CROW_ILL "ZLIB::ZLIB") list(APPEND _CROW_ICD "CROW_ENABLE_COMPRESSION") endif() -if("ssl" IN_LIST CROW_FEATURES) +if(CROW_ENABLE_SSL) list(APPEND _CROW_ILL "OpenSSL::SSL") list(APPEND _CROW_ICD "CROW_ENABLE_SSL") endif() diff --git a/docs/getting_started/setup/linux.md b/docs/getting_started/setup/linux.md index 40eb85ad5..fde9e231a 100644 --- a/docs/getting_started/setup/linux.md +++ b/docs/getting_started/setup/linux.md @@ -45,7 +45,9 @@ You can also download the `crow_all.h` file and simply include that into your pr !!! note - While building you can set the `CROW_FEATURES` variable (as a `;` separated list). You can use an argument such as `-DCROW_FEATURES="ssl;compression"`. + While building you can set: + the `CROW_ENABLE_SSL` variable to enable the support for https + the `CROW_ENABLE_COMPRESSION` variable to enable the support for http compression !!! note @@ -83,7 +85,10 @@ target_link_libraries(your_project PUBLIC Crow::Crow) From there CMake should handle compiling and linking your project. !!! note - For optional features like HTTP Compression or HTTPS you can set the `CROW_FEATURES` variable using lines such as `set(CROW_FEATURES "ssl;compression")`, `set(CROW_FEATURES ssl compression)`, or `set(CROW_FEATURES ssl)`. + For optional features like HTTP Compression or HTTPS you can set + + the `CROW_ENABLE_SSL` variable to enable the support for https + the `CROW_ENABLE_COMPRESSION` variable to enable the support for http compression ### Directly using a compiler All you need to do is run the following command: diff --git a/docs/getting_started/setup/macos.md b/docs/getting_started/setup/macos.md index 2d33ced3a..9a7e2e0d1 100644 --- a/docs/getting_started/setup/macos.md +++ b/docs/getting_started/setup/macos.md @@ -61,7 +61,10 @@ This will generate a `crow_all.h` file which you can use in the following steps 4. `make -j12` !!! note - You can add options like `-DCROW_FEATURES="ssl;compression"` or `-DCROW_AMALGAMATE` to `cmake ..` to build optional tests/examples for HTTP Compression or HTTPS. + You can add options like `-DCROW_ENABLE_COMPRESSION=ON` + or `-DCROW_ENABLE_SSL=ON` + or `-DCROW_AMALGAMATE` + to `cmake ..` to build optional tests/examples for HTTP Compression or HTTPS. ## Compiling using a compiler directly All you need to do is run the following command: diff --git a/docs/guides/compression.md b/docs/guides/compression.md index 47a258889..a6be358a1 100644 --- a/docs/guides/compression.md +++ b/docs/guides/compression.md @@ -5,7 +5,7 @@ Crow supports Zlib compression using Gzip or Deflate algorithms. ## HTTP Compression HTTP compression is by default disabled in crow. Do the following to enable it:
-- Define `CROW_ENABLE_COMPRESSION` in your compiler definitions (`g++ main.cpp -DCROW_ENABLE_COMPRESSION` for example) or `set(CROW_FEATURES compression)` in `CMakeLists.txt`. +- Define `CROW_ENABLE_COMPRESSION` in your compiler definitions (`g++ main.cpp -DCROW_ENABLE_COMPRESSION` for example) or `set(CROW_ENABLE_COMPRESSION ON)` in `CMakeLists.txt`. - Call `#!cpp use_compression(crow::compression::algorithm)` on your Crow app. - When compiling your application, make sure that ZLIB is included as a dependency. Either through `-lz` compiler argument or `find_package(ZLIB)` in CMake. diff --git a/docs/guides/ssl.md b/docs/guides/ssl.md index e44346bdf..ffbf7ecee 100644 --- a/docs/guides/ssl.md +++ b/docs/guides/ssl.md @@ -5,10 +5,11 @@ Crow supports HTTPS though SSL or TLS.

When mentioning SSL in this documentation, it is often a reference to openSSL, which includes TLS.

-To enable SSL, first your application needs to define either a `.crt` and `.key` files, or a `.pem` file. Once you have your files, you can add them to your app like this:
+To enable SSL, first your application needs to define either a `.crt` and `.key` files, or a `.pem` file. +Once you have your files, you can add them to your app like this:
`#!cpp app.ssl_file("/path/to/cert.crt", "/path/to/keyfile.key")` or `#!cpp app.ssl_file("/path/to/pem_file.pem")`. Please note that this method can be part of the app method chain, which means it can be followed by `.run()` or any other method.

-You also need to define `CROW_ENABLE_SSL` in your compiler definitions (`g++ main.cpp -DCROW_ENABLE_SSL` for example) or `set(CROW_FEATURES ssl)` in `CMakeLists.txt`. +You also need to define `CROW_ENABLE_SSL` in your compiler definitions (`g++ main.cpp -DCROW_ENABLE_SSL` for example) or `set(CROW_ENABLE_SSL ON)` in `CMakeLists.txt`. You can also set your own SSL context (by using `asio::ssl::context ctx`) and then applying it via the `#!cpp app.ssl(ctx)` method.

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c892a60ae..3e24c3557 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,7 +27,7 @@ add_subdirectory(template) add_subdirectory(multi_file) add_subdirectory(external_definition) if(NOT MSVC) - if ("ssl" IN_LIST CROW_FEATURES) + if (CROW_ENABLE_SSL) add_subdirectory(ssl) endif() endif()