Skip to content

Commit

Permalink
Merge pull request wolfSSL#7546 from oltolm/cmake
Browse files Browse the repository at this point in the history
cmake: fix generation of options.h
  • Loading branch information
SparkiDev authored and jefferyq2 committed Jun 9, 2024
1 parent ae5b099 commit 8382417
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 63 deletions.
42 changes: 15 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,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 @@ -2238,32 +2238,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 @@ -2341,6 +2315,20 @@ 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()

# If new build options are added please update the cmake/options.h.in
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/options.h.in ${OPTION_FILE})

set_target_properties(wolfssl
PROPERTIES
SOVERSION ${WOLFSSL_LIBRARY_VERSION_FIRST}
Expand Down
2 changes: 1 addition & 1 deletion cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This directory contains some supplementary functions for the [CMakeLists.txt](..

See also cmake notes in the [INSTALL](../INSTALL) documentation file.


If new CMake build options are added `cmake/options.h.in` must also be updated.
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 cmake/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ EXTRA_DIST += cmake/README.md
EXTRA_DIST += cmake/Config.cmake.in
EXTRA_DIST += cmake/config.in
EXTRA_DIST += cmake/functions.cmake
EXTRA_DIST += cmake/options.h.in
EXTRA_DIST += cmake/modules/FindARIA.cmake
EXTRA_DIST += cmake/modules/FindOQS.cmake
Loading

0 comments on commit 8382417

Please sign in to comment.