Skip to content

Commit b06b085

Browse files
committed
Adding support for inferring version validating build_types
1 parent 14e7b57 commit b06b085

File tree

9 files changed

+103
-38
lines changed

9 files changed

+103
-38
lines changed

CMakeLists.txt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,57 @@ if (LEGACY_BUILD)
1717
project("aws-cpp-sdk-all" VERSION "${PROJECT_VERSION}" LANGUAGES CXX)
1818
include(legacy_main)
1919
else ()
20-
message(STATUS "Building with 1.10 CMake scripts.")
20+
message(STATUS "Building with new CMake scripts.")
2121
string(CONCAT DESCRIPTION_STRING "The AWS SDK for C++ provides a modern C++ (standard version C++11 or later) "
2222
"interface for Amazon Web Services (AWS).")
2323

24-
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
25-
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
26-
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE
27-
STRING "Choose the type of build." FORCE)
28-
# cmake-gui helper
29-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
30-
endif ()
31-
3224
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
33-
include(sdk_versioning)
34-
obtain_project_version(SDK_PROJECT_VERSION)
25+
26+
find_package(Git QUIET) # Adding development helper tools as git_hash built when available.
27+
28+
include(project_version)
29+
obtain_project_version(SDK_PROJECT_VERSION aws-cpp-sdk_GIT_HASH)
3530

3631
project("aws-cpp-sdk"
3732
LANGUAGES CXX
3833
VERSION ${SDK_PROJECT_VERSION}
3934
DESCRIPTION ${DESCRIPTION_STRING}
4035
HOMEPAGE_URL "https://docs.aws.amazon.com/sdk-for-cpp"
4136
)
37+
38+
# Setting C++ minimum requirements
4239
set(CMAKE_CXX_STANDARD 11)
4340
set(CMAKE_CXX_EXTENSIONS OFF)
4441
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4542

4643
message(STATUS "Building ${PROJECT_NAME} ${CMAKE_PROJECT_VERSION}")
4744

45+
# Setting version header for library
46+
configure_file(
47+
VersionConfig.h.in
48+
src/aws-cpp-sdk-core/include/aws/core/VersionConfig.h
49+
@ONLY
50+
)
4851

49-
message(WARNING "Anything below this warning is a TODO not yet implemented.")
52+
# Validating config type and setting default if needed
53+
get_property(is_multi_conf_build GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
54+
if (NOT is_multi_conf_build)
55+
set(allowed_build_types Debug Release RelWithDebInfo MinSizeRel)
56+
# cmake-gui helper
57+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowed_build_types}")
58+
if (NOT CMAKE_BUILD_TYPE)
59+
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
60+
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
61+
elseif (NOT CMAKE_BUILD_TYPE IN_LIST allowed_build_types)
62+
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
63+
endif ()
64+
endif ()
65+
option(BUILD_TESTS "If enabled, the SDK will include tests in the build" OFF)
5066

67+
message(WARNING "Anything below this warning is a TODO not yet implemented.")
5168
message(STATUS "Detecting toolchain and external dependencies.")
52-
message(STATUS "Prepare CRT dependency.")
5369
message(STATUS "Setting up core library.")
70+
message(STATUS "Prepare CRT dependency.")
5471
message(STATUS "Building core library.")
5572
message(STATUS "Building core library tests.")
5673
message(STATUS "Add support for static analysis.")

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.10.0

VersionConfig.h.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#define AWS_CPP_SDK_VERSION_STRING "@aws-cpp-sdk_VERSION_STRING@"
7+
#define AWS_CPP_SDK_VERSION_MAJOR @aws-cpp-sdk_VERSION_MAJOR@
8+
#define AWS_CPP_SDK_VERSION_MINOR @aws-cpp-sdk_VERSION_MINOR@
9+
#define AWS_CPP_SDK_VERSION_PATCH @aws-cpp-sdk_VERSION_PATCH@
10+
#define AWS_CPP_SDK_GIT_HASH "@aws-cpp-sdk_GIT_HASH@"
11+
12+
// DEPRECATED in 1.10: The follow defines are kept for backward compatibility
13+
// Please prefer the use the new ones defined above
14+
#define AWS_SDK_VERSION_STRING AWS_CPP_SDK_VERSION_STRING
15+
#define AWS_SDK_VERSION_MAJOR AWS_CPP_SDK_VERSION_MAJOR
16+
#define AWS_SDK_VERSION_MINOR AWS_CPP_SDK_VERSION_MINOR
17+
#define AWS_SDK_VERSION_PATCH AWS_CPP_SDK_VERSION_PATCH
18+

cmake/project_version.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include_guard()
2+
3+
function(obtain_project_version resultVarVersion resultVarGitHash)
4+
if (GIT_FOUND)
5+
execute_process(
6+
COMMAND ${GIT_EXECUTABLE} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git describe --abbrev=0 --tags
7+
OUTPUT_VARIABLE VERSION_STRING
8+
OUTPUT_STRIP_TRAILING_WHITESPACE
9+
)
10+
execute_process(
11+
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
12+
RESULT_VARIABLE git_result
13+
OUTPUT_VARIABLE GIT_HASH
14+
OUTPUT_STRIP_TRAILING_WHITESPACE
15+
)
16+
if (NOT git_result)
17+
set(${resultVarGitHash} ${GIT_HASH} PARENT_SCOPE)
18+
message(STATUS "Building git hash: ${GIT_HASH}")
19+
endif()
20+
endif ()
21+
22+
if (NOT VERSION_STRING) # Non DEV build relays on VERSION file updated by release CI
23+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION_STRING)
24+
endif ()
25+
26+
set(${resultVarVersion} ${VERSION_STRING} PARENT_SCOPE)
27+
message(STATUS "SDK project version: ${VERSION_STRING}")
28+
endfunction()

cmake/sdk_versioning.cmake

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/aws-cpp-sdk-core/include/aws/core/Version.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ namespace Version
1515
AWS_CORE_API unsigned GetVersionMinor();
1616
AWS_CORE_API unsigned GetVersionPatch();
1717
AWS_CORE_API const char* GetCompilerVersionString();
18+
AWS_CORE_API const char* GetGitHash();
1819
} //namespace Version
1920
} //namespace Aws

src/aws-cpp-sdk-core/include/aws/core/VersionConfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
// DEPRECATED: This file is used by legacy_build generators only
7+
68
#define AWS_SDK_VERSION_STRING "1.9.227"
79
#define AWS_SDK_VERSION_MAJOR 1
810
#define AWS_SDK_VERSION_MINOR 9
911
#define AWS_SDK_VERSION_PATCH 227
12+
// Forward compatible definitions
13+
#define AWS_CPP_SDK_VERSION_STRING AWS_SDK_VERSION_STRING
14+
#define AWS_CPP_SDK_VERSION_MAJOR AWS_SDK_VERSION_MAJOR
15+
#define AWS_CPP_SDK_VERSION_MINOR AWS_SDK_VERSION_MINOR
16+
#define AWS_CPP_SDK_VERSION_PATCH AWS_SDK_VERSION_PATCH
17+
#define AWS_CPP_SDK_GIT_HASH "NoHashAvailableInLegacyBuild"

src/aws-cpp-sdk-core/include/aws/core/VersionConfig.h.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
// DEPRECATED: This file is used by legacy_build generators only
7+
68
#define AWS_SDK_VERSION_STRING "@AWSSDK_VERSION_STRING@"
79
#define AWS_SDK_VERSION_MAJOR @AWSSDK_VERSION_MAJOR@
810
#define AWS_SDK_VERSION_MINOR @AWSSDK_VERSION_MINOR@
9-
#define AWS_SDK_VERSION_PATCH @AWSSDK_VERSION_PATCH@
11+
#define AWS_SDK_VERSION_PATCH @AWSSDK_VERSION_PATCH@
12+
// Forward compatible definitions
13+
#define AWS_CPP_SDK_VERSION_STRING AWS_SDK_VERSION_STRING
14+
#define AWS_CPP_SDK_VERSION_MAJOR AWS_SDK_VERSION_MAJOR
15+
#define AWS_CPP_SDK_VERSION_MINOR AWS_SDK_VERSION_MINOR
16+
#define AWS_CPP_SDK_VERSION_PATCH AWS_SDK_VERSION_PATCH
17+
#define AWS_CPP_SDK_GIT_HASH "NoHashAvailableInLegacyBuild"

src/aws-cpp-sdk-core/source/Version.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,26 @@ namespace Version
1212
{
1313
const char* GetVersionString()
1414
{
15-
return AWS_SDK_VERSION_STRING;
15+
return AWS_CPP_SDK_VERSION_STRING;
1616
}
1717

1818
unsigned GetVersionMajor()
1919
{
20-
return AWS_SDK_VERSION_MAJOR;
20+
return AWS_CPP_SDK_VERSION_MAJOR;
2121
}
2222

2323
unsigned GetVersionMinor()
2424
{
25-
return AWS_SDK_VERSION_MINOR;
25+
return AWS_CPP_SDK_VERSION_MINOR;
2626
}
2727

2828
unsigned GetVersionPatch()
2929
{
30-
return AWS_SDK_VERSION_PATCH;
30+
return AWS_CPP_SDK_VERSION_PATCH;
31+
}
32+
33+
const char* GetGitHash(){
34+
return AWS_CPP_SDK_GIT_HASH;
3135
}
3236

3337

0 commit comments

Comments
 (0)