2018-03-26 00:31:39 +02:00
|
|
|
file(GLOB_RECURSE sources *.cpp)
|
2020-05-28 17:09:35 +02:00
|
|
|
add_library(${PROJECT_NAME}_c ${sources})
|
|
|
|
add_library(${PROJECT_NAME}::${PROJECT_NAME}_c ALIAS ${PROJECT_NAME}_c)
|
2018-03-22 18:11:39 +01:00
|
|
|
|
2019-09-18 20:23:14 +02:00
|
|
|
# Link against triqs and enable warnings
|
2020-05-28 17:09:35 +02:00
|
|
|
target_link_libraries(${PROJECT_NAME}_c PUBLIC triqs PRIVATE $<BUILD_INTERFACE:${PROJECT_NAME}_warnings>)
|
2018-03-26 00:31:39 +02:00
|
|
|
|
2020-04-24 23:50:26 +02:00
|
|
|
# Configure target and compilation
|
2020-10-30 19:39:40 +01:00
|
|
|
set_target_properties(${PROJECT_NAME}_c PROPERTIES
|
|
|
|
POSITION_INDEPENDENT_CODE ON
|
|
|
|
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
|
|
|
)
|
2020-05-28 17:09:35 +02:00
|
|
|
target_include_directories(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/c++>)
|
|
|
|
target_include_directories(${PROJECT_NAME}_c SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
|
|
|
|
target_compile_definitions(${PROJECT_NAME}_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
|
2020-05-28 17:09:35 +02:00
|
|
|
install(TARGETS ${PROJECT_NAME}_c EXPORT ${PROJECT_NAME}-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}")
|
2020-05-28 17:09:35 +02:00
|
|
|
set_target_properties(${PROJECT_NAME}_c PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
|
2018-04-06 14:35:21 +02:00
|
|
|
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(
|
2020-05-28 17:09:35 +02:00
|
|
|
TARGET ${PROJECT_NAME}_c
|
2018-03-25 19:00:54 +02:00
|
|
|
COMMAND ${CPPCHECK_EXECUTABLE}
|
2018-04-06 14:35:21 +02:00
|
|
|
--enable=warning,style,performance,portability
|
2019-09-13 23:50:00 +02:00
|
|
|
--std=c++17
|
2018-04-06 14:35:21 +02:00
|
|
|
--template=gcc
|
|
|
|
--verbose
|
2019-11-21 17:54:10 +01:00
|
|
|
--force
|
2018-04-06 14:35:21 +02:00
|
|
|
--quiet
|
|
|
|
${sources}
|
2019-11-21 17:54:10 +01:00
|
|
|
WORKING_DIRECTORY
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
2018-04-06 14:35:21 +02:00
|
|
|
)
|
|
|
|
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 ==========
|
|
|
|
|
|
|
|
option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer")
|
2019-09-16 20:39:27 +02:00
|
|
|
option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer")
|
|
|
|
|
2018-03-25 19:00:54 +02:00
|
|
|
if(ASAN)
|
2019-11-18 20:04:29 +01:00
|
|
|
if(NOT TARGET asan)
|
|
|
|
find_package(sanitizer REQUIRED "asan")
|
|
|
|
endif()
|
2020-05-28 17:09:35 +02:00
|
|
|
target_link_libraries(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:asan>)
|
2018-03-25 19:00:54 +02:00
|
|
|
endif()
|
|
|
|
if(UBSAN)
|
2019-11-18 20:04:29 +01:00
|
|
|
if(NOT TARGET ubsan)
|
|
|
|
find_package(sanitizer REQUIRED "ubsan")
|
|
|
|
endif()
|
2020-05-28 17:09:35 +02:00
|
|
|
target_link_libraries(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:ubsan>)
|
2018-03-25 19:00:54 +02:00
|
|
|
endif()
|