Fixes that allows use project as submodule (#815)
* Fix ADS_VERSION support for builds without git dependency - Move CMAKE_MODULE_PATH outside if(NOT ADS_VERSION) block so it's always available - Parse ADS_VERSION to set PROJECT_VERSION_* variables for Versioning.cmake - Update Versioning.cmake to use predefined version when available, fallback to git This allows building with -DADS_VERSION=X.Y.Z without requiring git repository. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> * Add ADS_PLATFORM_DIR option to customize output directory Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> --------- Co-authored-by: ArtemNabok <nabok.artem@yandex.ru> Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -4,12 +4,14 @@ if (POLICY CMP0091)
|
|||||||
cmake_policy(SET CMP0091 NEW)
|
cmake_policy(SET CMP0091 NEW)
|
||||||
endif (POLICY CMP0091)
|
endif (POLICY CMP0091)
|
||||||
|
|
||||||
|
# Add cmake modules path (required for Versioning.cmake and git revision description)
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
# By default, the version information is extracted from the git index. However,
|
# By default, the version information is extracted from the git index. However,
|
||||||
# we can override this behavior by explicitly setting ADS_VERSION and
|
# we can override this behavior by explicitly setting ADS_VERSION and
|
||||||
# skipping the git checks. This is useful for cases where this project is being
|
# skipping the git checks. This is useful for cases where this project is being
|
||||||
# used independently of its original git repo (e.g. vendored in another project)
|
# used independently of its original git repo (e.g. vendored in another project)
|
||||||
if(NOT ADS_VERSION)
|
if(NOT ADS_VERSION)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
|
||||||
include(GetGitRevisionDescription)
|
include(GetGitRevisionDescription)
|
||||||
git_describe(GitTagVersion --tags)
|
git_describe(GitTagVersion --tags)
|
||||||
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GitTagVersion}")
|
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GitTagVersion}")
|
||||||
@@ -23,6 +25,11 @@ else()
|
|||||||
if(VERSION_DOT_COUNT EQUAL 2)
|
if(VERSION_DOT_COUNT EQUAL 2)
|
||||||
set(VERSION_SHORT ${ADS_VERSION})
|
set(VERSION_SHORT ${ADS_VERSION})
|
||||||
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_SONAME "${ADS_VERSION}")
|
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_SONAME "${ADS_VERSION}")
|
||||||
|
# Set PROJECT_VERSION_* variables for Versioning.cmake
|
||||||
|
string(REGEX MATCHALL "[0-9]+" VERSION_PARTS "${ADS_VERSION}")
|
||||||
|
list(GET VERSION_PARTS 0 PROJECT_VERSION_MAJOR)
|
||||||
|
list(GET VERSION_PARTS 1 PROJECT_VERSION_MINOR)
|
||||||
|
list(GET VERSION_PARTS 2 PROJECT_VERSION_PATCH)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "ADS_VERSION must be in major.minor.patch format, e.g. 3.8.1. Got ${ADS_VERSION}")
|
message(FATAL_ERROR "ADS_VERSION must be in major.minor.patch format, e.g. 3.8.1. Got ${ADS_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
@@ -34,10 +41,15 @@ project(QtADS LANGUAGES CXX VERSION ${VERSION_SHORT})
|
|||||||
option(BUILD_STATIC "Build the static library" OFF)
|
option(BUILD_STATIC "Build the static library" OFF)
|
||||||
option(BUILD_EXAMPLES "Build the examples" ON)
|
option(BUILD_EXAMPLES "Build the examples" ON)
|
||||||
|
|
||||||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
# Platform directory: auto-detected based on pointer size, or manually set
|
||||||
set(ads_PlatformDir "x86")
|
if(NOT ADS_PLATFORM_DIR)
|
||||||
|
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
||||||
|
set(ads_PlatformDir "x86")
|
||||||
|
else()
|
||||||
|
set(ads_PlatformDir "x64")
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
set(ads_PlatformDir "x64")
|
set(ads_PlatformDir "${ADS_PLATFORM_DIR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|||||||
@@ -8,45 +8,48 @@
|
|||||||
set(_VERSIONING_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "Versioning module directory")
|
set(_VERSIONING_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "Versioning module directory")
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# Extract version information from Git
|
# Extract version information from Git or use predefined version
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
if(NOT DEFINED PROJECT_VERSION_MAJOR OR NOT DEFINED PROJECT_VERSION_MINOR OR NOT DEFINED PROJECT_VERSION_PATCH)
|
||||||
|
# Get tag (expected: v1.2.3 or 1.2.3 or 1.2.3-12-gHASH)
|
||||||
|
execute_process(
|
||||||
|
COMMAND git describe --tags --dirty
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE GIT_DESC_RAW
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
# Get tag (expected: v1.2.3 or 1.2.3 or 1.2.3-12-gHASH)
|
# Remove leading "v" if present
|
||||||
execute_process(
|
string(REGEX REPLACE "^v" "" GIT_DESC "${GIT_DESC_RAW}")
|
||||||
COMMAND git describe --tags --dirty
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
OUTPUT_VARIABLE GIT_DESC_RAW
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
# Remove leading "v" if present
|
# Extract major.minor.patch
|
||||||
string(REGEX REPLACE "^v" "" GIT_DESC "${GIT_DESC_RAW}")
|
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ "${GIT_DESC}")
|
||||||
|
set(PROJECT_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
||||||
|
set(PROJECT_VERSION_MINOR "${CMAKE_MATCH_2}")
|
||||||
|
set(PROJECT_VERSION_PATCH "${CMAKE_MATCH_3}")
|
||||||
|
|
||||||
# Extract major.minor.patch
|
|
||||||
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ "${GIT_DESC}")
|
|
||||||
set(PROJECT_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
# Commit hash (full + short)
|
||||||
set(PROJECT_VERSION_MINOR "${CMAKE_MATCH_2}")
|
execute_process(
|
||||||
set(PROJECT_VERSION_PATCH "${CMAKE_MATCH_3}")
|
COMMAND git rev-parse HEAD
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE PROJECT_GIT_HASH
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND git rev-parse --short HEAD
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE PROJECT_GIT_HASH_SHORT
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(PROJECT_VERSION_STRING
|
set(PROJECT_VERSION_STRING
|
||||||
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
|
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Commit hash (full + short)
|
|
||||||
execute_process(
|
|
||||||
COMMAND git rev-parse HEAD
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
OUTPUT_VARIABLE PROJECT_GIT_HASH
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND git rev-parse --short HEAD
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
OUTPUT_VARIABLE PROJECT_GIT_HASH_SHORT
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
# Export variables to parent scope
|
# Export variables to parent scope
|
||||||
set(PROJECT_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}" PARENT_SCOPE)
|
set(PROJECT_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}" PARENT_SCOPE)
|
||||||
set(PROJECT_VERSION_MINOR "${PROJECT_VERSION_MINOR}" PARENT_SCOPE)
|
set(PROJECT_VERSION_MINOR "${PROJECT_VERSION_MINOR}" PARENT_SCOPE)
|
||||||
|
|||||||
Reference in New Issue
Block a user