Skip to content

Commit 4fb0ff4

Browse files
authored
Add USE_EXTERNAL_DEPS_SOURCES cmake option (#714)
1 parent 5b1ffa8 commit 4fb0ff4

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ project(aws-iot-device-sdk-cpp-v2
1111
include(CTest)
1212

1313
option(BUILD_DEPS "Builds aws common runtime dependencies as part of build. Turn off if you want to control your dependency chain." ON)
14+
option(USE_EXTERNAL_DEPS_SOURCES "Use dependencies provided by add_subdirectory command" OFF)
1415
option(BUILD_SAMPLES "(DEPRECATED) Build samples as part of the build" OFF)
1516

1617
if (DEFINED CMAKE_PREFIX_PATH)
@@ -57,6 +58,10 @@ else()
5758
endif()
5859

5960
if (BUILD_DEPS)
61+
if (USE_EXTERNAL_DEPS_SOURCES)
62+
message(FATAL_ERROR "USE_EXTERNAL_DEPS_SOURCES option should be used with BUILD_DEPS set to OFF")
63+
endif()
64+
6065
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/crt/aws-crt-cpp/crt/aws-c-common/cmake")
6166

6267
include(AwsFindPackage)
@@ -70,8 +75,27 @@ if (BUILD_DEPS)
7075
endif ()
7176
set(BUILD_TESTING ${BUILD_TESTING_PREV})
7277
else()
78+
if (USE_EXTERNAL_DEPS_SOURCES)
79+
function(validate_deps_sources dep_name)
80+
if (NOT ${dep_name}_SOURCE_DIR)
81+
message(FATAL_ERROR "USE_EXTERNAL_DEPS_SOURCES option is set, but ${dep_name} project is not configured."
82+
" ${dep_name} must be added using add_subdirectory command (or one of the higher-level commands that"
83+
" uses add_subdirectory, like FetchContent)")
84+
endif()
85+
endfunction()
86+
87+
validate_deps_sources(aws-crt-cpp)
88+
validate_deps_sources(aws-c-iot)
89+
validate_deps_sources(aws-c-common)
90+
91+
list(APPEND CMAKE_MODULE_PATH "${aws-c-common_SOURCE_DIR}/cmake")
92+
93+
set(IN_SOURCE_BUILD ON)
94+
else()
95+
set(IN_SOURCE_BUILD OFF)
96+
endif()
97+
7398
include(AwsFindPackage)
74-
set(IN_SOURCE_BUILD OFF)
7599
endif()
76100

77101
aws_use_package(aws-crt-cpp)

0 commit comments

Comments
 (0)