1- function (find_botan_pkgconfig package_name botan_ver )
2- if (TARGET Botan::Botan)
1+ function (find_botan_pkgconfig package_name)
2+ if (TARGET Botan::Botan)
33 return ()
4- endif ()
4+ endif ()
55
6- pkg_check_modules(Botan QUIET IMPORTED_TARGET ${package_name} )
7- if (TARGET PkgConfig::Botan)
6+ pkg_check_modules(
7+ Botan
8+ QUIET
9+ IMPORTED_TARGET
10+ GLOBAL
11+ ${package_name}
12+ )
13+ if (TARGET PkgConfig::Botan)
814 add_library (Botan::Botan ALIAS PkgConfig::Botan)
915
10- if (botan_ver EQUAL 3)
16+ if (${Botan_FIND_VERSION} EQUAL 3)
1117 target_compile_features (PkgConfig::Botan INTERFACE cxx_std_20)
1218 endif ()
13- endif ()
19+ endif ()
1420endfunction ()
1521
16- function (find_botan_search package_name botan_ver)
17- if (TARGET Botan::Botan)
18- return ()
19- endif ()
20- find_path (Botan_INCLUDE_DIRS NAMES botan/botan.h
21- PATH_SUFFIXES ${package_name}
22- DOC "The Botan include directory" )
23-
24- find_library (Botan_LIBRARIES NAMES botan ${package_name}
25- DOC "The Botan library" )
22+ function (find_botan_search package_name)
23+ # botan2 have botan.h, but botan3 does not, botan3 using auto_rng.h instead
24+ find_path (
25+ Botan_INCLUDE_DIRS
26+ NAMES botan/botan.h botan/auto_rng.h
27+ HINTS ${BOTAN_ROOT_DIR} /include
28+ PATH_SUFFIXES ${package_name}
29+ DOC "The Botan include directory"
30+ )
2631
27- mark_as_advanced (Botan_INCLUDE_DIRS Botan_LIBRARIES)
32+ find_library (
33+ Botan_LIBRARIES
34+ NAMES botan ${package_name}
35+ HINTS ${BOTAN_ROOT_DIR} /lib
36+ DOC "The Botan library"
37+ )
2838
2939 add_library (Botan::Botan IMPORTED UNKNOWN)
3040 set_target_properties (
@@ -33,29 +43,32 @@ function(find_botan_search package_name botan_ver)
3343 IMPORTED_LOCATION "${Botan_LIBRARIES} "
3444 INTERFACE_INCLUDE_DIRECTORIES "${Botan_INCLUDE_DIRS} "
3545 )
36- if (botan_ver EQUAL 3)
46+ if (${Botan_FIND_VERSION} EQUAL 3)
3747 target_compile_features (Botan::Botan INTERFACE cxx_std_20)
3848 endif ()
3949
40- if (WIN32 )
50+ if (WIN32 )
4151 target_compile_definitions (Botan::Botan INTERFACE -DNOMINMAX=1)
42- endif ()
52+ endif ()
4353endfunction ()
4454
55+ # ######################################################################################################################
56+ # Using find_package with verion: find_package(Botan 3) or find_package(Botan 2)
57+ if (NOT DEFINED Botan_FIND_VERSION)
58+ message (FATAL_ERROR "Must specify Botan version: find_package(Botan 3) or find_package(Botan 2)" )
59+ endif ()
4560
46- find_package (PkgConfig)
47- if (NOT WIN32 AND PKG_CONFIG_FOUND)
48- # find_botan_pkgconfig(botan-2 2)
49- find_botan_pkgconfig(botan-3 3)
61+ if (NOT WIN32 )
62+ find_package (PkgConfig)
63+ if (PKG_CONFIG_FOUND)
64+ find_botan_pkgconfig(botan-${Botan_FIND_VERSION} )
65+ endif ()
5066endif ()
5167
5268if (NOT TARGET Botan::Botan)
53- # find_botan_search(botan-2 2)
54- find_botan_search(botan-3 3)
69+ find_botan_search(botan-${Botan_FIND_VERSION} )
5570endif ()
5671
5772include (FindPackageHandleStandardArgs)
58- find_package_handle_standard_args(
59- Botan
60- REQUIRED_VARS Botan_LIBRARIES Botan_INCLUDE_DIRS
61- )
73+ find_package_handle_standard_args(Botan REQUIRED_VARS Botan_LIBRARIES Botan_INCLUDE_DIRS)
74+ mark_as_advanced (Botan_INCLUDE_DIRS Botan_LIBRARIES)
0 commit comments