Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: fix generation of options.h #7546

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ add_option(WOLFSSL_ALPN
"no" "yes;no")

if(WOLFSSL_ALPN)
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ALPN" "-DHAVE_TLS_EXTENSIONS")
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_ALPN" "-DHAVE_TLS_EXTENSIONS")
endif()

# altcertchains
Expand Down Expand Up @@ -2236,32 +2236,6 @@ endif()

file(REMOVE ${OPTION_FILE})

file(APPEND ${OPTION_FILE} "/* wolfssl options.h\n")
file(APPEND ${OPTION_FILE} " * generated from configure options\n")
file(APPEND ${OPTION_FILE} " *\n")
file(APPEND ${OPTION_FILE} " * Copyright (C) 2006-2023 wolfSSL Inc.\n")
file(APPEND ${OPTION_FILE} " *\n")
file(APPEND ${OPTION_FILE} " * This file is part of wolfSSL. (formerly known as CyaSSL)\n")
file(APPEND ${OPTION_FILE} " *\n")
file(APPEND ${OPTION_FILE} " */\n\n")
file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_H\n")
file(APPEND ${OPTION_FILE} "#define WOLFSSL_OPTIONS_H\n\n\n")
file(APPEND ${OPTION_FILE} "#ifdef __cplusplus\n")
file(APPEND ${OPTION_FILE} "extern \"C\" {\n")
file(APPEND ${OPTION_FILE} "#endif\n\n")

add_to_options_file("${WOLFSSL_DEFINITIONS}" "${OPTION_FILE}")
# CMAKE_C_FLAGS is just a string of space-separated flags to pass to the C
# compiler. We need to replace those spaces with semicolons in order to treat it
# as a CMake list.
string(REPLACE " " ";" CMAKE_C_FLAGS_LIST "${CMAKE_C_FLAGS}")
add_to_options_file("${CMAKE_C_FLAGS_LIST}" "${OPTION_FILE}")

file(APPEND ${OPTION_FILE} "\n#ifdef __cplusplus\n")
file(APPEND ${OPTION_FILE} "}\n")
file(APPEND ${OPTION_FILE} "#endif\n\n\n")
file(APPEND ${OPTION_FILE} "#endif /* WOLFSSL_OPTIONS_H */\n\n")

####################################################
# Library Target
####################################################
Expand Down Expand Up @@ -2339,6 +2313,19 @@ if(WOLFSSL_ARIA)
message(STATUS "ARIA Check: WOLFSSL_LINK_LIBS = ${WOLFSSL_LINK_LIBS}")
endif()

foreach(DEF IN LISTS WOLFSSL_DEFINITIONS)
string(REGEX MATCH "^(-D)?([^=]+)(=(.*))?$" DEF_MATCH ${DEF})
if (DEFINED CMAKE_MATCH_4)
set(${CMAKE_MATCH_2} ${CMAKE_MATCH_4})
# message("set(${CMAKE_MATCH_2} ${CMAKE_MATCH_4})")
else()
set(${CMAKE_MATCH_2} 1)
# message("set(${CMAKE_MATCH_2} 1)")
endif()
endforeach()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h.in ${OPTION_FILE})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here about needing to update the file for new options. Also add a comment in cmake/README.md.


set_target_properties(wolfssl
PROPERTIES
SOVERSION ${WOLFSSL_LIBRARY_VERSION_FIRST}
Expand Down
29 changes: 0 additions & 29 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -918,35 +918,6 @@ function(generate_lib_src_list LIB_SOURCES)
set(LIB_SOURCES ${LIB_SOURCES} PARENT_SCOPE)
endfunction()

function(add_to_options_file DEFINITIONS OPTION_FILE)
list(REMOVE_DUPLICATES DEFINITIONS)
foreach(DEF IN LISTS DEFINITIONS)
if(DEF MATCHES "^-D")
if(DEF MATCHES "^-D(N)?DEBUG(=.+)?")
message("not outputting (N)DEBUG to ${OPTION_FILE}")
endif()

# allow user to ignore system options
if(DEF MATCHES "^-D_.*")
file(APPEND ${OPTION_FILE} "#ifndef WOLFSSL_OPTIONS_IGNORE_SYS\n")
endif()

string(REGEX REPLACE "^-D" "" DEF_NO_PREFIX ${DEF})
string(REGEX REPLACE "=.*$" "" DEF_NO_EQUAL_NO_VAL ${DEF_NO_PREFIX})
string(REPLACE "=" " " DEF_NO_EQUAL ${DEF_NO_PREFIX})

file(APPEND ${OPTION_FILE} "#undef ${DEF_NO_EQUAL_NO_VAL}\n")
file(APPEND ${OPTION_FILE} "#define ${DEF_NO_EQUAL}\n")

if(DEF MATCHES "^-D_.*")
file(APPEND ${OPTION_FILE} "#endif\n")
endif()

file(APPEND ${OPTION_FILE} "\n")
endif()
endforeach()
endfunction()

# Function: set_wolfssl_definitions
# Parameter: SEARCH_VALUE The string to search for. (e.g. "WOLFSSL_SHA3")
# Returns: RESULT
Expand Down
1 change: 1 addition & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
#endif
#include <wolfssl/error-ssl.h>

#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I was not able to reproduce.
@oltolm says : "fix compilation of tests with GCC".
@oltolm can you please describe how to reproduce this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix I get this on Windows with GCC 14.1.

FAILED: CMakeFiles/unit_test.dir/tests/api.c.obj 
C:\msys64\mingw64\bin\gcc.exe -DECC_SHAMIR -DECC_TIMING_RESISTANT -DGCM_TABLE_4BIT -DHAVE_AESGCM -DHAVE_CHACHA -DHAVE_CONFIG_H -DHAVE_DH_DEFAULT_PARAMS -DHAVE_ECC -DHAVE_ENCRYPT_THEN_MAC -DHAVE_EXTENDED_MASTER -DHAVE_FFDHE_2048 -DHAVE_HASHDRBG -DHAVE_HKDF -DHAVE_ONE_TIME_AUTH -DHAVE_POLY1305 -DHAVE_PTHREAD -DHAVE_SNI -DHAVE_SUPPORTED_CURVES -DHAVE_THREAD_LS -DHAVE_TLS_EXTENSIONS -DHAVE___UINT128_T -DNO_DES3 -DNO_DES3_TLS_SUITES -DNO_DSA -DNO_MD4 -DNO_PSK -DNO_RC4 -DTFM_ECC256 -DTFM_TIMING_RESISTANT -DWC_NO_ASYNC_THREADING -DWC_RSA_BLINDING -DWC_RSA_PSS -DWOLFSSL_BASE64_ENCODE -DWOLFSSL_DLL -DWOLFSSL_IGNORE_FILE_WARN -DWOLFSSL_NO_SHAKE128 -DWOLFSSL_NO_SHAKE256 -DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_SHA224 -DWOLFSSL_SHA3 -DWOLFSSL_SHA384 -DWOLFSSL_SHA512 -DWOLFSSL_SYS_CA_CERTS -DWOLFSSL_TLS13 -DWOLFSSL_USE_ALIGN -DWOLFSSL_X86_64_BUILD -D_POSIX_THREADS -IC:/src/wolfssl/build -IC:/src/wolfssl -Wall  -g -DNO_MAIN_DRIVER -MD -MT CMakeFiles/unit_test.dir/tests/api.c.obj -MF CMakeFiles\unit_test.dir\tests\api.c.obj.d -o CMakeFiles/unit_test.dir/tests/api.c.obj -c C:/src/wolfssl/tests/api.c
C:/src/wolfssl/tests/api.c: In function 'test_read_write_hs':
C:/src/wolfssl/tests/api.c:71565:5: error: unknown type name 'uint8_t'
71565 |     uint8_t test_buffer[16];
      |     ^~~~~~~
C:/src/wolfssl/tests/api.c:5519:1: note: 'uint8_t' is defined in header '<stdint.h>'; this is probably fixable by adding '#include <stdint.h>'
 5518 | #include <wolfssl/openssl/pem.h>
  +++ |+#include <stdint.h>
 5519 | /*----------------------------------------------------------------------------*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @oltolm . I went ahead and removed the uses of uint8_t. The reason we weren't seeing this is because configure sets HAVE_UINT_PTR that includes stdint.h.

#include <stdlib.h>
#include <wolfssl/ssl.h> /* compatibility layer */
#include <wolfssl/test.h>
Expand Down
Loading