From a49af31188fe77c046f5419abd527441f0758831 Mon Sep 17 00:00:00 2001 From: Christian Prather Date: Tue, 11 Jul 2023 13:54:22 -0600 Subject: [PATCH] Added cmake versioning and removed hardcoded share dir path --- CMakeLists.txt | 18 ++++++++++++++---- version.cmake | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 version.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ce25f95..e7de4f2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,14 @@ cmake_minimum_required(VERSION 3.10) -project(Tracy LANGUAGES CXX) +# Run version helper script +include(version.cmake) + +set(TRACY_VERSION_MAJOR ${major}) +set(TRACY_VERSION_MINOR ${minor}) +set(TRACY_VERSION_PATCH ${patch}) +set(TRACY_VERSION_STRING "${TRACY_VERSION_MAJOR}.${TRACY_VERSION_MINOR}.${TRACY_VERSION_PATCH}") + +project(Tracy LANGUAGES CXX VERSION ${TRACY_VERSION_STRING}) if(${BUILD_SHARED_LIBS}) set(DEFAULT_STATIC OFF) @@ -84,6 +92,8 @@ endif() include(CMakePackageConfigHelpers) include(GNUInstallDirs) +set_target_properties(TracyClient PROPERTIES VERSION ${PROJECT_VERSION}) + set(tracy_includes ${TRACY_PUBLIC_DIR}/tracy/TracyC.h ${TRACY_PUBLIC_DIR}/tracy/Tracy.hpp @@ -146,10 +156,10 @@ install(FILES ${common_includes} install(EXPORT TracyConfig NAMESPACE Tracy:: FILE TracyTargets.cmake - DESTINATION share/Tracy) + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Tracy) include(CMakePackageConfigHelpers) configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/TracyConfig.cmake" - INSTALL_DESTINATION share/Tracy) + INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Tracy) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TracyConfig.cmake - DESTINATION share/Tracy) + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Tracy) diff --git a/version.cmake b/version.cmake new file mode 100644 index 00000000..02ca8748 --- /dev/null +++ b/version.cmake @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.10) + +message("Parsing public/common/TracyVersion.hpp file") + +file(READ "public/common/TracyVersion.hpp" version) + +# Note: This looks for a specific pattern in TracyVersion.hpp, if it changes +# this needs updating. +string(REGEX MATCH "Major = ([0-9]+)" _ ${version}) + +# This works do to the above () subexpression selection. See +# https://cmake.org/cmake/help/latest/command/string.html#regex-match for more +# details +set(major ${CMAKE_MATCH_1}) + +string(REGEX MATCH "Minor = ([0-9]+)" _ ${version}) +set(minor ${CMAKE_MATCH_1}) + +string(REGEX MATCH "Patch = ([0-9]+)" _ ${version}) +set(patch ${CMAKE_MATCH_1}) + +message("VERSION ${major}.${minor}.${patch}")