You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.0 KiB

5 years ago
cmake_minimum_required(VERSION 3.12)
find_program(CCACHE_FOUND ccache)
5 years ago
if (CCACHE_FOUND)
5 years ago
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
5 years ago
endif (CCACHE_FOUND)
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx17.cmake"
CACHE
FILEPATH
"Default toolchain"
)
include("cmake/Hunter/init.cmake")
project(libp2p C CXX)
5 years ago
include(cmake/print.cmake)
print("C flags: ${CMAKE_C_FLAGS}")
print("CXX flags: ${CMAKE_CXX_FLAGS}")
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
5 years ago
include(CheckCXXCompilerFlag)
include(cmake/install.cmake)
include(cmake/libp2p_add_library.cmake)
5 years ago
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
5 years ago
include(cmake/san.cmake)
5 years ago
5 years ago
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5 years ago
option(TESTING "Build tests" ON)
5 years ago
option(CLANG_FORMAT "Enable clang-format target" ON)
option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF)
option(COVERAGE "Enable generation of coverage info" OFF)
# sanitizers will be enabled only for libp2p, and will be disabled for dependencies
option(ASAN "Enable address sanitizer" OFF)
option(LSAN "Enable leak sanitizer" OFF)
option(MSAN "Enable memory sanitizer" OFF)
option(TSAN "Enable thread sanitizer" OFF)
option(UBSAN "Enable UB sanitizer" OFF)
5 years ago
## setup compilation flags
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
# enable those flags
add_flag(-Wall)
add_flag(-Wextra)
add_flag(-Woverloaded-virtual) # warn if you overload (not override) a virtual function
add_flag(-Wformat=2) # warn on security issues around functions that format output (ie printf)
add_flag(-Wmisleading-indentation) # (only in GCC >= 6.0) warn if indentation implies blocks where blocks do not exist
add_flag(-Wduplicated-cond) # (only in GCC >= 6.0) warn if if / else chain has duplicated conditions
add_flag(-Wduplicated-branches) # (only in GCC >= 7.0) warn if if / else branches have duplicated code
add_flag(-Wnull-dereference) # (only in GCC >= 6.0) warn if a null dereference is detected
add_flag(-Wdouble-promotion) # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
add_flag(-Wsign-compare)
5 years ago
add_flag(-Wtype-limits) # size_t - size_t >= 0 -> always true
5 years ago
# disable those flags
add_flag(-Wno-unused-command-line-argument) # clang: warning: argument unused during compilation: '--coverage' [-Wunused-command-line-argument]
add_flag(-Wno-unused-parameter) # prints too many useless warnings
add_flag(-Wno-format-nonliteral) # prints way too many warnings from spdlog
add_flag(-Wno-gnu-zero-variadic-macro-arguments) # https://stackoverflow.com/questions/21266380/is-the-gnu-zero-variadic-macro-arguments-safe-to-ignore
# promote to errors
add_flag(-Werror-unused-lambda-capture) # error if lambda capture is unused
add_flag(-Werror-return-type) # warning: control reaches end of non-void function [-Wreturn-type]
add_flag(-Werror-non-virtual-dtor) # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors
add_flag(-Werror-sign-compare) # warn the user if they compare a signed and unsigned numbers
add_flag(-Werror-reorder) # field '$1' will be initialized after field '$2'
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
# TODO(warchant): add flags https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#msvc
5 years ago
endif ()
5 years ago
5 years ago
if (COVERAGE)
5 years ago
include(cmake/coverage.cmake)
5 years ago
endif ()
if (CLANG_TIDY)
5 years ago
include(cmake/clang-tidy.cmake)
5 years ago
endif ()
if (CLANG_FORMAT)
include(cmake/clang-format.cmake)
endif ()
5 years ago
5 years ago
include_directories(
# project includes
${PROJECT_SOURCE_DIR}/include
5 years ago
)
include_directories(
SYSTEM
# system includes
deps/di/include
deps/di/extension/include
deps/hat-trie/include
deps/spdlog/include
5 years ago
)
add_subdirectory(src)
add_subdirectory(example)
5 years ago
if(TESTING)
enable_testing()
add_subdirectory(test)
endif()