diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cab5f4f4..048f1eec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,35 +84,36 @@ if(BUILD_DEPS) if(UNIX AND NOT APPLE AND NOT BYO_CRYPTO) if(NOT USE_OPENSSL) - set(DISABLE_PERL ON CACHE BOOL "Disable Perl for AWS-LC.") - set(DISABLE_GO ON CACHE BOOL "Disable Go for AWS-LC.") - set(BUILD_LIBSSL OFF CACHE BOOL "Build libssl for AWS-LC.") + include(AwsPrebuildDependency) - # temporarily disable certain warnings as errors for the aws-lc build - set(OLD_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + set(AWSLC_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + # temporarily disable certain warnings as errors for the aws-lc build if(NOT MSVC) check_c_compiler_flag(-Wno-stringop-overflow HAS_WNO_STRINGOP_OVERFLOW) if(HAS_WNO_STRINGOP_OVERFLOW) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-overflow") + set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-stringop-overflow") endif() check_c_compiler_flag(-Wno-array-parameter HAS_WNO_ARRAY_PARAMETER) if(HAS_WNO_ARRAY_PARAMETER) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-parameter") + set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-array-parameter") endif() endif() - add_subdirectory(crt/aws-lc) - - # restore previous build flags - set(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}") - - set(SEARCH_LIBCRYPTO OFF CACHE BOOL "Let S2N use libcrypto from AWS-LC.") - else() - set(SEARCH_LIBCRYPTO ON CACHE BOOL "Let S2N search libcrypto in the system.") + # s2n-tls uses libcrypto during its configuration, so we need to prebuild aws-lc. + prebuild_dependency( + DEPENDENCY_NAME AWSLC + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/crt/aws-lc + CMAKE_ARGUMENTS + -DDISABLE_GO=ON + -DDISABLE_PERL=ON + -DBUILD_LIBSSL=OFF + -DBUILD_TESTING=OFF + -DCMAKE_C_FLAGS=${AWSLC_CMAKE_C_FLAGS} + ) endif() set(UNSAFE_TREAT_WARNINGS_AS_ERRORS OFF CACHE BOOL "Disable warnings-as-errors when building S2N")