### Building Examples and Installing Headers in CMake Source: https://github.com/eidheim/simple-web-server/blob/master/CMakeLists.txt This block executes only if the project is built as a top-level project (not a sub-project). It adds `http_examples` and `https_examples` executables, links them with the main library and Boost, and installs the public header files to the `include/simple-web-server` destination. ```CMake # If Simple-Web-Server is not a sub-project: if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") add_executable(http_examples http_examples.cpp) target_link_libraries(http_examples simple-web-server) find_package(Boost 1.53.0 COMPONENTS system thread filesystem REQUIRED) target_link_libraries(http_examples ${Boost_LIBRARIES}) target_include_directories(http_examples PRIVATE ${Boost_INCLUDE_DIR}) if(OPENSSL_FOUND) add_executable(https_examples https_examples.cpp) target_link_libraries(https_examples simple-web-server) target_link_libraries(https_examples ${Boost_LIBRARIES}) target_include_directories(https_examples PRIVATE ${Boost_INCLUDE_DIR}) endif() set(BUILD_TESTING ON) install(FILES server_http.hpp client_http.hpp server_https.hpp client_https.hpp crypto.hpp utility.hpp status_code.hpp DESTINATION include/simple-web-server) endif() ``` -------------------------------- ### CMake Project Initialization and Compiler Flags Source: https://github.com/eidheim/simple-web-server/blob/master/CMakeLists.txt Sets the minimum CMake version, defines the project name, and configures build options like using standalone Asio or building tests. It also applies C++11 standard and warning flags for GCC/Clang and a basic warning level for MSVC. ```CMake cmake_minimum_required (VERSION 3.0) project (Simple-Web-Server) option(USE_STANDALONE_ASIO "set ON to use standalone Asio instead of Boost.Asio" OFF) option(BUILD_TESTING "set ON to build library tests" OFF) if(NOT MSVC) add_compile_options(-std=c++11 -Wall -Wextra -Wsign-conversion) else() add_compile_options(/W1) endif() add_library(simple-web-server INTERFACE) target_include_directories(simple-web-server INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### Compile Simple-Web-Server Project Source: https://github.com/eidheim/simple-web-server/blob/master/README.md Instructions to compile the Simple-Web-Server project using CMake and Make, requiring a C++11 compliant compiler. This process creates a 'build' directory, configures the project, and compiles it. ```sh mkdir build cd build cmake .. make cd .. ``` -------------------------------- ### Configuring Asio or Boost.Asio Dependency in CMake Source: https://github.com/eidheim/simple-web-server/blob/master/CMakeLists.txt Manages the dependency on either standalone Asio or Boost.Asio. If `USE_STANDALONE_ASIO` is ON, it checks for `asio.hpp`; otherwise, it finds and links Boost components (system, thread). It also includes a special case for older GCC versions to link Boost.Regex. ```CMake # TODO 2020 when Debian Jessie LTS ends: # Remove Boost system, thread, regex components; use Boost:: aliases; remove Boost target_include_directories if(USE_STANDALONE_ASIO) target_compile_definitions(simple-web-server INTERFACE USE_STANDALONE_ASIO) include(CheckIncludeFileCXX) CHECK_INCLUDE_FILE_CXX(asio.hpp HAVE_ASIO) if(NOT HAVE_ASIO) message(FATAL_ERROR "Standalone Asio not found") endif() else() find_package(Boost 1.53.0 COMPONENTS system thread REQUIRED) target_link_libraries(simple-web-server INTERFACE ${Boost_LIBRARIES}) target_include_directories(simple-web-server INTERFACE ${Boost_INCLUDE_DIR}) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) target_compile_definitions(simple-web-server INTERFACE USE_BOOST_REGEX) find_package(Boost 1.53.0 COMPONENTS regex REQUIRED) target_link_libraries(simple-web-server INTERFACE ${Boost_LIBRARIES}) target_include_directories(simple-web-server INTERFACE ${Boost_INCLUDE_DIR}) endif() endif() ``` -------------------------------- ### Configure IO and Parse Tests (Non-MSVC) Source: https://github.com/eidheim/simple-web-server/blob/master/tests/CMakeLists.txt Configures and adds tests for I/O and parsing functionalities, specifically for non-Microsoft Visual C++ compilers. These tests are linked against the 'simple-web-server' library and include a compile option to disable access control. ```CMake if(NOT MSVC) add_compile_options(-fno-access-control) add_executable(io_test io_test.cpp) target_link_libraries(io_test simple-web-server) add_test(io_test io_test) add_executable(parse_test parse_test.cpp) target_link_libraries(parse_test simple-web-server) add_test(parse_test parse_test) endif() ``` -------------------------------- ### Configure Status Code Test Source: https://github.com/eidheim/simple-web-server/blob/master/tests/CMakeLists.txt Configures and adds a test for HTTP status code handling, which is always built regardless of compiler or library availability. This test is linked against the 'simple-web-server' library. ```CMake add_executable(status_code_test status_code_test.cpp) target_link_libraries(status_code_test simple-web-server) add_test(status_code_test status_code_test) ``` -------------------------------- ### Enabling and Adding Tests in CMake Source: https://github.com/eidheim/simple-web-server/blob/master/CMakeLists.txt Conditionally enables testing for the project if the `BUILD_TESTING` option is set. It then includes the `tests` subdirectory, allowing CMake to discover and configure the project's test suite. ```CMake if(BUILD_TESTING) enable_testing() add_subdirectory(tests) endif() ``` -------------------------------- ### Configuring OpenSSL Dependency in CMake Source: https://github.com/eidheim/simple-web-server/blob/master/CMakeLists.txt Manages the OpenSSL dependency for the project. It sets a hint for OpenSSL's root directory on macOS and then attempts to find and link OpenSSL libraries if found, enabling SSL/TLS functionalities. ```CMake if(APPLE) set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl") endif() find_package(OpenSSL) if(OPENSSL_FOUND) target_compile_definitions(simple-web-server INTERFACE HAVE_OPENSSL) target_link_libraries(simple-web-server INTERFACE ${OPENSSL_LIBRARIES}) target_include_directories(simple-web-server INTERFACE ${OPENSSL_INCLUDE_DIR}) endif() ``` -------------------------------- ### Linking Windows Socket Libraries in CMake Source: https://github.com/eidheim/simple-web-server/blob/master/CMakeLists.txt Conditionally links the `ws2_32` and `wsock32` libraries, which are required for socket programming on Windows platforms. This ensures proper network functionality when building on Windows. ```CMake if(WIN32) target_link_libraries(simple-web-server INTERFACE ws2_32 wsock32) endif() ``` -------------------------------- ### Linking Thread Library in CMake Source: https://github.com/eidheim/simple-web-server/blob/master/CMakeLists.txt Finds and links the required thread library to the `simple-web-server` interface library. This ensures that threading functionalities are available for the project. ```CMake find_package(Threads REQUIRED) target_link_libraries(simple-web-server INTERFACE ${CMAKE_THREAD_LIBS_INIT}) ``` -------------------------------- ### Configure Crypto Test (OpenSSL Found) Source: https://github.com/eidheim/simple-web-server/blob/master/tests/CMakeLists.txt Configures and adds a test for cryptographic functionalities, only if OpenSSL is detected on the system. This test is linked against the 'simple-web-server' library. ```CMake if(OPENSSL_FOUND) add_executable(crypto_test crypto_test.cpp) target_link_libraries(crypto_test simple-web-server) add_test(crypto_test crypto_test) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.