Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework cmake configs #209

Merged
merged 7 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ steps:
- export TRAVIS_BRANCH=$DRONE_BRANCH
- export TRAVIS_JOB_ID=$DRONE_BUILD_NUMBER
- apt-get -y update
- apt-get -y install libboost-all-dev doxygen mkdocs graphviz zlib1g-dev gcc clang make cmake python3 python3-pip git
- apt-get -y install libboost-all-dev doxygen mkdocs graphviz zlib1g-dev libssl-dev gcc clang make cmake python3 python3-pip git
- pip3 install mkdocs-material cpp-coveralls pyyaml
- export CC=/usr/bin/gcc
- export CXX=/usr/bin/g++
- mkdir build
- cd build
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4
- cd ..
Expand All @@ -33,7 +33,7 @@ steps:
- export CXX=/usr/bin/clang++
- mkdir build-clang
- cd build-clang
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4

Expand All @@ -58,19 +58,19 @@ steps:
commands:
- export DEBIAN_FRONTEND=noninteractive
- apt-get -y update
- apt-get -y install libboost-all-dev zlib1g-dev gcc clang make cmake python3
- apt-get -y install libboost-all-dev zlib1g-dev libssl-dev gcc clang make cmake python3
- mkdir build
- cd build
- cmake --version
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4
- cd ..
- export CC=/usr/bin/clang
- export CXX=/usr/bin/clang++
- mkdir build-clang
- cd build-clang
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4

Expand Down Expand Up @@ -108,13 +108,13 @@ steps:
- export TRAVIS_BRANCH=$DRONE_REPO_BRANCH
- export TRAVIS_JOB_ID=$DRONE_BUILD_NUMBER
- apt-get -y update
- apt-get -y install libboost-all-dev doxygen mkdocs graphviz zlib1g-dev gcc clang make cmake python3 python3-pip git
- apt-get -y install libboost-all-dev doxygen mkdocs graphviz zlib1g-dev libssl-dev gcc clang make cmake python3 python3-pip git
- pip3 install mkdocs-material cpp-coveralls pyyaml
- export CC=/usr/bin/gcc
- export CXX=/usr/bin/g++
- mkdir build
- cd build
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4
- cd ..
Expand All @@ -123,7 +123,7 @@ steps:
- export CXX=/usr/bin/clang++
- mkdir build-clang
- cd build-clang
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4
- cd ..
Expand Down Expand Up @@ -151,19 +151,19 @@ steps:
commands:
- export DEBIAN_FRONTEND=noninteractive
- apt-get -y update
- apt-get -y install libboost-all-dev zlib1g-dev gcc clang make cmake python3
- apt-get -y install libboost-all-dev zlib1g-dev libssl-dev gcc clang make cmake python3
- mkdir build
- cd build
- cmake --version
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4
- cd ..
- export CC=/usr/bin/clang
- export CXX=/usr/bin/clang++
- mkdir build-clang
- cd build-clang
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON
- make -j4
- ctest -V -j4

Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ addons:
- mkdocs
- graphviz
- zlib1g-dev
- libssl-dev

before_install:
- if [ "$TRAVIS_COMPILER" == "gcc" -a "$TRAVIS_CPU_ARCH" == "amd64" ]; then export PUSH_COVERAGE=ON; fi
Expand All @@ -45,7 +46,7 @@ before_script:
- mkdir build
- cd build
- cmake --version
- cmake ..
- cmake .. -DCROW_ENABLE_COMPRESSION=ON -DCROW_ENABLE_SSL=ON

script: make -j4 && ctest -V -j4

Expand Down
119 changes: 81 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,91 @@
#####################################
cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)

# Define the Project Name and Description
project (crow_all LANGUAGES CXX)

# Define the module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
# Define the project name and language
project(Crow
LANGUAGES CXX
)

# Set required C++ Standard
# Set required C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

if (NOT CMAKE_BUILD_TYPE)
# Default to build type "Release"
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()

#####################################
# Define Options
#####################################
option(BUILD_EXAMPLES "Builds the examples in the project" ON)
option(BUILD_TESTING "Builds the tests in the project" ON)
option(CROW_BUILD_EXAMPLES "Build the examples in the project" ON )
option(CROW_BUILD_TESTS "Build the tests in the project" ON )
option(CROW_AMALGAMATE "Combine all headers into one" OFF)
option(CROW_INSTALL "Add install step for Crow" ON )

#####################################
# Define CMake Module Imports
#####################################
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler_options.cmake)
option(CROW_ENABLE_SSL "Enable SSL capabilities (OpenSSL)" OFF)
option(CROW_ENABLE_COMPRESSION "Enable compression capabilities (ZLIB)" OFF)

#####################################
# Define project-wide imports
# Define Targets
#####################################
# this can be alternatively (and as recommended way) done with target_include_directories()
if(BUILD_EXAMPLES OR BUILD_TESTING)
set(PROJECT_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/include
)
luca-schlecker marked this conversation as resolved.
Show resolved Hide resolved
add_library(Crow INTERFACE)
add_library(Crow::Crow ALIAS Crow)

include_directories("${PROJECT_INCLUDE_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_BINARY_DIR}") # To include crow_all.h
endif()
target_include_directories(Crow
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

#####################################
# Define Targets
#####################################
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/merge_all.py
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/crow_all.h
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include/crow/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include/crow/middlewares/*.h
find_package(Boost 1.64 COMPONENTS system date_time REQUIRED)
find_package(Threads REQUIRED)

target_link_libraries(Crow
INTERFACE
Boost::boost Boost::system Boost::date_time
Threads::Threads
)

# Amalgamation
add_custom_target(amalgamation ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h)
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(CROW_ENABLE_SSL)
find_package(OpenSSL REQUIRED)
target_link_libraries(Crow INTERFACE OpenSSL::SSL)
target_compile_definitions(Crow INTERFACE CROW_ENABLE_SSL)
endif()

if(CROW_AMALGAMATE)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/merge_all.py
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/crow_all.h
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include/crow/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include/crow/middlewares/*.h
)

add_custom_target(crow_amalgamated ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h)
endif()

# Examples
if(BUILD_EXAMPLES)
if(CROW_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# Tests
if (NOT MSVC AND BUILD_TESTING)
if(NOT MSVC AND CROW_BUILD_TESTS)
if(NOT CROW_ENABLE_COMPRESSION)
message(STATUS "Compression tests are omitted. (Configure with CROW_ENABLE_COMPRESSION=ON to enable them)")
endif()
if(NOT CROW_ENABLE_SSL)
message(STATUS "SSL tests are omitted. (Configure with CROW_ENABLE_SSL=ON to enable them)")
endif()

add_subdirectory(tests)
enable_testing()
add_test(NAME crow_test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unittest)
Expand All @@ -74,7 +97,27 @@ endif()
#####################################
# Install Files
#####################################
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h DESTINATION include)
if(CROW_INSTALL)
install(TARGETS Crow EXPORT CrowTargets)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include)

install(EXPORT CrowTargets
FILE CrowTargets.cmake
NAMESPACE Crow::
DESTINATION lib/cmake/Crow
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CrowConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CrowConfig.cmake"
INSTALL_DESTINATION lib/cmake/Crow
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/CrowConfig.cmake"
DESTINATION lib/cmake/Crow
)
endif()

set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "CrowCpp")
Expand Down
19 changes: 19 additions & 0 deletions cmake/CrowConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@PACKAGE_INIT@

set(CROW_ENABLE_COMPRESSION @CROW_ENABLE_COMPRESSION@)
set(CROW_ENABLE_SSL @CROW_ENABLE_SSL@)

include(CMakeFindDependencyMacro)
find_dependency(Boost 1.64 COMPONENTS system date_time)
find_dependency(Threads)

if(CROW_ENABLE_COMPRESSION)
find_dependency(ZLIB)
endif()

if(CROW_ENABLE_SSL)
find_dependency(OpenSSL)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/CrowTargets.cmake")
check_required_components("@PROJECT_NAME@")
38 changes: 0 additions & 38 deletions cmake/FindTcmalloc.cmake

This file was deleted.

42 changes: 22 additions & 20 deletions cmake/compiler_options.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Compiler options with hardening flags

if(MSVC)

list(APPEND compiler_options
/W4
/permissive-
$<$<CONFIG:RELEASE>:/O2 /Ob2>
$<$<CONFIG:MINSIZEREL>:/O1 /Ob1>
$<$<CONFIG:RELWITHDEBINFO>:/Zi /O2 /Ob1>
$<$<CONFIG:DEBUG>:/Zi /Ob0 /Od /RTC1>)

else(MSVC)

list(APPEND compiler_options
-Wall
-Wextra
-Wpedantic
$<$<CONFIG:RELEASE>:-O2>
$<$<CONFIG:DEBUG>:-O0 -g -p -pg>)

endif()
function(add_warnings_optimizations target_name)
if(MSVC)
target_compile_options(${target_name}
PRIVATE
/W4
/permissive-
$<$<CONFIG:RELEASE>:/O2 /Ob2>
$<$<CONFIG:MINSIZEREL>:/O1 /Ob1>
$<$<CONFIG:RELWITHDEBINFO>:/Zi /O2 /Ob1>
$<$<CONFIG:DEBUG>:/Zi /Ob0 /Od /RTC1>
)
else()
target_compile_options(${target_name}
PRIVATE
-Wall
-Wextra
-Wpedantic
$<$<CONFIG:RELEASE>:-O2>
$<$<CONFIG:DEBUG>:-O0 -g -p -pg>
)
endif()
endfunction()
Loading