Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include/cpp_core/version.h
include/cpp_core/version.hpp
build/
.cache/
compile_commands.json
55 changes: 24 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,28 @@ cmake_minimum_required(VERSION 3.30)
# Export compile commands to root directory
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# ---------------------------------------------------------------------------
# Version information from Git tags
# Version is determined automatically from Git tags and cannot be overridden
# ---------------------------------------------------------------------------
include(${CMAKE_CURRENT_LIST_DIR}/cmake/get_version_from_git.cmake)

# Get version from Git tags
get_version_from_git()
set(CPP_CORE_VERSION_MAJOR ${VERSION_MAJOR} CACHE STRING "Major version number" FORCE)
set(CPP_CORE_VERSION_MINOR ${VERSION_MINOR} CACHE STRING "Minor version number" FORCE)
set(CPP_CORE_VERSION_PATCH ${VERSION_PATCH} CACHE STRING "Patch version number" FORCE)
set(CPP_CORE_VERSION_STRING ${VERSION_STRING} CACHE STRING "Full version string" FORCE)

# Set PROJECT_VERSION for CMake package config (only MAJOR.MINOR.PATCH, no suffix)
set(PROJECT_VERSION "${CPP_CORE_VERSION_MAJOR}.${CPP_CORE_VERSION_MINOR}.${CPP_CORE_VERSION_PATCH}")
include(cmake/CPM.cmake)

CPMAddPackage(
NAME cmake-git-versioning
GITHUB_REPOSITORY Katze719/cmake-git-versioning
GIT_TAG v1.0.0
)

# Include the cmake-git-versioning module
include(${cmake-git-versioning_SOURCE_DIR}/cmake/cmake-git-versioning.cmake)

# Get git version info (sets CMake variables)
get_git_version_info()
generate_git_version(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/include/cpp_core)

project(
cpp-core
VERSION ${PROJECT_VERSION}
VERSION "${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCH}"
DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings"
LANGUAGES CXX
)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h
@ONLY
)

# Header-only library --------------------------------------------------------
add_library(cpp_core INTERFACE)
add_library(cpp_core::cpp_core ALIAS cpp_core)
Expand All @@ -40,8 +33,8 @@ add_library(cpp_core::cpp_core ALIAS cpp_core)
target_include_directories(
cpp_core
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# Set C++ standard
Expand Down Expand Up @@ -74,9 +67,9 @@ include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake
VERSION ${PROJECT_VERSION}
VERSION "${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCH}"
COMPATIBILITY SameMajorVersion
)
)

configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/cpp_core_config.cmake.in
Expand All @@ -93,18 +86,18 @@ install(

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core
)

if(CMAKE_EXPORT_COMPILE_COMMANDS AND EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json")
add_custom_target(
copy-compile-commands
ALL
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/compile_commands.json
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/compile_commands.json
DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json
COMMENT "Copying compile_commands.json to project root"
)
Expand Down
Loading