Skip to content

Commit 7142e6e

Browse files
Marco Magdymarcomagdy
authored andcommitted
Define subparts of the version in cmake rather than in a header file
This simplifies our build process. Since we derive the version from git tags, we run into a chicken/egg problem. change the file and tag it, or tag it and derive the version from the tag.
1 parent 392dc34 commit 7142e6e

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

aws-cpp-sdk-core-tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ file(GLOB UTILS_XML_SRC "${CMAKE_CURRENT_SOURCE_DIR}/utils/memory/*.cpp")
2222

2323
file(GLOB AWS_CPP_SDK_CORE_TESTS_SRC
2424
"${CMAKE_CURRENT_SOURCE_DIR}/RunTests.cpp"
25+
"${CMAKE_CURRENT_SOURCE_DIR}/VersionTests.cpp"
2526
${AWS_SRC}
2627
${AWS_AUTH_SRC}
2728
${AWS_CONFIG_SRC}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#include <aws/external/gtest.h>
17+
#include <aws/core/utils/StringUtils.h>
18+
#include <aws/core/Version.h>
19+
20+
using namespace Aws::Version;
21+
22+
TEST(VersionTest, TestMajorMinorPatch)
23+
{
24+
auto major = GetVersionMajor();
25+
auto minor = GetVersionMinor();
26+
auto patch = GetVersionPatch();
27+
Aws::String version;
28+
version += Aws::Utils::StringUtils::to_string(major);
29+
version += ".";
30+
version += Aws::Utils::StringUtils::to_string(minor);
31+
version += ".";
32+
version += Aws::Utils::StringUtils::to_string(patch);
33+
auto versionString = GetVersionString();
34+
ASSERT_STREQ(versionString, version.c_str());
35+
}

aws-cpp-sdk-core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ endif(MSVC)
316316
add_library(${PROJECT_NAME} ${LIBTYPE} ${AWS_NATIVE_SDK_SRC})
317317
add_library(AWS::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
318318

319+
target_compile_definitions(${PROJECT_NAME} PUBLIC "AWS_SDK_VERSION_MAJOR=${AWSSDK_VERSION_MAJOR}")
320+
target_compile_definitions(${PROJECT_NAME} PUBLIC "AWS_SDK_VERSION_MINOR=${AWSSDK_VERSION_MINOR}")
321+
target_compile_definitions(${PROJECT_NAME} PUBLIC "AWS_SDK_VERSION_PATCH=${AWSSDK_VERSION_PATCH}")
322+
319323
set(Core_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include/")
320324

321325
if(PLATFORM_CUSTOM)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ namespace Aws
1919
{
2020
namespace Version
2121
{
22-
AWS_CORE_API const char* GetVersionString();
22+
AWS_CORE_API const char* GetVersionString();
23+
AWS_CORE_API unsigned GetVersionMajor();
24+
AWS_CORE_API unsigned GetVersionMinor();
25+
AWS_CORE_API unsigned GetVersionPatch();
2326
} //namespace Version
2427
} //namespace Aws

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@
1414
*/
1515

1616
#define AWS_SDK_VERSION_STRING "@AWSSDK_VERSION_STRING@"
17-
#define AWS_SDK_VERSION_MAJOR @AWSSDK_VERSION_MAJOR@
18-
#define AWS_SDK_VERSION_MINOR @AWSSDK_VERSION_MINOR@
19-
#define AWS_SDK_VERSION_PATCH @AWSSDK_VERSION_PATCH@

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ namespace Version
2424
{
2525
return AWS_SDK_VERSION_STRING;
2626
}
27+
28+
unsigned GetVersionMajor()
29+
{
30+
return AWS_SDK_VERSION_MAJOR;
31+
}
32+
33+
unsigned GetVersionMinor()
34+
{
35+
return AWS_SDK_VERSION_MINOR;
36+
}
37+
38+
unsigned GetVersionPatch()
39+
{
40+
return AWS_SDK_VERSION_PATCH;
41+
}
2742
} //namespace Version
2843
} //namespace Aws
2944

0 commit comments

Comments
 (0)