Added new cmake modules

This commit is contained in:
Michele Adduci 2021-01-08 16:15:45 +01:00
parent 6d4c7d8a9b
commit eb8ad4b685
2 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# 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>
$<$<CONFIG:DEBUG>:-g>
$<$<CONFIG:DEBUG>:-p>
$<$<CONFIG:DEBUG>:-pg>)
endif()
# This can also be done with target_compile_options() [recommended]
set(CMAKE_CXX_FLAGS "${compiler_options}")

36
cmake/dependencies.cmake Normal file
View File

@ -0,0 +1,36 @@
# Dependencies
if(BUILD_EXAMPLES OR BUILD_TESTING)
find_package(Tcmalloc)
find_package(Threads)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message("Found ccache ${CCACHE_FOUND}")
message("Using ccache to speed up compilation")
set(ENV{CCACHE_CPP2} "yes")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
if (MSVC)
set(Boost_USE_STATIC_LIBS ON)
find_package( Boost 1.52 COMPONENTS system thread regex REQUIRED )
else()
find_package( Boost 1.52 COMPONENTS system thread REQUIRED )
endif()
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
endif()
if(BUILD_EXAMPLES)
# OpenSSL is required at runtime dynamically by examples
find_package(OpenSSL)
if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
endif()
endif()