diff --git a/3rdParty/libsodium/CMakeLists.txt b/3rdParty/libsodium/CMakeLists.txt new file mode 100644 index 000000000..b2208b9ad --- /dev/null +++ b/3rdParty/libsodium/CMakeLists.txt @@ -0,0 +1,17 @@ +if(NOT DEVILUTIONX_SYSTEM_LIBSODIUM) + set(SODIUM_MINIMAL ON) + set(SODIUM_ENABLE_BLOCKING_RANDOM OFF) + set(SODIUM_DISABLE_TESTS ON) + + if(DEVILUTIONX_STATIC_LIBSODIUM) + set(BUILD_SHARED_LIBS OFF) + else() + set(BUILD_SHARED_LIBS ON) + endif() + include(FetchContent) + FetchContent_Declare(sodium + GIT_REPOSITORY https://github.com/robinlinden/libsodium-cmake.git + GIT_TAG a8ac4509b22b84d6c2eb7d7448f08678e4a67da6 + ) + FetchContent_MakeAvailable(sodium) +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b6aca744..4f663285a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.13) # CMP0083 NEW +include(CMakeDependentOption) include(CMake/out_of_tree.cmake) include(CMake/genex.cmake) @@ -32,6 +33,10 @@ if(NIGHTLY_BUILD OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") set(CPACK ON) endif() +option(DEVILUTIONX_SYSTEM_LIBSODIUM "Use system-provided libsodium" ON) +cmake_dependent_option(DEVILUTIONX_STATIC_LIBSODIUM "Link static libsodium" OFF + "DIST OR NOT DEVILUTIONX_SYSTEM_LIBSODIUM" ON) + if(NOT VERSION_NUM) include(CMake/git.cmake) get_git_tag(VERSION_NUM) @@ -131,10 +136,6 @@ if(N3DS) include(n3ds_defs) endif() -if(DIST) - set(sodium_USE_STATIC_LIBS ON) -endif() - if(PIE) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) endif() @@ -150,7 +151,12 @@ if(NOT N3DS) endif() if(NOT NONET) - find_package(sodium REQUIRED) + if(DEVILUTIONX_SYSTEM_LIBSODIUM) + set(sodium_USE_STATIC_LIBS ${DEVILUTIONX_STATIC_LIBSODIUM}) + find_package(sodium REQUIRED) + else() + add_subdirectory(3rdParty/libsodium) + endif() endif() if(USE_SDL1)