Skip to content

Commit

Permalink
rework cmake configs.
Browse files Browse the repository at this point in the history
See CrowCpp#160 for more info.
  • Loading branch information
luca-schlecker committed Aug 30, 2021
1 parent 6e1f5b5 commit ad4b299
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 225 deletions.
16 changes: 8 additions & 8 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ steps:
- 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 Down Expand Up @@ -62,15 +62,15 @@ steps:
- 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 @@ -114,7 +114,7 @@ steps:
- 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 @@ -155,15 +155,15 @@ steps:
- 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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
89 changes: 51 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,79 @@
#####################################
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
)
add_library(Crow INTERFACE)
add_library(Crow::Crow ALIAS Crow)
target_include_directories(Crow INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)

include_directories("${PROJECT_INCLUDE_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_BINARY_DIR}") # To include crow_all.h
endif()
find_package(Boost 1.64 COMPONENTS system date_time REQUIRED)
find_package(Threads REQUIRED)

#####################################
# 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
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)
add_subdirectory(tests)
enable_testing()
add_test(NAME crow_test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unittest)
Expand All @@ -74,7 +85,9 @@ endif()
#####################################
# Install Files
#####################################
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h DESTINATION include)
if(CROW_INSTALL)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include)
endif()

set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "CrowCpp")
Expand Down
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()
35 changes: 0 additions & 35 deletions cmake/dependencies.cmake

This file was deleted.

Loading

0 comments on commit ad4b299

Please sign in to comment.