From b758580fe26f7f90deaaab21a0edfcc0f2bdd5cf Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 6 Aug 2023 18:31:52 +0200 Subject: [PATCH] initial setup --- .gitignore | 22 ++ .gitmodules | 25 ++ CMakeLists.txt | 52 +++++ external/CMakeLists.txt | 14 ++ external/entt/CMakeLists.txt | 4 + external/entt/entt | 1 + external/solanaceae_contact | 1 + external/solanaceae_message3 | 1 + external/solanaceae_plugin | 1 + external/solanaceae_tox | 1 + external/solanaceae_toxcore | 1 + external/solanaceae_util | 1 + external/toxcore/.gitignore | 1 + external/toxcore/CMakeLists.txt | 197 ++++++++++++++++ external/toxcore/c-toxcore | 1 + external/toxcore/cmake/Findsodium.cmake | 297 ++++++++++++++++++++++++ src/CMakeLists.txt | 12 + 17 files changed, 632 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 external/CMakeLists.txt create mode 100644 external/entt/CMakeLists.txt create mode 160000 external/entt/entt create mode 160000 external/solanaceae_contact create mode 160000 external/solanaceae_message3 create mode 160000 external/solanaceae_plugin create mode 160000 external/solanaceae_tox create mode 160000 external/solanaceae_toxcore create mode 160000 external/solanaceae_util create mode 100644 external/toxcore/.gitignore create mode 100644 external/toxcore/CMakeLists.txt create mode 160000 external/toxcore/c-toxcore create mode 100644 external/toxcore/cmake/Findsodium.cmake create mode 100644 src/CMakeLists.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..248798c --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +.vs/ +*.o +*.swp +~* +*~ +.idea/ +cmake-build-debug/ +cmake-build-debugandtest/ +cmake-build-release/ +*.stackdump +*.coredump +compile_commands.json +/build* +.clangd +.cache + +.DS_Store +.AppleDouble +.LSOverride + +CMakeLists.txt.user* +CMakeCache.txt diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3e18559 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,25 @@ +[submodule "external/solanaceae_contact"] + path = external/solanaceae_contact + url = https://github.com/Green-Sky/solanaceae_contact.git +[submodule "external/solanaceae_util"] + path = external/solanaceae_util + url = https://github.com/Green-Sky/solanaceae_util.git +[submodule "external/solanaceae_message3"] + path = external/solanaceae_message3 + url = https://github.com/Green-Sky/solanaceae_message3.git +[submodule "external/solanaceae_plugin"] + path = external/solanaceae_plugin + url = https://github.com/Green-Sky/solanaceae_plugin.git +[submodule "external/entt/entt"] + path = external/entt/entt + url = https://github.com/skypjack/entt.git +[submodule "external/toxcore/c-toxcore"] + path = external/toxcore/c-toxcore + url = https://github.com/Green-Sky/c-toxcore.git + branch = ngc_events +[submodule "external/solanaceae_toxcore"] + path = external/solanaceae_toxcore + url = https://github.com/Green-Sky/solanaceae_toxcore.git +[submodule "external/solanaceae_tox"] + path = external/solanaceae_tox + url = https://github.com/Green-Sky/solanaceae_tox.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..be0ea18 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) + +# cmake setup begin +project(solplug_ngcft1) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# defaulting to debug mode, if not specified +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# setup my vim ycm :D +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# more paths +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + +# external libs +add_subdirectory(./external) # before increasing warn levels, sad :( + +set(CMAKE_CXX_EXTENSIONS OFF) + +# bump up warning levels appropriately for clang, gcc & msvc +if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + add_compile_options( + -Wall -Wextra # Reasonable and standard + -Wpedantic # Warn if non-standard C++ is used + -Wunused # Warn on anything being unused + #-Wconversion # Warn on type conversions that may lose data + #-Wsign-conversion # Warn on sign conversions + -Wshadow # Warn if a variable declaration shadows one from a parent context + ) + + if (NOT WIN32) + #link_libraries(-fsanitize=address,undefined) + #link_libraries(-fsanitize=undefined) + endif() +elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") + if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() +endif() + +# cmake setup end + +#add_subdirectory(./src) + diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 0000000..80a65a9 --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) + +add_subdirectory(./solanaceae_util) +add_subdirectory(./solanaceae_plugin) + +add_subdirectory(./entt) + +add_subdirectory(./solanaceae_contact) +add_subdirectory(./solanaceae_message3) + +add_subdirectory(./toxcore) +add_subdirectory(./solanaceae_toxcore) +add_subdirectory(./solanaceae_tox) + diff --git a/external/entt/CMakeLists.txt b/external/entt/CMakeLists.txt new file mode 100644 index 0000000..abbae8d --- /dev/null +++ b/external/entt/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) + +add_subdirectory(./entt EXCLUDE_FROM_ALL) + diff --git a/external/entt/entt b/external/entt/entt new file mode 160000 index 0000000..fef9211 --- /dev/null +++ b/external/entt/entt @@ -0,0 +1 @@ +Subproject commit fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc diff --git a/external/solanaceae_contact b/external/solanaceae_contact new file mode 160000 index 0000000..738d2ab --- /dev/null +++ b/external/solanaceae_contact @@ -0,0 +1 @@ +Subproject commit 738d2abe7b4d6088412e56b89f4e26aab1a8bdba diff --git a/external/solanaceae_message3 b/external/solanaceae_message3 new file mode 160000 index 0000000..d2d6cfb --- /dev/null +++ b/external/solanaceae_message3 @@ -0,0 +1 @@ +Subproject commit d2d6cfbf5326de74cbac2dcd11be74df2cf79d2a diff --git a/external/solanaceae_plugin b/external/solanaceae_plugin new file mode 160000 index 0000000..d41efdd --- /dev/null +++ b/external/solanaceae_plugin @@ -0,0 +1 @@ +Subproject commit d41efddf56f710c99a8a86041cdc2d861322ebb0 diff --git a/external/solanaceae_tox b/external/solanaceae_tox new file mode 160000 index 0000000..de33242 --- /dev/null +++ b/external/solanaceae_tox @@ -0,0 +1 @@ +Subproject commit de332421f783a94877b7b529a698e0752273e7a4 diff --git a/external/solanaceae_toxcore b/external/solanaceae_toxcore new file mode 160000 index 0000000..b49db89 --- /dev/null +++ b/external/solanaceae_toxcore @@ -0,0 +1 @@ +Subproject commit b49db892f6f0069985c763f7c8598b57fc9810dd diff --git a/external/solanaceae_util b/external/solanaceae_util new file mode 160000 index 0000000..92eee15 --- /dev/null +++ b/external/solanaceae_util @@ -0,0 +1 @@ +Subproject commit 92eee153f2c14f97e50f44b10e2a0aeb5f8b190d diff --git a/external/toxcore/.gitignore b/external/toxcore/.gitignore new file mode 100644 index 0000000..0d9d95d --- /dev/null +++ b/external/toxcore/.gitignore @@ -0,0 +1 @@ +c-toxcore/tox diff --git a/external/toxcore/CMakeLists.txt b/external/toxcore/CMakeLists.txt new file mode 100644 index 0000000..45fade7 --- /dev/null +++ b/external/toxcore/CMakeLists.txt @@ -0,0 +1,197 @@ +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +set(TOX_DIR "${CMAKE_CURRENT_SOURCE_DIR}/c-toxcore/") + +# TODO: shared +add_library(toxcore STATIC + ${TOX_DIR}third_party/cmp/cmp.c + ${TOX_DIR}third_party/cmp/cmp.h + + ${TOX_DIR}toxcore/announce.c + ${TOX_DIR}toxcore/announce.h + ${TOX_DIR}toxcore/bin_pack.c + ${TOX_DIR}toxcore/bin_pack.h + ${TOX_DIR}toxcore/bin_unpack.c + ${TOX_DIR}toxcore/bin_unpack.h + ${TOX_DIR}toxcore/ccompat.c + ${TOX_DIR}toxcore/ccompat.h + ${TOX_DIR}toxcore/crypto_core.c + ${TOX_DIR}toxcore/crypto_core.h + ${TOX_DIR}toxcore/DHT.c + ${TOX_DIR}toxcore/DHT.h + ${TOX_DIR}toxcore/events/conference_connected.c + ${TOX_DIR}toxcore/events/conference_invite.c + ${TOX_DIR}toxcore/events/conference_message.c + ${TOX_DIR}toxcore/events/conference_peer_list_changed.c + ${TOX_DIR}toxcore/events/conference_peer_name.c + ${TOX_DIR}toxcore/events/conference_title.c + ${TOX_DIR}toxcore/events/events_alloc.c + ${TOX_DIR}toxcore/events/events_alloc.h + ${TOX_DIR}toxcore/events/file_chunk_request.c + ${TOX_DIR}toxcore/events/file_recv.c + ${TOX_DIR}toxcore/events/file_recv_chunk.c + ${TOX_DIR}toxcore/events/file_recv_control.c + ${TOX_DIR}toxcore/events/friend_connection_status.c + ${TOX_DIR}toxcore/events/friend_lossless_packet.c + ${TOX_DIR}toxcore/events/friend_lossy_packet.c + ${TOX_DIR}toxcore/events/friend_message.c + ${TOX_DIR}toxcore/events/friend_name.c + ${TOX_DIR}toxcore/events/friend_read_receipt.c + ${TOX_DIR}toxcore/events/friend_request.c + ${TOX_DIR}toxcore/events/friend_status.c + ${TOX_DIR}toxcore/events/friend_status_message.c + ${TOX_DIR}toxcore/events/friend_typing.c + ${TOX_DIR}toxcore/events/self_connection_status.c + ${TOX_DIR}toxcore/events/group_custom_packet.c + ${TOX_DIR}toxcore/events/group_custom_private_packet.c + ${TOX_DIR}toxcore/events/group_invite.c + ${TOX_DIR}toxcore/events/group_join_fail.c + ${TOX_DIR}toxcore/events/group_message.c + ${TOX_DIR}toxcore/events/group_moderation.c + ${TOX_DIR}toxcore/events/group_password.c + ${TOX_DIR}toxcore/events/group_peer_exit.c + ${TOX_DIR}toxcore/events/group_peer_join.c + ${TOX_DIR}toxcore/events/group_peer_limit.c + ${TOX_DIR}toxcore/events/group_peer_name.c + ${TOX_DIR}toxcore/events/group_peer_status.c + ${TOX_DIR}toxcore/events/group_privacy_state.c + ${TOX_DIR}toxcore/events/group_private_message.c + ${TOX_DIR}toxcore/events/group_self_join.c + ${TOX_DIR}toxcore/events/group_topic.c + ${TOX_DIR}toxcore/events/group_topic_lock.c + ${TOX_DIR}toxcore/events/group_voice_state.c + ${TOX_DIR}toxcore/forwarding.c + ${TOX_DIR}toxcore/forwarding.h + ${TOX_DIR}toxcore/friend_connection.c + ${TOX_DIR}toxcore/friend_connection.h + ${TOX_DIR}toxcore/friend_requests.c + ${TOX_DIR}toxcore/friend_requests.h + ${TOX_DIR}toxcore/group.c + ${TOX_DIR}toxcore/group.h + ${TOX_DIR}toxcore/group_announce.c + ${TOX_DIR}toxcore/group_announce.h + ${TOX_DIR}toxcore/group_moderation.c + ${TOX_DIR}toxcore/group_moderation.h + ${TOX_DIR}toxcore/group_chats.c + ${TOX_DIR}toxcore/group_chats.h + ${TOX_DIR}toxcore/group_common.h + ${TOX_DIR}toxcore/group_connection.c + ${TOX_DIR}toxcore/group_connection.h + ${TOX_DIR}toxcore/group_onion_announce.c + ${TOX_DIR}toxcore/group_onion_announce.h + ${TOX_DIR}toxcore/group_pack.c + ${TOX_DIR}toxcore/group_pack.h + ${TOX_DIR}toxcore/LAN_discovery.c + ${TOX_DIR}toxcore/LAN_discovery.h + ${TOX_DIR}toxcore/list.c + ${TOX_DIR}toxcore/list.h + ${TOX_DIR}toxcore/logger.c + ${TOX_DIR}toxcore/logger.h + ${TOX_DIR}toxcore/Messenger.c + ${TOX_DIR}toxcore/Messenger.h + ${TOX_DIR}toxcore/mono_time.c + ${TOX_DIR}toxcore/mono_time.h + ${TOX_DIR}toxcore/net_crypto.c + ${TOX_DIR}toxcore/net_crypto.h + ${TOX_DIR}toxcore/network.c + ${TOX_DIR}toxcore/network.h + ${TOX_DIR}toxcore/onion_announce.c + ${TOX_DIR}toxcore/onion_announce.h + ${TOX_DIR}toxcore/onion.c + ${TOX_DIR}toxcore/onion_client.c + ${TOX_DIR}toxcore/onion_client.h + ${TOX_DIR}toxcore/onion.h + ${TOX_DIR}toxcore/ping_array.c + ${TOX_DIR}toxcore/ping_array.h + ${TOX_DIR}toxcore/ping.c + ${TOX_DIR}toxcore/ping.h + ${TOX_DIR}toxcore/shared_key_cache.c + ${TOX_DIR}toxcore/shared_key_cache.h + ${TOX_DIR}toxcore/state.c + ${TOX_DIR}toxcore/state.h + ${TOX_DIR}toxcore/TCP_client.c + ${TOX_DIR}toxcore/TCP_client.h + ${TOX_DIR}toxcore/TCP_common.c + ${TOX_DIR}toxcore/TCP_common.h + ${TOX_DIR}toxcore/TCP_connection.c + ${TOX_DIR}toxcore/TCP_connection.h + ${TOX_DIR}toxcore/TCP_server.c + ${TOX_DIR}toxcore/TCP_server.h + ${TOX_DIR}toxcore/timed_auth.c + ${TOX_DIR}toxcore/timed_auth.h + ${TOX_DIR}toxcore/tox_api.c + ${TOX_DIR}toxcore/tox.c + ${TOX_DIR}toxcore/tox_dispatch.c + ${TOX_DIR}toxcore/tox_dispatch.h + ${TOX_DIR}toxcore/tox_events.c + ${TOX_DIR}toxcore/tox_events.h + ${TOX_DIR}toxcore/tox.h + ${TOX_DIR}toxcore/tox_private.c + ${TOX_DIR}toxcore/tox_private.h + ${TOX_DIR}toxcore/tox_unpack.c + ${TOX_DIR}toxcore/tox_unpack.h + ${TOX_DIR}toxcore/util.c + ${TOX_DIR}toxcore/util.h +) + +# HACK: "install" api headers into self +# this is dirty, should be binary dir +# TODO: add the others +configure_file( + ${TOX_DIR}toxcore/tox.h + ${TOX_DIR}tox/tox.h + @ONLY +) +configure_file( + ${TOX_DIR}toxcore/tox_events.h + ${TOX_DIR}tox/tox_events.h + @ONLY +) + +target_include_directories(toxcore PRIVATE "${TOX_DIR}toxcore") +target_include_directories(toxcore PUBLIC "${TOX_DIR}") + +target_compile_definitions(toxcore PUBLIC USE_IPV6=1) +#target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_DEBUG) +target_compile_definitions(toxcore PUBLIC MIN_LOGGER_LEVEL=LOGGER_LEVEL_INFO) + +find_package(unofficial-sodium CONFIG QUIET) +find_package(sodium QUIET) +if(unofficial-sodium_FOUND) # vcpkg + if(TARGET unofficial-sodium::sodium) + target_link_libraries(toxcore unofficial-sodium::sodium) + endif() + if(TARGET unofficial-sodium::sodium_config_public) + target_link_libraries(toxcore unofficial-sodium::sodium_config_public) + endif() +elseif(sodium_FOUND) + target_link_libraries(toxcore sodium) +else() + message(SEND_ERROR "missing libsodium") +endif() + +if(WIN32) + target_link_libraries(toxcore ws2_32 iphlpapi) +endif() + +find_package(pthreads QUIET) +if(TARGET PThreads4W::PThreads4W) + target_link_libraries(toxcore PThreads4W::PThreads4W) +else() + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + target_link_libraries(toxcore Threads::Threads) +endif() + +add_executable(DHT_Bootstrap EXCLUDE_FROM_ALL + ${TOX_DIR}other/DHT_bootstrap.c + ${TOX_DIR}other/bootstrap_node_packets.h + ${TOX_DIR}other/bootstrap_node_packets.c + ${TOX_DIR}testing/misc_tools.h + ${TOX_DIR}testing/misc_tools.c +) + +target_link_libraries(DHT_Bootstrap toxcore) + diff --git a/external/toxcore/c-toxcore b/external/toxcore/c-toxcore new file mode 160000 index 0000000..67badf6 --- /dev/null +++ b/external/toxcore/c-toxcore @@ -0,0 +1 @@ +Subproject commit 67badf69416a74e74f6d7eb51dd96f37282b8455 diff --git a/external/toxcore/cmake/Findsodium.cmake b/external/toxcore/cmake/Findsodium.cmake new file mode 100644 index 0000000..a210c00 --- /dev/null +++ b/external/toxcore/cmake/Findsodium.cmake @@ -0,0 +1,297 @@ +# Written in 2016 by Henrik Steffen Gaßmann +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# +# http://creativecommons.org/publicdomain/zero/1.0/ +# +######################################################################## +# Tries to find the local libsodium installation. +# +# On Windows the sodium_DIR environment variable is used as a default +# hint which can be overridden by setting the corresponding cmake variable. +# +# Once done the following variables will be defined: +# +# sodium_FOUND +# sodium_INCLUDE_DIR +# sodium_LIBRARY_DEBUG +# sodium_LIBRARY_RELEASE +# +# +# Furthermore an imported "sodium" target is created. +# + +if (CMAKE_C_COMPILER_ID STREQUAL "GNU" + OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(_GCC_COMPATIBLE 1) +endif() + +# static library option +if (NOT DEFINED sodium_USE_STATIC_LIBS) + option(sodium_USE_STATIC_LIBS "enable to statically link against sodium" OFF) +endif() +if(NOT (sodium_USE_STATIC_LIBS EQUAL sodium_USE_STATIC_LIBS_LAST)) + unset(sodium_LIBRARY CACHE) + unset(sodium_LIBRARY_DEBUG CACHE) + unset(sodium_LIBRARY_RELEASE CACHE) + unset(sodium_DLL_DEBUG CACHE) + unset(sodium_DLL_RELEASE CACHE) + set(sodium_USE_STATIC_LIBS_LAST ${sodium_USE_STATIC_LIBS} CACHE INTERNAL "internal change tracking variable") +endif() + + +######################################################################## +# UNIX +if (UNIX) + # import pkg-config + find_package(PkgConfig QUIET) + if (PKG_CONFIG_FOUND) + pkg_check_modules(sodium_PKG QUIET libsodium) + endif() + + if(sodium_USE_STATIC_LIBS) + foreach(_libname ${sodium_PKG_STATIC_LIBRARIES}) + if (NOT _libname MATCHES "^lib.*\\.a$") # ignore strings already ending with .a + list(INSERT sodium_PKG_STATIC_LIBRARIES 0 "lib${_libname}.a") + endif() + endforeach() + list(REMOVE_DUPLICATES sodium_PKG_STATIC_LIBRARIES) + + # if pkgconfig for libsodium doesn't provide + # static lib info, then override PKG_STATIC here.. + if (NOT sodium_PKG_STATIC_FOUND) + set(sodium_PKG_STATIC_LIBRARIES libsodium.a) + endif() + + set(XPREFIX sodium_PKG_STATIC) + else() + if (NOT sodium_PKG_FOUND) + set(sodium_PKG_LIBRARIES sodium) + endif() + + set(XPREFIX sodium_PKG) + endif() + + find_path(sodium_INCLUDE_DIR sodium.h + HINTS ${${XPREFIX}_INCLUDE_DIRS} + ) + find_library(sodium_LIBRARY_DEBUG NAMES ${${XPREFIX}_LIBRARIES} + HINTS ${${XPREFIX}_LIBRARY_DIRS} + ) + find_library(sodium_LIBRARY_RELEASE NAMES ${${XPREFIX}_LIBRARIES} + HINTS ${${XPREFIX}_LIBRARY_DIRS} + ) + + +######################################################################## +# Windows +elseif (WIN32) + set(sodium_DIR "$ENV{sodium_DIR}" CACHE FILEPATH "sodium install directory") + mark_as_advanced(sodium_DIR) + + find_path(sodium_INCLUDE_DIR sodium.h + HINTS ${sodium_DIR} + PATH_SUFFIXES include + ) + + if (MSVC) + # detect target architecture + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/arch.cpp" [=[ + #if defined _M_IX86 + #error ARCH_VALUE x86_32 + #elif defined _M_X64 + #error ARCH_VALUE x86_64 + #endif + #error ARCH_VALUE unknown + ]=]) + try_compile(_UNUSED_VAR "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/arch.cpp" + OUTPUT_VARIABLE _COMPILATION_LOG + ) + string(REGEX REPLACE ".*ARCH_VALUE ([a-zA-Z0-9_]+).*" "\\1" _TARGET_ARCH "${_COMPILATION_LOG}") + + # construct library path + if (_TARGET_ARCH STREQUAL "x86_32") + string(APPEND _PLATFORM_PATH "Win32") + elseif(_TARGET_ARCH STREQUAL "x86_64") + string(APPEND _PLATFORM_PATH "x64") + else() + message(FATAL_ERROR "the ${_TARGET_ARCH} architecture is not supported by Findsodium.cmake.") + endif() + string(APPEND _PLATFORM_PATH "/$$CONFIG$$") + + if (MSVC_VERSION LESS 1900) + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 60") + else() + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 50") + endif() + string(APPEND _PLATFORM_PATH "/v${_VS_VERSION}") + + if (sodium_USE_STATIC_LIBS) + string(APPEND _PLATFORM_PATH "/static") + else() + string(APPEND _PLATFORM_PATH "/dynamic") + endif() + + string(REPLACE "$$CONFIG$$" "Debug" _DEBUG_PATH_SUFFIX "${_PLATFORM_PATH}") + string(REPLACE "$$CONFIG$$" "Release" _RELEASE_PATH_SUFFIX "${_PLATFORM_PATH}") + + find_library(sodium_LIBRARY_DEBUG libsodium.lib + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX} + ) + find_library(sodium_LIBRARY_RELEASE libsodium.lib + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX} + ) + if (NOT sodium_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll") + find_library(sodium_DLL_DEBUG libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX} + ) + find_library(sodium_DLL_RELEASE libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX} + ) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK}) + endif() + + elseif(_GCC_COMPATIBLE) + if (sodium_USE_STATIC_LIBS) + find_library(sodium_LIBRARY_DEBUG libsodium.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + find_library(sodium_LIBRARY_RELEASE libsodium.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + else() + find_library(sodium_LIBRARY_DEBUG libsodium.dll.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + find_library(sodium_LIBRARY_RELEASE libsodium.dll.a + HINTS ${sodium_DIR} + PATH_SUFFIXES lib + ) + + file(GLOB _DLL + LIST_DIRECTORIES false + RELATIVE "${sodium_DIR}/bin" + "${sodium_DIR}/bin/libsodium*.dll" + ) + find_library(sodium_DLL_DEBUG ${_DLL} libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES bin + ) + find_library(sodium_DLL_RELEASE ${_DLL} libsodium + HINTS ${sodium_DIR} + PATH_SUFFIXES bin + ) + endif() + else() + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") + endif() + + +######################################################################## +# unsupported +else() + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") +endif() + + +######################################################################## +# common stuff + +# extract sodium version +if (sodium_INCLUDE_DIR) + set(_VERSION_HEADER "${_INCLUDE_DIR}/sodium/version.h") + if (EXISTS _VERSION_HEADER) + file(READ "${_VERSION_HEADER}" _VERSION_HEADER_CONTENT) + string(REGEX REPLACE ".*#[ \t]*define[ \t]*SODIUM_VERSION_STRING[ \t]*\"([^\n]*)\".*" "\\1" + sodium_VERSION "${_VERSION_HEADER_CONTENT}") + set(sodium_VERSION "${sodium_VERSION}" PARENT_SCOPE) + endif() +endif() + +# communicate results +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + sodium # The name must be either uppercase or match the filename case. + REQUIRED_VARS + sodium_LIBRARY_RELEASE + sodium_LIBRARY_DEBUG + sodium_INCLUDE_DIR + VERSION_VAR + sodium_VERSION +) + +if(Sodium_FOUND) + set(sodium_LIBRARIES + optimized ${sodium_LIBRARY_RELEASE} debug ${sodium_LIBRARY_DEBUG}) +endif() + +# mark file paths as advanced +mark_as_advanced(sodium_INCLUDE_DIR) +mark_as_advanced(sodium_LIBRARY_DEBUG) +mark_as_advanced(sodium_LIBRARY_RELEASE) +if (WIN32) + mark_as_advanced(sodium_DLL_DEBUG) + mark_as_advanced(sodium_DLL_RELEASE) +endif() + +# create imported target +if(sodium_USE_STATIC_LIBS) + set(_LIB_TYPE STATIC) +else() + set(_LIB_TYPE SHARED) +endif() + +if(NOT TARGET sodium) + add_library(sodium ${_LIB_TYPE} IMPORTED) +endif() + +set_target_properties(sodium PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${sodium_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" +) + +if (sodium_USE_STATIC_LIBS) + set_target_properties(sodium PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "SODIUM_STATIC" + IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}" + IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}" + ) +else() + if (UNIX) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}" + IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}" + ) + elseif (WIN32) + set_target_properties(sodium PROPERTIES + IMPORTED_IMPLIB "${sodium_LIBRARY_RELEASE}" + IMPORTED_IMPLIB_DEBUG "${sodium_LIBRARY_DEBUG}" + ) + if (NOT (sodium_DLL_DEBUG MATCHES ".*-NOTFOUND")) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION_DEBUG "${sodium_DLL_DEBUG}" + ) + endif() + if (NOT (sodium_DLL_RELEASE MATCHES ".*-NOTFOUND")) + set_target_properties(sodium PROPERTIES + IMPORTED_LOCATION_RELWITHDEBINFO "${sodium_DLL_RELEASE}" + IMPORTED_LOCATION_MINSIZEREL "${sodium_DLL_RELEASE}" + IMPORTED_LOCATION_RELEASE "${sodium_DLL_RELEASE}" + ) + endif() + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..9403a2a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) + +add_library(plugin_ngcft1 SHARED + ./plugin_ngcft1.cpp +) + +target_link_libraries(plugin_ngcft1 PUBLIC + solanaceae_plugin +) + +######################################## +