Skip to content

Commit

Permalink
don't build bundled libzmq if it doesn't find libsodium
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Feb 15, 2024
1 parent de49357 commit e6afb15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ if (ZMQ_PREFIX STREQUAL "bundled")
list(PREPEND CMAKE_PREFIX_PATH ${BUNDLE_DIR})

# libsodium

if (WIN32)
set(libsodium_lib "${BUNDLE_DIR}/lib/libsodium.lib")
else()
Expand All @@ -166,19 +167,25 @@ if (ZMQ_PREFIX STREQUAL "bundled")
)
FetchContent_MakeAvailable(bundled_libsodium)
# run libsodium build explicitly here, so it's available to libzmq next
set(bundled_libsodium_include "${bundled_libsodium_SOURCE_DIR}/src/libsodium/include")

if(${bundled_libsodium_POPULATED} AND NOT EXISTS "${libsodium_lib}")
message(STATUS "building bundled libsodium")
if (WIN32)
# TODO: allow picking msvc build?
list(APPEND libsodium_build
"msbuild"
"/m"
"/v:n"
"/p:Configuration=Static${CMAKE_BUILD_TYPE}"
"/p:Platform=${CMAKE_GENERATOR_PLATFORM}"
"builds/msvc/vs2022/libsodium.sln"
)
execute_process(
COMMAND msbuild
"/m"
"/v:n"
"/p:Configuration=Static${CMAKE_BUILD_TYPE}"
"/p:Platform=${CMAKE_GENERATOR_PLATFORM}"
"builds/msvc/vs2022/libsodium.sln"
COMMAND ${libsodium_build}
WORKING_DIRECTORY ${bundled_libsodium_SOURCE_DIR}
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY
)
file(GLOB_RECURSE BUILT_LIBS "${bundled_libsodium_SOURCE_DIR}/**/libsodium.lib")
message(STATUS "built ${BUILT_LIBS}")
Expand Down
10 changes: 7 additions & 3 deletions cmake/Findsodium.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# copy libzmq's findsodium, which can't be told where to look
# we want to get our local bundled static libsodium
# not any other
message(STATUS "in my findsodium")
message(CHECK_START "Looking for pyzmq-bundled libsodium")
set(SODIUM_FOUND FALSE)

set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
Expand All @@ -20,13 +20,13 @@ if (NOT SODIUM_FOUND)
find_path(
SODIUM_INCLUDE_DIRS
NAMES sodium.h
HINTS ${BUNDLE_DIR}/include
PATH ${BUNDLE_DIR} ${bundled_libsodium_include}
)
# TODO: find bundled sodium on msvc
find_library(
SODIUM_LIBRARIES
NAMES libsodium.a sodium.lib
HINTS ${BUNDLE_DIR}/lib
PATH ${BUNDLE_DIR}/lib
)
if (SODIUM_LIBRARIES)
# pkg-config didn't work, what do we need?
Expand All @@ -37,6 +37,10 @@ if (NOT SODIUM_FOUND)
endif()
endif()

if (NOT SODIUM_FOUND)
message(CHECK_FAIL "no")
message(FATAL_ERROR "Failed to find bundled libsodium")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(sodium DEFAULT_MSG SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)
mark_as_advanced(SODIUM_FOUND SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)

0 comments on commit e6afb15

Please sign in to comment.