Skip to content

Commit 690aa2f

Browse files
committed
CMake fixes and improvements
* Minor fixes to the CMakeLists.txt * Add more options to the CMake infrastructure already present in the autoconf infrastructure * An autoconf build now also generates and installs files required to consume the installed wolfssl library via CMake. * Added test for autoconf-CMake interworking Work is mostly done by Codex and Curser.
1 parent a631611 commit 690aa2f

File tree

16 files changed

+258
-15
lines changed

16 files changed

+258
-15
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: WolfSSL CMake Autoconf Interworking Test
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
build:
11+
if: github.repository_owner == 'wolfssl'
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
# pull wolfSSL
16+
- uses: actions/checkout@master
17+
18+
# install cmake and autotools
19+
- name: Install cmake
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y cmake autoconf automake libtool
23+
24+
# pull wolfssl
25+
- name: Checkout wolfssl
26+
uses: actions/checkout@master
27+
with:
28+
repository: wolfssl/wolfssl
29+
path: wolfssl
30+
31+
# build and install wolfssl via autotools for CMake consumer test
32+
- name: Build wolfssl with autotools
33+
working-directory: ./wolfssl
34+
run: |
35+
./autogen.sh
36+
./configure --prefix="$GITHUB_WORKSPACE/install-autoconf" --enable-all
37+
make -j $(nproc)
38+
make install
39+
40+
# CMake consumer test using the autotools install
41+
- name: CMake consumer test (autotools install)
42+
working-directory: ./wolfssl
43+
run: |
44+
mkdir -p cmake/consumer/build
45+
cd cmake/consumer/build
46+
cmake -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install-autoconf" ..
47+
cmake --build .
48+
./wolfssl_consumer
49+
cd ..
50+
rm -rf build

.github/workflows/cmake.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
cd build
3737
cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DWOLFSSL_INSTALL=yes -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install" \
3838
-DWOLFSSL_16BIT:BOOL=no -DWOLFSSL_32BIT:BOOL=no -DWOLFSSL_AES:BOOL=yes \
39-
-DWOLFSSL_AESCBC:BOOL=yes -DWOLFSSL_AESCCM:BOOL=yes -DWOLFSSL_AESCFB:BOOL=yes \
39+
-DWOLFSSL_AESCBC:BOOL=yes -DWOLFSSL_AESCCM:BOOL=yes -DWOLFSSL_AESCFB:BOOL=yes -DWOLFSSL_AESECB:BOOL=yes \
4040
-DWOLFSSL_AESCTR:BOOL=yes -DWOLFSSL_AESGCM:STRING=yes -DWOLFSSL_AESKEYWRAP:BOOL=yes \
41-
-DWOLFSSL_AESOFB:BOOL=yes -DWOLFSSL_AESSIV:BOOL=yes -DWOLFSSL_ALIGN_DATA:BOOL=yes \
41+
-DWOLFSSL_AESOFB:BOOL=yes -DWOLFSSL_AESCTS:BOOL=yes -DWOLFSSL_AESSIV:BOOL=yes -DWOLFSSL_ALIGN_DATA:BOOL=yes \
4242
-DWOLFSSL_ALPN:BOOL=ON -DWOLFSSL_ALT_CERT_CHAINS:BOOL=ON -DWOLFSSL_ARC4:BOOL=yes \
4343
-DWOLFSSL_ARIA:BOOL=no -DWOLFSSL_ASIO:BOOL=no -DWOLFSSL_ASM:BOOL=yes -DWOLFSSL_ASN:BOOL=yes \
4444
-DWOLFSSL_ASYNC_THREADS:BOOL=no -DWOLFSSL_BASE64_ENCODE:BOOL=yes -DWOLFSSL_CAAM:BOOL=no \
@@ -51,7 +51,7 @@ jobs:
5151
-DWOLFSSL_CURVE448:STRING=yes -DWOLFSSL_DEBUG:BOOL=yes -DWOLFSSL_DES3:BOOL=ON \
5252
-DWOLFSSL_DES3_TLS_SUITES:BOOL=no -DWOLFSSL_DH:STRING=yes -DWOLFSSL_DH_DEFAULT_PARAMS:BOOL=yes \
5353
-DWOLFSSL_DSA:BOOL=yes -DWOLFSSL_DTLS:BOOL=ON -DWOLFSSL_DTLS13:BOOL=yes \
54-
-DWOLFSSL_DTLS_CID:BOOL=yes -DWOLFSSL_ECC:STRING=yes \
54+
-DWOLFSSL_DTLS_CID:BOOL=yes -DWOLFSSL_DTLS_CH_FRAG:BOOL=yes -DWOLFSSL_ECC:STRING=yes \
5555
-DWOLFSSL_ECCCUSTCURVES:STRING=all -DWOLFSSL_ECCSHAMIR:BOOL=yes \
5656
-DWOLFSSL_ECH:BOOL=yes -DWOLFSSL_ED25519:BOOL=yes -DWOLFSSL_ED448:STRING=yes \
5757
-DWOLFSSL_ENCKEYS:BOOL=yes -DWOLFSSL_ENC_THEN_MAC:BOOL=yes -DWOLFSSL_ERROR_QUEUE:BOOL=yes \

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ tags
4141
.tags*
4242
cyassl-config
4343
wolfssl-config
44+
cmake/wolfssl-config.cmake
45+
cmake/wolfssl-config-version.cmake
46+
cmake/wolfssl-targets.cmake
4447
cyassl.sublime*
4548
fips.h
4649
fips.c

CMakeLists.txt

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,18 @@ if(WOLFSSL_DTLS_CID)
427427
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS_CID")
428428
endif()
429429

430+
# DTLS 1.3 Fragment ClientHello
431+
add_option("WOLFSSL_DTLS_CH_FRAG"
432+
"Enable wolfSSL DTLS 1.3 Fragment ClientHello (default: disabled)"
433+
"no" "yes;no")
434+
435+
if(WOLFSSL_DTLS_CH_FRAG)
436+
if(NOT WOLFSSL_DTLS13)
437+
message(FATAL_ERROR "DTLS 1.3 Fragment ClientHello are supported only for DTLSv1.3")
438+
endif()
439+
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_DTLS_CH_FRAG")
440+
endif()
441+
430442
# RNG
431443
add_option("WOLFSSL_RNG"
432444
"Enable compiling and using RNG (default: enabled)"
@@ -513,6 +525,7 @@ endif()
513525

514526
if(WOLFSSL_WOLFSSH OR WOLFSSL_WPAS)
515527
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_PUBLIC_MP")
528+
set(WOLFSSL_PUBLIC_MP ON)
516529
endif()
517530

518531
# TODO: - DTLS-SCTP
@@ -881,6 +894,27 @@ add_option("WOLFSSL_AESOFB"
881894
"Enable wolfSSL AES-OFB support (default: disabled)"
882895
"no" "yes;no")
883896

897+
# AES-ECB
898+
add_option("WOLFSSL_AESECB"
899+
"Enable wolfSSL AES-ECB support (default: disabled)"
900+
"no" "yes;no")
901+
902+
if(WOLFSSL_AESECB)
903+
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_AES_ECB")
904+
endif()
905+
906+
# AES-CTS
907+
add_option("WOLFSSL_AESCTS"
908+
"Enable wolfSSL AES-CTS support (default: disabled)"
909+
"no" "yes;no")
910+
911+
if(WOLFSSL_AESCTS)
912+
if(NOT WOLFSSL_AESCBC)
913+
message(FATAL_ERROR "AES-CTS requires AES-CBC.")
914+
endif()
915+
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_AES_CTS")
916+
endif()
917+
884918
# TODO: - AES-GCM stream
885919
# - AES-ARM
886920
# - Xilinx hardened crypto
@@ -1081,6 +1115,7 @@ if(WOLFSSL_ECCSI)
10811115
endif()
10821116

10831117
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFCRYPT_HAVE_ECCSI -DWOLFSSL_PUBLIC_MP")
1118+
set(WOLFSSL_PUBLIC_MP ON)
10841119
endif()
10851120

10861121
# SAKKE
@@ -1105,6 +1140,14 @@ if(WOLFSSL_SIPHASH)
11051140
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_SIPHASH")
11061141
endif()
11071142

1143+
add_option("WOLFSSL_PUBLIC_MP"
1144+
"Enable public MP API (default: disabled)"
1145+
"no" "yes;no")
1146+
1147+
if(WOLFSSL_PUBLIC_MP)
1148+
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_PUBLIC_MP")
1149+
endif()
1150+
11081151
# TODO: - Compressed key
11091152
# - FP ECC, fixed point cache ECC
11101153
# - ECC encrypt
@@ -1435,6 +1478,12 @@ if(NOT WOLFSSL_AES)
14351478
if(WOLFSSL_AESCTR)
14361479
message(FATAL_ERROR "AESCTR requires AES.")
14371480
endif()
1481+
if(WOLFSSL_AESECB)
1482+
message(FATAL_ERROR "AES-ECB requires AES.")
1483+
endif()
1484+
if(WOLFSSL_AESCTS)
1485+
message(FATAL_ERROR "AES-CTS requires AES.")
1486+
endif()
14381487
else()
14391488
if(WOLFSSL_LEAN_PSK)
14401489
list(APPEND WOLFSSL_DEFINITIONS "-DNO_AES")
@@ -2196,13 +2245,14 @@ if(WOLFSSL_AESOFB)
21962245
endif()
21972246

21982247
if(WOLFSSL_TPM)
2199-
override_cache(WOLFSSL_KEYGEN "yes")
2200-
override_cache(WOLFSSL_CERTGEN "yes")
2201-
override_cache(WOLFSSL_CRYPTOCB "yes")
2202-
override_cache(WOLFSSL_CERTREQ "yes")
2203-
override_cache(WOLFSSL_CERTEXT "yes")
2204-
override_cache(WOLFSSL_PKCS7 "yes")
2205-
override_cache(WOLFSSL_AESCFB "yes")
2248+
override_cache(WOLFSSL_KEYGEN "yes")
2249+
override_cache(WOLFSSL_CERTGEN "yes")
2250+
override_cache(WOLFSSL_CRYPTOCB "yes")
2251+
override_cache(WOLFSSL_CERTREQ "yes")
2252+
override_cache(WOLFSSL_CERTEXT "yes")
2253+
override_cache(WOLFSSL_PKCS7 "yes")
2254+
override_cache(WOLFSSL_AESCFB "yes")
2255+
override_cache(WOLFSSL_PUBLIC_MP "yes")
22062256
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_ALLOW_ENCODING_CA_FALSE")
22072257
endif()
22082258

@@ -2600,7 +2650,7 @@ target_compile_definitions(wolfssl PRIVATE "BUILDING_WOLFSSL")
26002650
if(${BUILD_SHARED_LIBS})
26012651
target_compile_definitions(wolfssl PUBLIC "WOLFSSL_DLL")
26022652
endif()
2603-
target_compile_definitions(wolfssl PUBLIC ${WOLFSSL_DEFINITIONS})
2653+
target_compile_definitions(wolfssl PRIVATE ${WOLFSSL_DEFINITIONS})
26042654

26052655
####################################################
26062656
# Include Directories
@@ -2663,6 +2713,7 @@ if(WOLFSSL_EXAMPLES)
26632713
add_executable(client
26642714
${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
26652715
target_link_libraries(client wolfssl)
2716+
target_compile_definitions(client PRIVATE ${WOLFSSL_DEFINITIONS})
26662717
set_property(TARGET client
26672718
PROPERTY RUNTIME_OUTPUT_DIRECTORY
26682719
${WOLFSSL_OUTPUT_BASE}/examples/client)
@@ -2671,6 +2722,7 @@ if(WOLFSSL_EXAMPLES)
26712722
add_executable(server
26722723
${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c)
26732724
target_link_libraries(server wolfssl)
2725+
target_compile_definitions(server PRIVATE ${WOLFSSL_DEFINITIONS})
26742726
set_property(TARGET server
26752727
PROPERTY RUNTIME_OUTPUT_DIRECTORY
26762728
${WOLFSSL_OUTPUT_BASE}/examples/server)
@@ -2681,6 +2733,7 @@ if(WOLFSSL_EXAMPLES)
26812733
target_include_directories(echoclient PRIVATE
26822734
${CMAKE_CURRENT_BINARY_DIR})
26832735
target_link_libraries(echoclient wolfssl)
2736+
target_compile_definitions(echoclient PRIVATE ${WOLFSSL_DEFINITIONS})
26842737
set_property(TARGET echoclient
26852738
PROPERTY RUNTIME_OUTPUT_DIRECTORY
26862739
${WOLFSSL_OUTPUT_BASE}/examples/echoclient)
@@ -2691,6 +2744,7 @@ if(WOLFSSL_EXAMPLES)
26912744
target_include_directories(echoserver PRIVATE
26922745
${CMAKE_CURRENT_BINARY_DIR})
26932746
target_link_libraries(echoserver wolfssl)
2747+
target_compile_definitions(echoserver PRIVATE ${WOLFSSL_DEFINITIONS})
26942748
set_property(TARGET echoserver
26952749
PROPERTY RUNTIME_OUTPUT_DIRECTORY
26962750
${WOLFSSL_OUTPUT_BASE}/examples/echoserver)
@@ -2700,6 +2754,7 @@ if(WOLFSSL_EXAMPLES)
27002754
add_executable(tls_bench
27012755
${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
27022756
target_link_libraries(tls_bench wolfssl)
2757+
target_compile_definitions(tls_bench PRIVATE ${WOLFSSL_DEFINITIONS})
27032758
if(CMAKE_USE_PTHREADS_INIT)
27042759
target_link_libraries(tls_bench Threads::Threads)
27052760
endif()
@@ -2804,6 +2859,7 @@ if(WOLFSSL_EXAMPLES)
28042859
${CMAKE_CURRENT_BINARY_DIR})
28052860
target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
28062861
target_link_libraries(unit_test wolfssl)
2862+
target_compile_definitions(unit_test PRIVATE ${WOLFSSL_DEFINITIONS})
28072863
if(CMAKE_USE_PTHREADS_INIT)
28082864
target_link_libraries(unit_test Threads::Threads)
28092865
endif()
@@ -2829,6 +2885,7 @@ if(WOLFSSL_CRYPT_TESTS)
28292885
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
28302886
set_target_properties(wolfcrypttest_lib PROPERTIES OUTPUT_NAME "wolfcrypttest")
28312887
target_link_libraries(wolfcrypttest_lib wolfssl)
2888+
target_compile_definitions(wolfcrypttest_lib PRIVATE ${WOLFSSL_DEFINITIONS})
28322889
target_compile_options(wolfcrypttest_lib PRIVATE "-DNO_MAIN_DRIVER")
28332890
if(WOLFSSL_CRYPT_TESTS_HELP)
28342891
target_compile_options(wolfcrypttest_lib PRIVATE "-DHAVE_WOLFCRYPT_TEST_OPTIONS")
@@ -2839,13 +2896,15 @@ if(WOLFSSL_CRYPT_TESTS)
28392896
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
28402897
set_target_properties(wolfcryptbench_lib PROPERTIES OUTPUT_NAME "wolfcryptbench")
28412898
target_link_libraries(wolfcryptbench_lib wolfssl)
2899+
target_compile_definitions(wolfcryptbench_lib PRIVATE ${WOLFSSL_DEFINITIONS})
28422900
target_compile_options(wolfcryptbench_lib PRIVATE "-DNO_MAIN_DRIVER")
28432901
endif()
28442902

28452903
# Build wolfCrypt test executable.
28462904
add_executable(wolfcrypttest
28472905
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
28482906
target_link_libraries(wolfcrypttest wolfssl)
2907+
target_compile_definitions(wolfcrypttest PRIVATE ${WOLFSSL_DEFINITIONS})
28492908
set_property(TARGET wolfcrypttest
28502909
PROPERTY RUNTIME_OUTPUT_DIRECTORY
28512910
${WOLFSSL_OUTPUT_BASE}/wolfcrypt/test)
@@ -2865,6 +2924,7 @@ if(WOLFSSL_CRYPT_TESTS)
28652924
target_include_directories(wolfcryptbench PRIVATE
28662925
${CMAKE_CURRENT_BINARY_DIR})
28672926
target_link_libraries(wolfcryptbench wolfssl)
2927+
target_compile_definitions(wolfcryptbench PRIVATE ${WOLFSSL_DEFINITIONS})
28682928
set_property(TARGET wolfcryptbench
28692929
PROPERTY RUNTIME_OUTPUT_DIRECTORY
28702930
${WOLFSSL_OUTPUT_BASE}/wolfcrypt/benchmark)
@@ -3019,9 +3079,9 @@ if(WOLFSSL_INSTALL)
30193079
# Install the library
30203080
install(TARGETS wolfssl
30213081
EXPORT wolfssl-targets
3022-
LIBRARY DESTINATION lib
3023-
ARCHIVE DESTINATION lib
3024-
RUNTIME DESTINATION bin
3082+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
3083+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
3084+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
30253085
)
30263086
# Install the headers
30273087
install(DIRECTORY ${WOLFSSL_OUTPUT_BASE}/wolfssl/

INSTALL

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
all the generated build options. This file needs to be included in your application
1717
before any other wolfSSL headers. Optionally your application can define
1818
WOLFSSL_USE_OPTIONS_H to do this automatically.
19+
Note: Building with configure also installs CMake package files under
20+
$(libdir)/cmake/wolfssl to support find_package(wolfssl). You can disable this
21+
with ./configure --disable-cmake-install.
1922

2023
2. Building on iOS
2124

Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ CLEANFILES+= ecc-key.der \
7878
pkcs7encryptedDataDES3.der \
7979
pkcs7encryptedDataDES.der \
8080
pkcs7envelopedDataAES256CBC_ECDH.der \
81+
cmake/wolfssl-config.cmake \
82+
cmake/wolfssl-config-version.cmake \
83+
cmake/wolfssl-targets.cmake \
8184
pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der \
8285
pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der \
8386
pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der \

cmake/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
This directory contains some supplementary functions for the [CMakeLists.txt](../CMakeLists.txt) in the root.
44

55
See also cmake notes in the [INSTALL](../INSTALL) documentation file.
6+
When building with autoconf/automake, CMake package files are installed by default
7+
under $(libdir)/cmake/wolfssl to support find_package(wolfssl). Disable with
8+
./configure --disable-cmake-install.
69

710
If new CMake build options are added `cmake/options.h.in` must also be updated.
811

@@ -56,4 +59,3 @@ See the Microsoft [CMakeSettings.json schema reference](https://learn.microsoft.
5659
* Specific environment variables
5760
* *UI-related tweaks
5861

59-

cmake/consumer/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(wolfssl_consumer C)
4+
5+
find_package(wolfssl CONFIG REQUIRED)
6+
7+
add_executable(wolfssl_consumer main.c)
8+
target_link_libraries(wolfssl_consumer PRIVATE wolfssl::wolfssl)

cmake/consumer/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# CMake consumer test
2+
3+
This is a minimal CMake project that consumes the installed wolfSSL
4+
package config.
5+
6+
## Build
7+
8+
```
9+
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/wolfssl/install
10+
cmake --build build
11+
./build/wolfssl_consumer
12+
```

cmake/consumer/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <wolfssl/options.h>
2+
#include <wolfssl/ssl.h>
3+
4+
int main(void)
5+
{
6+
if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
7+
return 1;
8+
}
9+
wolfSSL_Cleanup();
10+
return 0;
11+
}

0 commit comments

Comments
 (0)