130 lines
3.8 KiB
CMake
130 lines
3.8 KiB
CMake
# git-journal - A git plugin to manage journal entries in git
|
|
#
|
|
# 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/>.
|
|
|
|
|
|
add_executable(git-journal)
|
|
|
|
set_target_properties(git-journal 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(git-journal PRIVATE cxx_std_20)
|
|
|
|
# Setup header directory and auto generated headers
|
|
target_include_directories(git-journal
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
)
|
|
|
|
target_include_directories(git-journal SYSTEM PUBLIC
|
|
# We don't want the generated files from table gen
|
|
# to be treated as local since the contain warnings
|
|
${PROJECT_BINARY_DIR}/git-journal/include)
|
|
|
|
target_link_libraries(git-journal PRIVATE
|
|
LLVMSupport
|
|
)
|
|
|
|
# Autogenerate the `config.h` file
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/git-journal/config.h.in include/git-journal/config.h)
|
|
|
|
target_compile_options(git-journal
|
|
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(git-journal PRIVATE
|
|
$<$<BOOL:${ENABLE_LIBCXX}>:-stdlib=libc++>
|
|
$<$<BOOL:${ENABLE_LIBCXX}>:-lc++abi>
|
|
$<$<BOOL:${ENABLE_COMPILER_RT}>:--rtlib=compiler-rt>
|
|
|
|
-Wl,--gc-sections
|
|
$<$<CONFIG:RELEASE>:-s>
|
|
|
|
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
|
$<$<CONFIG:DEBUG>:-static-libsan>
|
|
# Do not link against shared libraries
|
|
--static
|
|
)
|
|
|
|
if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
|
|
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
|
endif()
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
# Optional IPO. Do not use IPO if it's not supported by compiler.
|
|
check_ipo_supported(RESULT result OUTPUT output)
|
|
if(result)
|
|
message(STATUS "IPO is supported and is turned on")
|
|
set_property(TARGET git-journal PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
else()
|
|
message(WARNING "IPO is not supported: ${output}")
|
|
message(WARNING "Make sure to use lld")
|
|
endif()
|
|
endif()
|
|
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
install(TARGETS git-journal EXPORT Git-JournalTargets
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
add_subdirectory(src)
|
|
add_subdirectory(include)
|
|
|
|
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()
|