@@ -19,6 +19,26 @@ set(REPORTED_PKGCONFIG_VERSION "1.1.1")
1919# Defer enabling C and CXX languages.
2020project (AWSLC VERSION "${SOFTWARE_VERSION} " LANGUAGES NONE )
2121
22+ if (DEFINED ENABLE_PRE_SONAME_BUILD)
23+ message (WARNING "ENABLE_PRE_SONAME_BUILD option will be deprecated in a future release. Please see ENABLE_DIST_PKG and ENABLE_DIST_PKG_OPENSSL_SHIM" )
24+ endif ()
25+
26+ option (BUILD_TESTING "Build all test targets for AWS-LC" ON )
27+ option (BUILD_LIBSSL "Build libssl for AWS-LC" ON )
28+ option (BUILD_TOOL "Build bssl tool for AWS-LC" ON )
29+ option (DISABLE_PERL "Disable Perl for AWS-LC" OFF )
30+ option (DISABLE_GO "Disable Go for AWS-LC" OFF )
31+ # Keeping this flag for now, for compatibility with existing build configs.
32+ option (ENABLE_FIPS_ENTROPY_CPU_JITTER "Enable FIPS entropy source: CPU Jitter" OFF )
33+ option (ENABLE_DATA_INDEPENDENT_TIMING "Enable automatic setting/resetting Data-Independent Timing
34+ (DIT) flag in cryptographic functions. Currently only applicable to Arm64 (except on Windows)" OFF )
35+ option (ENABLE_PRE_SONAME_BUILD "Build AWS-LC without SONAME configuration for shared library builds" ON )
36+ option (ENABLE_SOURCE_MODIFICATION "Allow the build to update files in the source directory. This is typically done to update versioning." ON )
37+ option (DISABLE_CPU_JITTER_ENTROPY "Disable usage of CPU Jitter Entropy as an entropy source. This option cannot be used with the FIPS build. With this configuration, randomness generation might not use two independent entropy sources." OFF )
38+ option (GENERATE_RUST_BINDINGS "Generate Rust bindings using bindgen-cli" OFF )
39+ option (ENABLE_DIST_PKG "Enables a set of packaging that take highest precedence to any other packaging configuration i.e. ENABLE_PRE_SONAME_BUILD" OFF )
40+ option (ENABLE_DIST_PKG_OPENSSL_SHIM "Controls whether the OpenSSL shim components are installed when ENABLE_DIST_PKG is enabled" OFF )
41+
2242if (MSVC )
2343 # On Windows, prefer cl over gcc if both are available. By default most of
2444 # the CMake generators prefer gcc, even on Windows.
@@ -52,6 +72,62 @@ if(POLICY CMP0077)
5272 cmake_policy (SET CMP0077 NEW ) #option does nothing when a normal variable of the same name exists.
5373endif ()
5474
75+ set (RUST_BINDINGS_TARGET_VERSION "1.70" CACHE STRING "Minimum Rust version for generated bindings" )
76+
77+ include (cmake/go.cmake )
78+
79+ if (ENABLE_DIST_PKG_OPENSSL_SHIM AND NOT ENABLE_DIST_PKG)
80+ message (FATAL_ERROR "ENABLE_DIST_PKG_OPENSSL_SHIM requires ENABLE_DIST_PKG to be enabled and will be ignored." )
81+ endif ()
82+
83+ if (ENABLE_DIST_PKG)
84+ if (NOT UNIX OR APPLE )
85+ message (FATAL_ERROR "ENABLE_DIST_PKG is not supported on macOS or Windows and will be ignored." )
86+ else ()
87+ set (SET_LIB_SONAME 1)
88+ set (COHABITANT_HEADERS 1)
89+ if (ENABLE_DIST_PKG_OPENSSL_SHIM)
90+ set (INSTALL_OPENSSL_SHIM 1)
91+ else ()
92+ set (INSTALL_OPENSSL_SHIM 0)
93+ endif ()
94+ endif ()
95+ elseif (NOT ENABLE_PRE_SONAME_BUILD AND BUILD_SHARED_LIBS AND UNIX AND NOT APPLE )
96+ set (SET_LIB_SONAME 1)
97+ set (COHABITANT_HEADERS 0)
98+ set (INSTALL_OPENSSL_SHIM 1)
99+ else ()
100+ set (SET_LIB_SONAME 0)
101+ set (COHABITANT_HEADERS 0)
102+ set (INSTALL_OPENSSL_SHIM 1)
103+ endif ()
104+
105+ message (STATUS "SET_LIB_SONAME: ${SET_LIB_SONAME} " )
106+ message (STATUS "COHABITANT_HEADERS: ${COHABITANT_HEADERS} " )
107+ message (STATUS "INSTALL_OPENSSL_SHIM: ${INSTALL_OPENSSL_SHIM} " )
108+
109+ if (SET_LIB_SONAME)
110+ set (CRYPTO_LIB_NAME "${CRYPTO_LIB_NAME} -${SOFTWARE_NAME} " )
111+ set (SSL_LIB_NAME "${SSL_LIB_NAME} -${SOFTWARE_NAME} " )
112+ endif ()
113+
114+ enable_language (C )
115+
116+ if (NOT WIN32 AND NOT APPLE )
117+ include (GNUInstallDirs )
118+ elseif (NOT DEFINED CMAKE_INSTALL_LIBDIR)
119+ set (CMAKE_INSTALL_LIBDIR "lib" )
120+ set (CMAKE_INSTALL_INCLUDEDIR "include" )
121+ set (CMAKE_INSTALL_BINDIR "bin" )
122+ endif ()
123+
124+ # Set the install include directory based on whether a prefix subdirectory is desired
125+ if (COHABITANT_HEADERS)
126+ set (AWSLC_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR} /aws-lc" )
127+ else ()
128+ set (AWSLC_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR} " )
129+ endif ()
130+
55131function (target_add_awslc_include_paths )
56132 set (options EXCLUDE_PREFIX_HEADERS)
57133 set (oneValueArgs TARGET SCOPE)
@@ -81,39 +157,9 @@ function(target_add_awslc_include_paths)
81157 target_include_directories (${arg_TARGET} BEFORE ${arg_SCOPE}
82158 $<$<BOOL :${INCLUDE_PREFIX_HEADERS} >:$<BUILD_INTERFACE :${AWSLC_BINARY_DIR} /symbol_prefix_include >>
83159 $<BUILD_INTERFACE :${AWSLC_SOURCE_DIR} /include >
84- $<INSTALL_INTERFACE :include >)
160+ $<INSTALL_INTERFACE :${AWSLC_INSTALL_INCLUDEDIR} >)
85161endfunction ()
86162
87- option (BUILD_TESTING "Build all test targets for AWS-LC" ON )
88- option (BUILD_LIBSSL "Build libssl for AWS-LC" ON )
89- option (BUILD_TOOL "Build bssl tool for AWS-LC" ON )
90- option (DISABLE_PERL "Disable Perl for AWS-LC" OFF )
91- option (DISABLE_GO "Disable Go for AWS-LC" OFF )
92- # Keeping this flag for now, for compatibility with existing build configs.
93- option (ENABLE_FIPS_ENTROPY_CPU_JITTER "Enable FIPS entropy source: CPU Jitter" OFF )
94- option (ENABLE_DATA_INDEPENDENT_TIMING "Enable automatic setting/resetting Data-Independent Timing
95- (DIT) flag in cryptographic functions. Currently only applicable to Arm64 (except on Windows)" OFF )
96- option (ENABLE_PRE_SONAME_BUILD "Build AWS-LC without SONAME configuration for shared library builds" ON )
97- option (ENABLE_SOURCE_MODIFICATION "Allow the build to update files in the source directory. This is typically done to update versioning." ON )
98- option (DISABLE_CPU_JITTER_ENTROPY "Disable usage of CPU Jitter Entropy as an entropy source. This option cannot be used with the FIPS build. With this configuration, randomness generation might not use two independent entropy sources." OFF )
99- option (GENERATE_RUST_BINDINGS "Generate Rust bindings using bindgen-cli" OFF )
100- set (RUST_BINDINGS_TARGET_VERSION "1.70" CACHE STRING "Minimum Rust version for generated bindings" )
101-
102- include (cmake/go.cmake )
103-
104- if (NOT ENABLE_PRE_SONAME_BUILD AND BUILD_SHARED_LIBS AND UNIX AND NOT APPLE )
105- set (PERFORM_SONAME_BUILD 1)
106- set (CRYPTO_LIB_NAME "${CRYPTO_LIB_NAME} -${SOFTWARE_NAME} " )
107- set (SSL_LIB_NAME "${SSL_LIB_NAME} -${SOFTWARE_NAME} " )
108- else ()
109- set (PERFORM_SONAME_BUILD 0)
110- endif ()
111-
112- message (STATUS "ENABLE_PRE_SONAME_BUILD: ${ENABLE_PRE_SONAME_BUILD} " )
113- message (STATUS "PERFORM_SONAME_BUILD: ${PERFORM_SONAME_BUILD} " )
114-
115- enable_language (C )
116-
117163# Validate Rust bindings prerequisites
118164if (GENERATE_RUST_BINDINGS)
119165 find_program (BINDGEN_EXECUTABLE NAMES bindgen )
@@ -168,8 +214,6 @@ else()
168214 message (STATUS "Entropy source configured: Dynamic (default: CPU Jitter)" )
169215endif ()
170216
171-
172-
173217if (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" )
174218 # OpenBSD by defaults links with --execute-only this is problematic for two reasons:
175219 # 1. The FIPS shared and static builds need to compute the module signature hash by reading the .text section
@@ -254,16 +298,8 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
254298 set (GCC 1)
255299endif ()
256300
257- if (NOT WIN32 AND NOT APPLE )
258- include (GNUInstallDirs )
259- elseif (NOT DEFINED CMAKE_INSTALL_LIBDIR)
260- set (CMAKE_INSTALL_LIBDIR "lib" )
261- set (CMAKE_INSTALL_INCLUDEDIR "include" )
262- set (CMAKE_INSTALL_BINDIR "bin" )
263- endif ()
264-
265301install (DIRECTORY include/openssl
266- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR }
302+ DESTINATION ${AWSLC_INSTALL_INCLUDEDIR }
267303 COMPONENT Development
268304 PATTERN boringssl_prefix_symbols.h EXCLUDE
269305 PATTERN boringssl_prefix_symbols_asm.h EXCLUDE
@@ -364,7 +400,7 @@ if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS AND GO_EXECUTABLE)
364400 symbol_prefix_include/openssl/boringssl_prefix_symbols_nasm.inc )
365401
366402 install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /symbol_prefix_include/openssl
367- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR }
403+ DESTINATION ${AWSLC_INSTALL_INCLUDEDIR }
368404 COMPONENT Development
369405 )
370406elseif (BORINGSSL_PREFIX AND BORINGSSL_PREFIX_HEADERS)
@@ -384,7 +420,7 @@ elseif(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_HEADERS)
384420 add_custom_target (boringssl_prefix_symbols )
385421
386422 install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /symbol_prefix_include/openssl
387- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR }
423+ DESTINATION ${AWSLC_INSTALL_INCLUDEDIR }
388424 COMPONENT Development
389425 )
390426elseif (BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS AND NOT GO_EXECUTABLE)
@@ -398,7 +434,7 @@ else()
398434 add_custom_target (boringssl_prefix_symbols )
399435
400436 install (DIRECTORY include/openssl
401- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR }
437+ DESTINATION ${AWSLC_INSTALL_INCLUDEDIR }
402438 COMPONENT Development
403439 FILES_MATCHING
404440 PATTERN boringssl_prefix_symbols.h
@@ -1233,6 +1269,26 @@ if(NOT DISABLE_CPU_JITTER_ENTROPY)
12331269 add_subdirectory (third_party/jitterentropy )
12341270endif ()
12351271
1272+ # CMAKE_SYSTEM_NAME is "Generic" for embedded OSes:
1273+ # https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html#toolchain-files
1274+ #
1275+ # For now we assume embedded OSes do not have threads. Additionally, the Threads
1276+ # package does not work with Android, but Android does not require any extra
1277+ # parameters to link pthreads. Emscripten provides its own pthread implementation
1278+ # via Web Workers and SharedArrayBuffer, configured through compiler flags.
1279+ if (NOT CMAKE_SYSTEM_NAME MATCHES "^(Generic|Android|Emscripten)$" )
1280+ find_package (Threads REQUIRED )
1281+ set (AWSLC_LINK_THREADS TRUE )
1282+ # CMAKE_THREAD_LIBS_INIT contains the actual linker flags (e.g., -lpthread)
1283+ # set by find_package(Threads). Use this for pkgconfig instead of the
1284+ # imported target name.
1285+ set (PKGCONFIG_LIBS_PRIVATE "${CMAKE_THREAD_LIBS_INIT} " )
1286+ else ()
1287+ set (AWSLC_LINK_THREADS FALSE )
1288+ set (PKGCONFIG_LIBS_PRIVATE "" )
1289+ endif ()
1290+
1291+
12361292add_subdirectory (crypto )
12371293if (BUILD_LIBSSL)
12381294 add_subdirectory (ssl )
@@ -1460,21 +1516,23 @@ if(NOT MSVC AND NOT CLANG AND NOT GCC)
14601516 message (STATUS "Alternative compiler '${CMAKE_C_COMPILER_ID} ' detected. Not all flags may be set, check final options with 'cmake --build . -- VERBOSE=1'" )
14611517endif ()
14621518
1463- # AWS-LC may be installed in a non-standard prefix. If OpenSSL exists in the standard path,
1464- # the downstream integration may build with the system's OpenSSL version instead.
1465- # Consider adjusting the PKG_CONFIG_PATH environment to get around this.
1466- file (GLOB OPENSSL_PKGCONFIGS "pkgconfig/*.pc.in" )
1467-
14681519include (cmake/JoinPaths.cmake )
1469- join_paths (libdir_for_pc_file "\$ {prefix}" "${CMAKE_INSTALL_LIBDIR} " )
1470- join_paths (includedir_for_pc_file "\$ {prefix}" "${CMAKE_INSTALL_INCLUDEDIR} " )
1471-
1472- foreach (in_file ${OPENSSL_PKGCONFIGS} )
1473- file (RELATIVE_PATH in_file ${AWSLC_SOURCE_DIR} ${in_file} )
1474- string (REPLACE ".in" "" pc_file ${in_file} )
1475- configure_file (${in_file} ${CMAKE_CURRENT_BINARY_DIR} /${pc_file} @ONLY )
1476- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${pc_file} DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig)
1477- endforeach ()
1520+ join_paths (LIBDIR_FOR_PC_FILE "\$ {prefix}" "${CMAKE_INSTALL_LIBDIR} " )
1521+ join_paths (INCLUDEDIR_FOR_PC_FILE "\$ {prefix}" "${AWSLC_INSTALL_INCLUDEDIR} " )
1522+
1523+ function (install_pkgconfig_file )
1524+ set (options "" )
1525+ set (oneValueArgs TEMPLATE DEST)
1526+ set (multiValueArgs)
1527+ if (CMAKE_VERSION VERSION_LESS "3.7" )
1528+ cmake_parse_arguments (arg "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
1529+ else ()
1530+ cmake_parse_arguments (PARSE_ARGV 0 arg "${options} " "${oneValueArgs} " "${multiValueArgs} " )
1531+ endif ()
1532+
1533+ configure_file (pkgconfig/${arg_TEMPLATE} ${CMAKE_CURRENT_BINARY_DIR} /pkgconfig/${arg_DEST} @ONLY )
1534+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /pkgconfig/${arg_DEST} DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig)
1535+ endfunction ()
14781536
14791537if (ENABLE_SOURCE_MODIFICATION)
14801538 configure_file (include /openssl/base.h.in ${AWSLC_SOURCE_DIR} /include/openssl/base.h @ONLY )
@@ -1483,3 +1541,42 @@ if(ENABLE_SOURCE_MODIFICATION)
14831541 configure_file (util/check-linkage.sh.in check-linkage.sh @ONLY )
14841542 endif ()
14851543endif ()
1544+
1545+ install_pkgconfig_file (TEMPLATE product.pc.in DEST aws-lc.pc )
1546+ install_pkgconfig_file (TEMPLATE libcrypto.pc.in DEST lib${CRYPTO_LIB_NAME}.pc )
1547+ install_pkgconfig_file (TEMPLATE libssl.pc.in DEST lib${SSL_LIB_NAME}.pc )
1548+
1549+ if (INSTALL_OPENSSL_SHIM)
1550+ install_pkgconfig_file (TEMPLATE product.pc.in DEST openssl.pc )
1551+
1552+ # Create OpenSSL compatibility symlinks
1553+ if (BUILD_SHARED_LIBS )
1554+ if (SET_LIB_SONAME)
1555+ # When SONAME build is enabled, libraries have -awslc suffix
1556+ install (CODE "
1557+ execute_process(COMMAND \$ {CMAKE_COMMAND} -E create_symlink
1558+ lib${CRYPTO_LIB_NAME} .so \"\$ ENV{DESTDIR}\$ {CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} /libcrypto.so\" )
1559+ execute_process(COMMAND \$ {CMAKE_COMMAND} -E create_symlink
1560+ lib${SSL_LIB_NAME} .so \"\$ ENV{DESTDIR}\$ {CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} /libssl.so\" )
1561+ " )
1562+ endif ()
1563+ else ()
1564+ if (SET_LIB_SONAME)
1565+ # When SONAME build is enabled, libraries have -awslc suffix
1566+ install (CODE "
1567+ execute_process(COMMAND \$ {CMAKE_COMMAND} -E create_symlink
1568+ lib${CRYPTO_LIB_NAME} .a \"\$ ENV{DESTDIR}\$ {CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} /libcrypto.a\" )
1569+ execute_process(COMMAND \$ {CMAKE_COMMAND} -E create_symlink
1570+ lib${SSL_LIB_NAME} .a \"\$ ENV{DESTDIR}\$ {CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} /libssl.a\" )
1571+ " COMPONENT Development)
1572+ endif ()
1573+ endif ()
1574+
1575+ if (COHABITANT_HEADERS)
1576+ # Always create the include directory symlink for OpenSSL compatibility
1577+ install (CODE "
1578+ execute_process(COMMAND \$ {CMAKE_COMMAND} -E create_symlink
1579+ aws-lc/openssl \"\$ ENV{DESTDIR}\$ {CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR} /openssl\" )
1580+ " COMPONENT Development)
1581+ endif ()
1582+ endif ()
0 commit comments