Skip to content

Commit

Permalink
Move to submodules (#91)
Browse files Browse the repository at this point in the history
Moved BUILD_DEPS path to use git submodules.
  • Loading branch information
JonathanHenson authored Jan 9, 2020
1 parent d525412 commit 1f045a1
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 612 deletions.
24 changes: 24 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[submodule "aws-common-runtime/aws-c-common"]
path = aws-common-runtime/aws-c-common
url = https://github.com/awslabs/aws-c-common.git
[submodule "aws-common-runtime/aws-c-io"]
path = aws-common-runtime/aws-c-io
url = https://github.com/awslabs/aws-c-io.git
[submodule "aws-common-runtime/aws-c-compression"]
path = aws-common-runtime/aws-c-compression
url = https://github.com/awslabs/aws-c-compression.git
[submodule "aws-common-runtime/aws-c-cal"]
path = aws-common-runtime/aws-c-cal
url = https://github.com/awslabs/aws-c-cal.git
[submodule "aws-common-runtime/aws-c-auth"]
path = aws-common-runtime/aws-c-auth
url = https://github.com/awslabs/aws-c-auth.git
[submodule "aws-common-runtime/aws-c-http"]
path = aws-common-runtime/aws-c-http
url = https://github.com/awslabs/aws-c-http.git
[submodule "aws-common-runtime/aws-c-mqtt"]
path = aws-common-runtime/aws-c-mqtt
url = https://github.com/awslabs/aws-c-mqtt.git
[submodule "aws-common-runtime/s2n"]
path = aws-common-runtime/s2n
url = https://github.com/awslabs/s2n.git
159 changes: 58 additions & 101 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.1)

project(aws-crt-cpp CXX C)
option(BUILD_DEPS "Builds aws common runtime dependencies as part of build, only do this if you don't want to control your dependency chain." OFF)

include(CTest)

if (DEFINED CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
endif()
Expand All @@ -28,93 +30,44 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()

set(AWS_CRT_CPP_VERSION "v0.6.8")
set(AWS_CRT_CPP_VERSION "v0.7.1")

configure_file(include/aws/crt/Config.h.in ${CMAKE_CURRENT_LIST_DIR}/include/aws/crt/Config.h @ONLY)

if (BUILD_DEPS)
set(AWS_DEPS_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps CACHE STRING "If BUILD_DEPS is on, aws common runtime dependencies build in this directory.")
if (DEFINED CMAKE_INSTALL_PREFIX)
set(AWS_DEPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
else()
set(AWS_DEPS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/install)
endif()
# This is required in order to append /lib/cmake to each element in CMAKE_PREFIX_PATH
set(AWS_MODULE_DIR "/${CMAKE_INSTALL_LIBDIR}/cmake")
string(REPLACE ";" "${AWS_MODULE_DIR};" AWS_MODULE_PATH "${CMAKE_PREFIX_PATH}${AWS_MODULE_DIR}")
# Append that generated list to the module search path
list(APPEND CMAKE_MODULE_PATH ${AWS_MODULE_PATH})

if (NOT DEFINED CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${AWS_DEPS_INSTALL_DIR})
endif()
if (BUILD_DEPS)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/aws-common-runtime/aws-c-common/cmake")

file(MAKE_DIRECTORY ${AWS_DEPS_BUILD_DIR})
if(TARGET_ARCH STREQUAL "ANDROID")
execute_process(
COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
-DTARGET_ARCH=${TARGET_ARCH}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL}
-DANDROID_ABI=${ANDROID_ABI}
-DANDROID_TOOLCHAIN_NAME=${ANDROID_TOOLCHAIN_NAME}
-DANDROID_STANDALONE_TOOLCHAIN=${ANDROID_STANDALONE_TOOLCHAIN}
-DANDROID_STL=${ANDROID_STL}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
${CMAKE_CURRENT_SOURCE_DIR}/aws-common-runtime
WORKING_DIRECTORY ${AWS_DEPS_BUILD_DIR}
)

else()
execute_process(
COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
-DTARGET_ARCH=${TARGET_ARCH}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_CURRENT_BINARY_DIR}/bin
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
${CMAKE_CURRENT_SOURCE_DIR}/aws-common-runtime
WORKING_DIRECTORY ${AWS_DEPS_BUILD_DIR}
RESULT_VARIABLE BUILD_AWSCRT_EXIT_CODE
)
endif()
include(AwsFindPackage)

if (NOT ${BUILD_AWSCRT_EXIT_CODE} EQUAL 0)
message(FATAL_ERROR "Failed to configure aws crt libraries.")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build ${AWS_DEPS_BUILD_DIR} --config ${CMAKE_BUILD_TYPE}
RESULT_VARIABLE BUILD_AWSCRT_EXIT_CODE)
set(IN_SOURCE_BUILD ON)
set(BUILD_TESTING_PREV BUILD_TESTING)
set(BUILD_TESTING OFF)
add_subdirectory(aws-common-runtime/aws-c-common)

if (NOT ${BUILD_AWSCRT_EXIT_CODE} EQUAL 0)
message(FATAL_ERROR "Failed to build aws crt libraries.")
if (UNIX AND NOT APPLE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/aws-common-runtime/s2n/cmake/modules")
find_package(LibCrypto REQUIRED)
add_subdirectory(aws-common-runtime/s2n)
endif()
message(STATUS "AWS Common Runtime is installed at: ${AWS_DEPS_INSTALL_DIR}")

#the following two lines are done in this branch intentionally, don't move it. project() does some magic that
#we don't want happening until we're done with the above code.
list(APPEND CMAKE_PREFIX_PATH "${AWS_DEPS_INSTALL_DIR}")

project(aws-crt-cpp)

add_subdirectory(aws-common-runtime/aws-c-io)
add_subdirectory(aws-common-runtime/aws-c-cal)
add_subdirectory(aws-common-runtime/aws-c-compression)
add_subdirectory(aws-common-runtime/aws-c-http)
add_subdirectory(aws-common-runtime/aws-c-auth)
add_subdirectory(aws-common-runtime/aws-c-mqtt)
set(BUILD_TESTING BUILD_TESTING_PREV)
else()
#the following two lines are done in this branch intentionally, don't move it. project() does some magic that
#we want happening exactly right now.
project(aws-crt-cpp)

include(AwsFindPackage)
set(IN_SOURCE_BUILD OFF)
endif()

# This is required in order to append /lib/cmake to each element in CMAKE_PREFIX_PATH
set(AWS_MODULE_DIR "/${CMAKE_INSTALL_LIBDIR}/cmake")
string(REPLACE ";" "${AWS_MODULE_DIR};" AWS_MODULE_PATH "${CMAKE_PREFIX_PATH}${AWS_MODULE_DIR}")
# Append that generated list to the module search path
list(APPEND CMAKE_MODULE_PATH ${AWS_MODULE_PATH})

include(AwsCFlags)
include(AwsSharedLibSetup)

Expand Down Expand Up @@ -226,38 +179,38 @@ if (WIN32)
endif ()
endif()

add_library(${CMAKE_PROJECT_NAME} ${AWS_CRT_CPP_SRC})
add_library(${PROJECT_NAME} ${AWS_CRT_CPP_SRC})

if (BUILD_SHARED_LIBS)
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC -DAWS_CRT_CPP_USE_IMPORT_EXPORT)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE -DAWS_CRT_CPP_EXPORTS)
target_compile_definitions(${PROJECT_NAME} PUBLIC -DAWS_CRT_CPP_USE_IMPORT_EXPORT)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DAWS_CRT_CPP_EXPORTS)
endif()

set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})

aws_prepare_symbol_visibility_args(${CMAKE_PROJECT_NAME} "AWS_CRT_CPP")
aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_CRT_CPP")

#set warnings
if (MSVC)
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
else ()
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "-DDEBUG_BUILD")
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DDEBUG_BUILD")
endif ()

target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

find_package(aws-c-http REQUIRED)
find_package(aws-c-mqtt REQUIRED)
find_package(aws-c-cal REQUIRED)
find_package(aws-c-auth REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME} AWS::aws-c-auth AWS::aws-c-cal AWS::aws-c-http AWS::aws-c-mqtt)
aws_use_package(aws-c-http)
aws_use_package(aws-c-mqtt)
aws_use_package(aws-c-cal)
aws_use_package(aws-c-auth)
target_link_libraries(${PROJECT_NAME} ${DEP_AWS_LIBS})

install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt" COMPONENT Development)
install(FILES ${AWS_CRT_AUTH_HEADERS} DESTINATION "include/aws/crt/auth" COMPONENT Development)
Expand All @@ -269,8 +222,8 @@ install(FILES ${AWS_CRT_HTTP_HEADERS} DESTINATION "include/aws/crt/http" COMPONE
install(FILES ${AWS_CRT_EXTERNAL_HEADERS} DESTINATION "include/aws/crt/external" COMPONENT Development)

install(
TARGETS ${CMAKE_PROJECT_NAME}
EXPORT ${CMAKE_PROJECT_NAME}-targets
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
Expand All @@ -282,18 +235,22 @@ else()
set (TARGET_DIR "static")
endif()

install(EXPORT "${CMAKE_PROJECT_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${CMAKE_PROJECT_NAME}/cmake/${TARGET_DIR}"
install(EXPORT "${PROJECT_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/${TARGET_DIR}"
NAMESPACE AWS::
COMPONENT Development)

configure_file("cmake/${CMAKE_PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config.cmake"
configure_file("cmake/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
@ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${CMAKE_PROJECT_NAME}/cmake/"
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/"
COMPONENT Development)

enable_testing()
add_subdirectory(tests)
if (NOT CMAKE_CROSSCOMPILING)
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
endif()

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ More protocols and utilities are coming soon, so stay tuned.

## Building

The C99 libraries are already included for your convenience when you specify the `-DBUILD_DEPS=ON` CMake argument.
The C99 libraries are already included for your convenience as submodules. If you would like to have us build them
by default, be sure to either perform a recursive clone `git clone --recursive` or initialize the submodules via.
`git submodule update --init`. Then, to build, specify the `-DBUILD_DEPS=ON` CMake argument.

If you want to manage these dependencies manually (e.g. you're using them in other projects), simply specify
`-DCMAKE_INSTALL_PREFIX` to point to the directory where you have them installed.
`-DCMAKE_PREFIX_PATH` to point to the absolute path where you have them installed.

## Dependencies?

Expand Down
64 changes: 0 additions & 64 deletions aws-common-runtime/CMakeLists.txt

This file was deleted.

1 change: 1 addition & 0 deletions aws-common-runtime/aws-c-auth
Submodule aws-c-auth added at 8281ad
1 change: 1 addition & 0 deletions aws-common-runtime/aws-c-cal
Submodule aws-c-cal added at 5f5627
1 change: 1 addition & 0 deletions aws-common-runtime/aws-c-common
Submodule aws-c-common added at 045024
1 change: 1 addition & 0 deletions aws-common-runtime/aws-c-compression
Submodule aws-c-compression added at 45d6ba
1 change: 1 addition & 0 deletions aws-common-runtime/aws-c-http
Submodule aws-c-http added at 232f33
1 change: 1 addition & 0 deletions aws-common-runtime/aws-c-io
Submodule aws-c-io added at 250484
1 change: 1 addition & 0 deletions aws-common-runtime/aws-c-mqtt
Submodule aws-c-mqtt added at 9895e4
Loading

0 comments on commit 1f045a1

Please sign in to comment.