127 lines
3.5 KiB
CMake
127 lines
3.5 KiB
CMake
# FeynmanDB
|
|
#
|
|
# Copyright (c) 2023-2024 Sameer Rahmani <lxsameer@gnu.org>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, version 2.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
find_program(iwyu NAMES include-what-you-use iwyu REQUIRED)
|
|
set(iwyu_path ${iwyu})
|
|
|
|
find_program(lld NAMES lld REQUIRED)
|
|
|
|
add_executable(feynman)
|
|
|
|
set_target_properties(feynman PROPERTIES
|
|
VERSION ${PROJECT_VERSION}
|
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
|
C_INCLUDE_WHAT_YOU_USE ${iwyu}
|
|
CXX_INCLUDE_WHAT_YOU_USE ${iwyu}
|
|
# Warn on unused libs
|
|
LINK_WHAT_YOU_USE TRUE
|
|
)
|
|
|
|
target_compile_features(feynman PRIVATE cxx_std_20)
|
|
|
|
# Setup header directory and auto generated headers
|
|
target_include_directories(feynman
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
)
|
|
|
|
target_include_directories(feynman SYSTEM PUBLIC
|
|
# We don't want the generated files from table gen
|
|
# to be treated as local since the contain warnings
|
|
${PROJECT_BINARY_DIR}/include)
|
|
|
|
|
|
# target_link_libraries(feynman PRIVATE
|
|
|
|
# )
|
|
|
|
# Autogenerate the `config.h` file
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in include/config.h)
|
|
|
|
target_compile_options(feynman
|
|
PRIVATE
|
|
# $<$<BOOL:${ENABLE_LIBCXX}>:-stdlib=libc++>
|
|
|
|
-fno-builtin-strlen
|
|
|
|
# Dedicate a section to each function, so the linker
|
|
# can do a better job on dead code elimination
|
|
-ffunction-sections
|
|
-fdata-sections
|
|
|
|
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
|
$<$<CONFIG:DEBUG>:-static-libsan>
|
|
$<$<CONFIG:DEBUG>:-g3>
|
|
$<$<CONFIG:DEBUG>:-O0>
|
|
$<$<CONFIG:DEBUG>:-ggdb>
|
|
# For the sake of debugging
|
|
$<$<CONFIG:DEBUG>:-fno-inline>
|
|
# To make the local ccache happy
|
|
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=.>
|
|
|
|
# No tail call elimination on Debug to let asan provide
|
|
# better stacktrackes
|
|
$<$<CONFIG:DEBUG>:-fno-optimize-sibling-calls>
|
|
|
|
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
|
|
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
|
|
$<$<CONFIG:RELEASE>:-O3>
|
|
$<$<CONFIG:RELEASE>:-fmerge-all-constants>
|
|
)
|
|
|
|
target_link_options(feynman PRIVATE
|
|
-Wl,--gc-sections
|
|
-Wl,-fuse-ld=lld
|
|
$<$<CONFIG:RELEASE>:-s>
|
|
|
|
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
|
$<$<CONFIG:DEBUG>:-static-libsan>
|
|
|
|
# Do not link against shared libraries
|
|
-static-pie
|
|
)
|
|
|
|
if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
|
|
find_program(CLANG_TIDY_PATH NAMES clang-tidy REQUIRED)
|
|
set_target_properties(feynman PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
|
endif()
|
|
|
|
include(CheckIPOSupported)
|
|
set_property(TARGET feynman PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
include(CheckPIESupported)
|
|
check_pie_supported()
|
|
set_property(TARGET feynman PROPERTY POSITION_INDEPENDENT_CODE TRUE)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
install(TARGETS feynman EXPORT FeynmanTargets
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
|
|
if(ENABLE_TESTS)
|
|
enable_testing()
|
|
find_package(GTest REQUIRED)
|
|
add_subdirectory(tests)
|
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
endif()
|
|
|
|
add_subdirectory(src)
|