Skip to content

Commit 90b8584

Browse files
authored
CMake: improve build scripts (#6331)
* make wolfssl compile with Mingw-w64 * cmake: CMAKE_SYSTEM_PROCESSOR is AMD64 on Windows * cmake: use target_compile_definitions instead of add_definitions * cmake: change default value of WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT to ON * cmake: link crypt32.lib on Windows * cmake: export wolfssl * move Config.cmake.in to cmake directory * revert changes to .gitignore * add Config.cmake.in to include.am
1 parent 2bb3ade commit 90b8584

6 files changed

Lines changed: 49 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ctaocrypt/src/src/
1010
*.cache
1111
.dirstamp
1212
*.user
13-
configure
13+
configure
1414
config.*
1515
!cmake/config.in
1616
*Debug/

CMakeLists.txt

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ endif()
548548

549549
# SHA224
550550
set(SHA224_DEFAULT "no")
551-
if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
551+
if(("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64") OR
552552
("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
553553
if(NOT WOLFSSL_AFALG AND NOT WOLFSSL_DEVCRYPTO AND
554554
(NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2")))
@@ -562,7 +562,7 @@ add_option("WOLFSSL_SHA224"
562562

563563
# SHA3
564564
set(SHA3_DEFAULT "no")
565-
if(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") OR
565+
if(("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64") OR
566566
("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
567567
if(NOT WOLFSSL_FIPS OR ("${FIPS_VERSION}" STREQUAL "v2"))
568568
set(SHA3_DEFAULT "yes")
@@ -1048,7 +1048,7 @@ endif()
10481048

10491049
# Base64
10501050
set(BASE64_ENCODE_DEFAULT "no")
1051-
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
1051+
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64")
10521052
set(BASE64_ENCODE_DEFAULT "yes")
10531053
endif()
10541054

@@ -1526,15 +1526,15 @@ if(WOLFSSL_FAST_MATH)
15261526
set(WOLFSSL_SLOWMATH "no")
15271527
endif()
15281528

1529-
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
1529+
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64")
15301530
# Have settings.h set FP_MAX_BITS higher if user didn't set directly
15311531
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
15321532
endif()
15331533
endif()
15341534

15351535
# TODO: - Fast huge math
15361536

1537-
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
1537+
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64|AMD64")
15381538
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_X86_64_BUILD")
15391539
endif()
15401540

@@ -1853,10 +1853,6 @@ if(WOLFSSL_USER_SETTINGS_ASM)
18531853
endif()
18541854
endif()
18551855

1856-
# TODO: Applying definitions to everything like this, rather than
1857-
# individual targets, is discouraged in CMake.
1858-
add_definitions(${WOLFSSL_DEFINITIONS})
1859-
18601856
add_option("WOLFSSL_CONFIG_H"
18611857
"Enable generation of config.h and define HAVE_CONFIG_H (default: enabled)"
18621858
"yes" "yes;no")
@@ -1878,7 +1874,7 @@ message("Generating user options header...")
18781874
if (${CMAKE_DISABLE_SOURCE_CHANGES})
18791875
set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "${CMAKE_DISABLE_SOURCE_CHANGES}")
18801876
else()
1881-
set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "no")
1877+
set(WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT "yes")
18821878
endif()
18831879
add_option("WOLFSSL_BUILD_OUT_OF_TREE"
18841880
"Don't generate files in the source tree (default: ${WOLFSSL_BUILD_OUT_OF_TREE_DEFAULT})"
@@ -1940,7 +1936,13 @@ set(LIB_SOURCES "")
19401936
# Corresponds to the instances of "src_libwolfssl_la_SOURCES += ..."
19411937
# in the *.am files.
19421938
generate_lib_src_list("${LIB_SOURCES}")
1943-
add_library(wolfssl ${LIB_SOURCES})
1939+
if(BUILD_SHARED_LIBS)
1940+
add_library(wolfssl SHARED ${LIB_SOURCES})
1941+
else()
1942+
add_library(wolfssl STATIC ${LIB_SOURCES})
1943+
endif()
1944+
1945+
add_library(wolfssl::wolfssl ALIAS wolfssl)
19441946

19451947
set_target_properties(wolfssl
19461948
PROPERTIES
@@ -1952,6 +1954,7 @@ target_compile_definitions(wolfssl PRIVATE "BUILDING_WOLFSSL")
19521954
if(${BUILD_SHARED_LIBS})
19531955
target_compile_definitions(wolfssl PUBLIC "WOLFSSL_DLL")
19541956
endif()
1957+
target_compile_definitions(wolfssl PUBLIC ${WOLFSSL_DEFINITIONS})
19551958

19561959
####################################################
19571960
# Include Directories
@@ -1974,7 +1977,7 @@ target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS})
19741977
if(WIN32)
19751978
# For Windows link ws2_32
19761979
target_link_libraries(wolfssl PUBLIC
1977-
$<$<PLATFORM_ID:Windows>:ws2_32>)
1980+
$<$<PLATFORM_ID:Windows>:ws2_32 crypt32>)
19781981
elseif(APPLE)
19791982
if(WOLFSSL_SYS_CA_CERTS)
19801983
target_link_libraries(wolfssl PUBLIC
@@ -2295,7 +2298,8 @@ install(FILES
22952298
# Install the export set
22962299
install(EXPORT wolfssl-targets
22972300
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
2298-
FILE wolfssl-config.cmake)
2301+
FILE wolfssl-targets.cmake
2302+
NAMESPACE wolfssl::)
22992303

23002304
# TODO: Distro build + rules for what to include in the distro.
23012305
# See various include.am files.
@@ -2309,3 +2313,28 @@ set(VERSION ${PROJECT_VERSION})
23092313
configure_file(support/wolfssl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc @ONLY)
23102314
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc
23112315
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
2316+
2317+
include(CMakePackageConfigHelpers)
2318+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
2319+
"${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config.cmake"
2320+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl"
2321+
NO_SET_AND_CHECK_MACRO
2322+
NO_CHECK_REQUIRED_COMPONENTS_MACRO
2323+
)
2324+
2325+
export(EXPORT wolfssl-targets
2326+
FILE "${CMAKE_CURRENT_BINARY_DIR}/wolfssl-targets.cmake"
2327+
NAMESPACE wolfssl::
2328+
)
2329+
2330+
write_basic_package_version_file(
2331+
"${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config-version.cmake"
2332+
VERSION "${wolfssl_VERSION_MAJOR}.${wolfssl_VERSION_MINOR}"
2333+
COMPATIBILITY AnyNewerVersion
2334+
)
2335+
2336+
install(FILES
2337+
${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config.cmake
2338+
${CMAKE_CURRENT_BINARY_DIR}/wolfssl-config-version.cmake
2339+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfssl
2340+
)

cmake/Config.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@PACKAGE_INIT@
2+
3+
include ( "${CMAKE_CURRENT_LIST_DIR}/wolfssl-targets.cmake" )

cmake/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
EXTRA_DIST += cmake/Config.cmake.in
12
EXTRA_DIST += cmake/config.in
23
EXTRA_DIST += cmake/functions.cmake
34
EXTRA_DIST += cmake/modules/FindOQS.cmake

wolfssl/wolfcrypt/sp_int.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ extern "C" {
234234
#ifndef SP_WORD_SIZE
235235
#ifdef NO_64BIT
236236
#define SP_WORD_SIZE 16
237-
#elif !defined(HAVE___UINT128_T)
237+
#elif !defined(HAVE___UINT128_T) || defined(_WIN32)
238238
#define SP_WORD_SIZE 32
239239
#else
240240
#define SP_WORD_SIZE 64

wolfssl/wolfcrypt/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ decouple library dependencies with standard string, memory and so on.
141141
#define WC_STRINGIFY(str) _WC_STRINGIFY_L2(str)
142142

143143
/* try to set SIZEOF_LONG or SIZEOF_LONG_LONG if user didn't */
144-
#if defined(_MSC_VER) || defined(HAVE_LIMITS_H)
144+
#if defined(_WIN32) || defined(HAVE_LIMITS_H)
145145
/* make sure both SIZEOF_LONG_LONG and SIZEOF_LONG are set,
146146
* otherwise causes issues with CTC_SETTINGS */
147147
#if !defined(SIZEOF_LONG_LONG) || !defined(SIZEOF_LONG)

0 commit comments

Comments
 (0)