2018-03-26 00:31:39 +02:00
|
|
|
file(GLOB_RECURSE sources *.cpp)
|
2018-03-22 18:11:39 +01:00
|
|
|
add_library(app4triqs_c ${sources})
|
|
|
|
|
2019-04-03 00:07:03 +02:00
|
|
|
# Link against dependencies
|
2019-06-26 17:06:04 +02:00
|
|
|
target_link_libraries(app4triqs_c PUBLIC triqs PRIVATE project_warnings)
|
2018-03-26 00:31:39 +02:00
|
|
|
|
2019-04-03 00:07:03 +02:00
|
|
|
# Configure compilation
|
2019-04-26 18:40:44 +02:00
|
|
|
target_compile_options(app4triqs_c PUBLIC -fPIC)
|
2019-06-26 17:35:52 +02:00
|
|
|
target_include_directories(app4triqs_c PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/c++>)
|
2019-04-03 00:07:03 +02:00
|
|
|
target_compile_definitions(app4triqs_c PUBLIC
|
2019-07-16 17:54:32 +02:00
|
|
|
APP4TRIQS_GIT_HASH=${PROJECT_GIT_HASH}
|
2019-04-03 00:07:03 +02:00
|
|
|
TRIQS_GIT_HASH=${TRIQS_GIT_HASH}
|
2018-03-25 19:00:54 +02:00
|
|
|
$<$<CONFIG:Debug>:APP4TRIQS_DEBUG>
|
2019-04-03 00:07:03 +02:00
|
|
|
$<$<CONFIG:Debug>:TRIQS_DEBUG>
|
|
|
|
$<$<CONFIG:Debug>:TRIQS_ARRAYS_ENFORCE_BOUNDCHECK>
|
|
|
|
)
|
2018-03-22 18:11:39 +01:00
|
|
|
|
2018-03-25 19:00:54 +02:00
|
|
|
# Install library and headers
|
2018-03-23 16:59:38 +01:00
|
|
|
install(TARGETS app4triqs_c EXPORT app4triqs-targets DESTINATION lib)
|
2019-04-03 00:07:03 +02:00
|
|
|
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
|
2018-03-25 19:00:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
# ========= Static Analyzer Checks ==========
|
|
|
|
|
2018-04-06 14:35:21 +02:00
|
|
|
option(ANALYZE_SOURCES OFF "Run static analyzer checks if found (clang-tidy, cppcheck)")
|
|
|
|
if(ANALYZE_SOURCES)
|
|
|
|
|
|
|
|
# Locate static analyzer tools
|
|
|
|
find_program(CPPCHECK_EXECUTABLE NAMES "cppcheck" PATHS ENV PATH)
|
|
|
|
find_program(CLANG_TIDY_EXECUTABLE NAMES "clang-tidy" PATHS ENV PATH)
|
2018-03-25 19:00:54 +02:00
|
|
|
|
2018-04-06 14:35:21 +02:00
|
|
|
# Run clang-tidy if found
|
|
|
|
if(CLANG_TIDY_EXECUTABLE)
|
|
|
|
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXECUTABLE}")
|
|
|
|
set_target_properties(app4triqs_c PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
|
|
|
|
else()
|
|
|
|
message(STATUS "clang-tidy not found in $PATH. Please consider installing clang-tidy for additional checks!")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Run cppcheck if found
|
|
|
|
if(CPPCHECK_EXECUTABLE)
|
|
|
|
message(STATUS "cppcheck found: ${CPPCHECK_EXECUTABLE}")
|
|
|
|
add_custom_command(
|
2018-03-25 19:00:54 +02:00
|
|
|
TARGET app4triqs_c
|
|
|
|
COMMAND ${CPPCHECK_EXECUTABLE}
|
2018-04-06 14:35:21 +02:00
|
|
|
--enable=warning,style,performance,portability
|
|
|
|
--std=c++14
|
|
|
|
--template=gcc
|
|
|
|
--verbose
|
|
|
|
--quiet
|
|
|
|
${sources}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
message(STATUS "cppcheck not found in $PATH. Please consider installing cppcheck for additional checks!")
|
|
|
|
endif()
|
|
|
|
|
2018-03-25 19:00:54 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
# ========= Dynamic Analyzer Checks ==========
|
|
|
|
|
2019-04-03 00:07:03 +02:00
|
|
|
set(sanitizers "")
|
2018-03-25 19:00:54 +02:00
|
|
|
# Address Sanitizer
|
|
|
|
option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer")
|
|
|
|
if(ASAN)
|
2019-04-03 00:07:03 +02:00
|
|
|
list(APPEND sanitizers asan)
|
|
|
|
target_compile_options(app4triqs_c PRIVATE -fsanitize=address -fno-omit-frame-pointer -ggdb3)
|
2018-11-21 22:52:55 +01:00
|
|
|
target_link_libraries(app4triqs_c INTERFACE "-fsanitize=address -fno-omit-frame-pointer")
|
2019-04-03 00:07:03 +02:00
|
|
|
if(NOT DEFINED ENV{ASAN_OPTIONS})
|
|
|
|
message(WARNING "ASAN_OPTIONS is not set. Consider setting ASAN_OPTIONS=symbolize=1:detect_leaks=0 when running tests")
|
|
|
|
endif()
|
2018-03-25 19:00:54 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Undefined Behavior Sanitizer
|
|
|
|
option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer")
|
|
|
|
if(UBSAN)
|
2019-04-03 00:07:03 +02:00
|
|
|
list(APPEND sanitizers ubsan)
|
|
|
|
target_compile_options(app4triqs_c PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-omit-frame-pointer -ggdb3)
|
2018-11-26 18:04:35 +01:00
|
|
|
target_link_libraries(app4triqs_c INTERFACE "-fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-omit-frame-pointer")
|
2019-04-03 00:07:03 +02:00
|
|
|
if(NOT DEFINED ENV{UBSAN_OPTIONS})
|
|
|
|
message(WARNING "UBSAN_OPTIONS is not set. Consider setting UBSAN_OPTIONS=symbolize=1:print_stacktrace=1:halt_on_error=1 when running tests")
|
|
|
|
endif()
|
2018-11-21 22:52:55 +01:00
|
|
|
endif()
|
|
|
|
|
2019-04-03 00:07:03 +02:00
|
|
|
if(sanitizers)
|
|
|
|
find_package(sanitizer REQUIRED ${sanitizers})
|
|
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
|
|
|
target_link_libraries(app4triqs_c INTERFACE "-fuse-ld=gold")
|
|
|
|
endif()
|
2018-03-25 19:00:54 +02:00
|
|
|
endif()
|