Skip to content

Commit

Permalink
Update CMake modules to detect Botan3 with not specified botan3 backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Feb 23, 2024
1 parent 06c917b commit c89f47a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ endif(WIN32)

# set a few other things at the top level to prevent incompatibilities
set(CMAKE_C_STANDARD 99)
if(NOT CRYPTO_BACKEND_BOTAN3)
set(CMAKE_CXX_STANDARD 11)
else()
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_definitions(-D_GNU_SOURCE)
Expand Down
22 changes: 12 additions & 10 deletions cmake/Modules/FindBotan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ if(DEFINED ENV{BOTAN_ROOT_DIR})
list(APPEND _hints_lib "$ENV{BOTAN_ROOT_DIR}/lib")
endif()

# Append PC_* stuff only if BOTAN_ROOT_DIR is not specified
if(NOT _hints_include)
list(APPEND _hints_include ${PC_BOTAN_INCLUDEDIR} ${PC_BOTAN_INCLUDE_DIRS})
list(APPEND _hints_lib ${PC_BOTAN_LIBDIR} ${PC_BOTAN_LIBRARY_DIRS})
else()
set(_no_def_path "NO_DEFAULT_PATH")
endif()

# find the headers
find_path(BOTAN_INCLUDE_DIR
NAMES botan/version.h
HINTS
${_hints_include}
${PC_BOTAN_INCLUDEDIR}
${PC_BOTAN_INCLUDE_DIRS}
PATH_SUFFIXES ${_suffixes}
${_no_def_path}
)

# find the library
Expand All @@ -100,24 +107,20 @@ if(MSVC)
NAMES botan
HINTS
${_hints_lib}
${PC_BOTAN_LIBDIR}
${PC_BOTAN_LIBRARY_DIRS}
${_no_def_path}
)
else()
find_library(BOTAN_LIBRARY
NAMES
${_names}
HINTS
${_hints_lib}
${PC_BOTAN_LIBDIR}
${PC_BOTAN_LIBRARY_DIRS}
${_no_def_path}
)
endif()

# determine the version
if(PC_BOTAN_VERSION)
set(BOTAN_VERSION ${PC_BOTAN_VERSION})
elseif(BOTAN_INCLUDE_DIR AND EXISTS "${BOTAN_INCLUDE_DIR}/botan/build.h")
if(BOTAN_INCLUDE_DIR AND EXISTS "${BOTAN_INCLUDE_DIR}/botan/build.h")
file(STRINGS "${BOTAN_INCLUDE_DIR}/botan/build.h" botan_version_str
REGEX "^#define[\t ]+(BOTAN_VERSION_[A-Z]+)[\t ]+[0-9]+")

Expand Down Expand Up @@ -163,4 +166,3 @@ if (BOTAN_FOUND AND NOT TARGET Botan::Botan)
endif()

mark_as_advanced(BOTAN_INCLUDE_DIR BOTAN_LIBRARY)

4 changes: 4 additions & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ if (CRYPTO_BACKEND_OPENSSL)
endif()
endif()

if(CRYPTO_BACKEND_BOTAN3)
set(CMAKE_CXX_STANDARD 20)
endif()

# generate a config.h
include(CheckIncludeFileCXX)
include(CheckCXXSymbolExists)
Expand Down
7 changes: 7 additions & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ if (CRYPTO_BACKEND_BOTAN3)
find_package(Botan 3.0.0 REQUIRED)
elseif (CRYPTO_BACKEND_BOTAN)
find_package(Botan 2.14.0 REQUIRED)
if(BOTAN_VERSION VERSION_GREATER_EQUAL 3.0.0)
set(CRYPTO_BACKEND_BOTAN3 1)
endif()
endif()
if (CRYPTO_BACKEND_LOWERCASE STREQUAL "openssl")
find_package(OpenSSL 1.1.1 REQUIRED)
endif()

if(CRYPTO_BACKEND_BOTAN3)
set(CMAKE_CXX_STANDARD 20)
endif()

add_executable(rnp_tests
../rnp/rnpcfg.cpp
../rnp/fficli.cpp
Expand Down

0 comments on commit c89f47a

Please sign in to comment.