|
1 |
| -# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 |
| -# This file is licensed under the Apache License, Version 2.0 (the "License"). |
3 |
| -# You may not use this file except in compliance with the License. A copy of |
4 |
| -# the License is located at |
5 |
| -# http://aws.amazon.com/apache2.0/ |
6 |
| -# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
7 |
| -# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
8 |
| -# specific language governing permissions and limitations under the License. |
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
9 | 3 |
|
10 | 4 | # Set the minimum required version of CMake for this project.
|
11 | 5 | cmake_minimum_required(VERSION 3.8)
|
12 | 6 |
|
| 7 | +set(SERVICE_NAME sns) |
| 8 | +set(SERVICE_COMPONENTS sns) |
| 9 | + |
13 | 10 | # Set this project's name.
|
14 |
| -project("sns-examples") |
| 11 | +project("${SERVICE_NAME}-examples") |
15 | 12 |
|
16 | 13 | # Set the C++ standard to use to build this target.
|
17 | 14 | set(CMAKE_CXX_STANDARD 11)
|
18 | 15 |
|
19 |
| -# Enable CTest for testing these code examples. |
20 |
| -include(CTest) |
21 |
| - |
22 | 16 | # Build shared libraries by default.
|
23 |
| -if(NOT BUILD_SHARED_LIBS) |
24 |
| - set(BUILD_SHARED_LIBS ON) |
25 |
| -endif() |
| 17 | +set(BUILD_SHARED_LIBS ON) |
26 | 18 |
|
27 |
| -list(APPEND CMAKE_PREFIX_PATH "C:\\Program Files (x86)\\aws-cpp-sdk-all\\lib\\cmake") |
28 |
| -#Set the location of where Windows can find the installed libraries of the SDK. |
29 |
| -if(MSVC) |
| 19 | +# Set the location of where Windows can find the installed libraries of the SDK. |
| 20 | +if (MSVC) |
30 | 21 | string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
|
31 | 22 | list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
|
32 |
| -endif() |
| 23 | +endif () |
33 | 24 |
|
34 |
| -# Locate the aws sdk for c++ package. |
35 |
| -find_package(AWSSDK REQUIRED COMPONENTS sns) |
| 25 | +# Find the AWS SDK for C++ package. |
| 26 | +find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS}) |
36 | 27 |
|
37 |
| -# If the compiler is some version of Microsoft Visual C++, |
| 28 | +# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++, |
38 | 29 | # and building as shared libraries, then dynamically link to those shared libraries.
|
39 |
| -if(MSVC AND BUILD_SHARED_LIBS) |
40 |
| - add_definitions(-DUSE_IMPORT_EXPORT) |
| 30 | +if (MSVC) |
| 31 | + set(CMAKE_BUILD_TYPE Debug) # Explicitly setting CMAKE_BUILD_TYPE is necessary in Windows to copy DLLs. |
| 32 | + |
| 33 | + list(APPEND SERVICE_LIST ${SERVICE_COMPONENTS}) |
| 34 | + |
41 | 35 | # Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
|
42 |
| - list(APPEND SERVICE_LIST sns) |
43 |
| - |
44 |
| - #For IDE's like Xcode and Visual Studio this line will be ignored because Release/Debug |
45 |
| - # is switched internally, but this is necessary for non-IDE builds. |
46 |
| - set(CMAKE_BUILD_TYPE Debug) #TODO: Set to your build type |
47 |
| - |
48 |
| - #TODO:Choose appropriate one of the following two lines, you want to copy to the same folder where your executables are. |
49 |
| - AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) #Choose this line if your executables are in /build/Debug |
50 |
| - #AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}) #Choose this line for Visual Studio and possibly other IDEs |
51 |
| - |
52 |
| - message(STATUS ">>CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}") |
53 |
| - message(STATUS ">>CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") |
54 |
| - message(STATUS ">>EXECUTABLE_OUTPUT_PATH : ${EXECUTABLE_OUTPUT_PATH}") |
55 |
| -endif() |
56 |
| - |
57 |
| - |
58 |
| -#set(EXAMPLES "") |
59 |
| -#list(APPEND EXAMPLES "create_topic") |
60 |
| -#list(APPEND EXAMPLES "delete_topic") |
61 |
| -#list(APPEND EXAMPLES "get_sms_type") |
62 |
| -#list(APPEND EXAMPLES "get_topic_attributes") |
63 |
| -#list(APPEND EXAMPLES "list_subscriptions") |
64 |
| -#list(APPEND EXAMPLES "list_topics") |
65 |
| -#list(APPEND EXAMPLES "publish_sms") |
66 |
| -#list(APPEND EXAMPLES "publish_to_topic") |
67 |
| -#list(APPEND EXAMPLES "set_sms_type") |
68 |
| -#list(APPEND EXAMPLES "subscribe_app") |
69 |
| -#list(APPEND EXAMPLES "subscribe_email") |
70 |
| -#list(APPEND EXAMPLES "subscribe_lambda") |
71 |
| -#list(APPEND EXAMPLES "unsubscribe") |
72 |
| - |
73 |
| -# Add the code example-specific header files. (none-currently, placeholder) |
74 |
| -file(GLOB AWSDOC_HEADERS |
75 |
| - "include/awsdoc/ex/*.h" |
76 |
| -) |
77 |
| - |
78 |
| -# Add the code example-specific source files. |
79 |
| -file(GLOB AWSDOC_SOURCE |
80 |
| - "*.cpp" |
81 |
| -) |
82 |
| - |
83 |
| -# Check whether the target system is Windows, including Win64. |
84 |
| -if(WIN32) |
85 |
| - # Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++. |
86 |
| - if(MSVC) |
87 |
| - source_group("Header Files\\awsdoc\\ex" FILES ${AWSDOC_HEADERS}) |
88 |
| - source_group("Source Files" FILES ${AWSDOC_SOURCE}) |
89 |
| - endif(MSVC) |
90 |
| -endif() |
91 |
| - |
92 |
| -foreach(file ${AWSDOC_SOURCE}) |
| 36 | + AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) |
| 37 | +endif () |
| 38 | + |
| 39 | +# AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example, |
| 40 | +# you can limit files to one action. |
| 41 | +if (NOT DEFINED AWSDOC_SOURCE) |
| 42 | + file(GLOB AWSDOC_SOURCE |
| 43 | + "*.cpp" |
| 44 | + ) |
| 45 | +endif () |
| 46 | + |
| 47 | +foreach (file ${AWSDOC_SOURCE}) |
93 | 48 | get_filename_component(EXAMPLE ${file} NAME_WE)
|
94 | 49 |
|
95 | 50 | # Build the code example executables.
|
96 | 51 | set(EXAMPLE_EXE run_${EXAMPLE})
|
97 | 52 |
|
98 |
| - add_executable(${EXAMPLE_EXE} ${AWSDOC_HEADERS} ${file}) |
| 53 | + add_executable(${EXAMPLE_EXE} ${file}) |
99 | 54 |
|
100 |
| - if(MSVC AND BUILD_SHARED_LIBS) |
101 |
| - target_compile_definitions(${EXAMPLE_EXE} PUBLIC "USE_IMPORT_EXPORT") |
102 |
| - target_compile_definitions(${EXAMPLE_EXE} PRIVATE "AWSDOC_EXPORTS") |
103 |
| - endif() |
104 |
| - |
105 |
| - target_include_directories(${EXAMPLE_EXE} PUBLIC |
106 |
| - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
107 |
| - $<INSTALL_INTERFACE:include>) |
108 | 55 | target_link_libraries(${EXAMPLE_EXE} ${AWSSDK_LINK_LIBRARIES}
|
109 |
| - ${AWSSDK_PLATFORM_DEPS}) |
110 |
| - |
111 |
| - if(BUILD_TESTING) |
112 |
| - # Enable testing for this directory and below. |
113 |
| - enable_testing() |
114 |
| - |
115 |
| - # Build the code example libraries. |
116 |
| - set(EXAMPLE_LIB ${EXAMPLE}) |
117 |
| - |
118 |
| - add_library(${EXAMPLE_LIB} ${AWSDOC_HEADERS} ${file} ) |
119 |
| - |
120 |
| - if(MSVC AND BUILD_SHARED_LIBS) |
121 |
| - target_compile_definitions(${EXAMPLE_LIB} PUBLIC "USE_IMPORT_EXPORT") |
122 |
| - target_compile_definitions(${EXAMPLE_LIB} PRIVATE "AWSDOC_EXPORTS") |
123 |
| - endif() |
124 |
| - |
125 |
| - target_include_directories(${EXAMPLE_LIB} PUBLIC |
126 |
| - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
127 |
| - $<INSTALL_INTERFACE:include>) |
128 |
| - target_link_libraries(${EXAMPLE_LIB} ${AWSSDK_LINK_LIBRARIES} |
129 | 56 | ${AWSSDK_PLATFORM_DEPS})
|
130 | 57 |
|
131 |
| - # Build the code example unit tests. |
132 |
| - set(EXAMPLE_TEST test_${EXAMPLE}) |
133 |
| - set(EXAMPLE_TEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_${EXAMPLE}.cpp) |
134 |
| - |
135 |
| - if(EXISTS ${EXAMPLE_TEST_FILE}) |
136 |
| - add_executable(${EXAMPLE_TEST} ${EXAMPLE_TEST_FILE} ) |
137 |
| - |
138 |
| - target_include_directories(${EXAMPLE_TEST} PUBLIC |
139 |
| - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
140 |
| - $<INSTALL_INTERFACE:include>) |
141 |
| - target_link_libraries(${EXAMPLE_TEST} ${EXAMPLE_LIB} ) |
142 |
| - add_test(${EXAMPLE_TEST} ${EXAMPLE_TEST}) |
143 |
| - endif() |
144 |
| - |
145 |
| - endif() |
146 |
| -endforeach() |
147 |
| - |
| 58 | +endforeach () |
148 | 59 |
|
149 | 60 |
|
| 61 | +if (BUILD_TESTS) |
| 62 | + add_subdirectory(tests) |
| 63 | +endif () |
150 | 64 |
|
151 |
| -# The executables to build. |
152 |
| -foreach(EXAMPLE IN LISTS EXAMPLES) |
153 |
| - add_executable(${EXAMPLE} ${EXAMPLE}.cpp) |
154 |
| - target_link_libraries(${EXAMPLE} ${AWSSDK_LINK_LIBRARIES}) |
155 |
| -endforeach() |
0 commit comments