Skip to content

Commit

Permalink
Find GNUnet library and include path
Browse files Browse the repository at this point in the history
  • Loading branch information
marty1885 committed Jun 26, 2023
1 parent f86f1e3 commit 1a3df87
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ project(gnunetpp CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(GNUnet REQUIRED)

add_subdirectory(gnunetpp)

option(GNUNETPP_BUILD_EXAMPLES "Build examples" ON)
Expand All @@ -22,5 +25,8 @@ configure_package_config_file(
gnunetppConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/gnunetppConfig.cmake
INSTALL_DESTINATION lib/cmake/gnunetpp)


install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gnunetppConfig.cmake
DESTINATION lib/cmake/gnunetpp)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGNUnet.cmake
DESTINATION lib/cmake/gnunetpp)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This project aims to create a easy to use wapper for the commonly used part of G
- [x] Replace cppcoro
- [ ] Port to C++ modules when CMake supports it
- CMake
- [ ] Locate GNUnet installation path (currently use the expected path)
- [x] Locate GNUnet installation path (currently use the expected path)
- [ ] Find libidn2
- DHT
- [x] Basic operations (put/get)
Expand Down
41 changes: 41 additions & 0 deletions cmake/FindGNUnet.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
if (TARGET GNUnet::GNUnet)
return()
endif ()

find_path(GNUnet_INCLUDE_DIRS NAMES gnunet/gnunet_common.h
DOC "The GNUnet include directory")

set(GNUnet_LIBS namestore gnsrecord identity core util fs dht nse cadet peerinfo datastore gns messenger
transport hello)
set(all_libs_found TRUE)
foreach(lib ${GNUnet_LIBS})
find_library(GNUnet_${lib}_LIBRARY NAMES gnunet${lib})
if (NOT GNUnet_${lib}_LIBRARY)
message(STATUS "Missing GNUnet library: ${lib}")
set(all_libs_found FALSE)
endif ()
list(APPEND GNUnet_LIBRARIES ${GNUnet_${lib}_LIBRARY})
endforeach()

if (NOT all_libs_found)
message(STATUS "Missing some or all GNUnet library")
set(GNUnet_FOUND FALSE)
return()
endif ()

# HACK: CMake requires a library as the "target" of an imported library, so we
# use a library we know will be present on the system.
add_library(GNUnet::GNUnet IMPORTED UNKNOWN)
set_target_properties(GNUnet::GNUnet PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GNUnet_INCLUDE_DIRS}"
IMPORTED_LOCATION ${GNUnet_util_LIBRARY}
INTERFACE_LINK_LIBRARIES "${GNUnet_LIBRARIES}"
)

mark_as_advanced(GNUnet_INCLUDE_DIRS GNUnet_LIBRARIES)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
GNUnet
REQUIRED_VARS GNUnet_LIBRARIES GNUnet_INCLUDE_DIRS
)
4 changes: 1 addition & 3 deletions gnunetpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ add_library(gnunetpp
inner/Infra.cpp)
target_include_directories(gnunetpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_precompile_headers(gnunetpp PRIVATE pch.hpp)
target_link_libraries(gnunetpp PUBLIC idn gnunetnamestore gnunetgnsrecord gnunetidentity gnunetcore
gnunetutil gnunetfs gnunetdht gnunetnse gnunetcadet gnunetpeerinfo gnunetdatastore gnunetgns gnunetmessenger
gnunettransport gnunethello)
target_link_libraries(gnunetpp PUBLIC idn GNUnet::GNUnet)
# workaround for libintl.h conflicts
target_compile_definitions(gnunetpp PUBLIC -DENABLE_NLS)

Expand Down

0 comments on commit 1a3df87

Please sign in to comment.