CMake fixes: libuv static build, base_libs, shared lib install dir (#1431)

* Update how we build libuv

- Update submoduled libuv to latest stable (1.40.0)
- Don't look for a system libuv if we're under BUILD_STATIC_DEPS
- Add a libuv interface library rather than using globals
- Make the windows build fall back to the submodule if not explicitly
  given a LIBUV_ROOT

* Replace ${LIBS} global with `base_libs` interface

This simplifies linking and include handling a bit.

* Remove unneeded header

* Add missing csignal header

(This was previously being pulled in incredibly indirectly via some
stuff that eventually includes some other stuff that eventually included
uv.h)

* Use GNUInstallDirs to get lib dir instead of hard-coding lib

Fixes #1429
pull/1433/head
Jason Rhinelander 4 years ago committed by GitHub
parent 4e2ba1a96c
commit e47b70a82f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -271,17 +271,19 @@ if (NOT BUILD_STATIC_DEPS)
target_link_libraries(libunbound INTERFACE PkgConfig::UNBOUND)
endif()
pkg_check_modules(SD libsystemd)
pkg_check_modules(SD libsystemd IMPORTED_TARGET)
# Default WITH_SYSTEMD to true if we found it
option(WITH_SYSTEMD "enable systemd integration for sd_notify" ${SD_FOUND})
# Base interface target where we set up global link libraries, definitions, includes, etc.
add_library(base_libs INTERFACE)
if(WITH_SYSTEMD AND (NOT ANDROID))
if(NOT SD_FOUND)
message(FATAL_ERROR "libsystemd not found")
endif()
add_definitions(-DWITH_SYSTEMD)
include_directories(${SD_INCLUDE_DIRS})
set(SD_LIBS ${SD_LDFLAGS})
target_link_libraries(base_libs INTERFACE PkgConfig::SD)
target_compile_definitions(base_libs INTERFACE WITH_SYSTEMD)
endif()
option(SUBMODULE_CHECK "Enables checking that vendored library submodules are up to date" ON)
@ -331,14 +333,13 @@ include_directories(SYSTEM external/sqlite_orm/include)
add_subdirectory(vendor)
if(ANDROID)
list(APPEND LIBS log)
add_definitions(-DANDROID)
target_link_libraries(base_libs INTERFACE log)
target_compile_definitions(base_libs INTERFACE ANDROID)
set(ANDROID_PLATFORM_SRC android/ifaddrs.c)
endif()
set(LIBS ${MALLOC_LIB} ${LIBUV_LIBRARY} ${SD_LIBS})
if(TRACY_ROOT)
list(APPEND LIBS -ldl)
target_link_libraries(base_libs INTERFACE dl)
endif()
if(WITH_HIVE)

@ -24,29 +24,21 @@ if (STATIC_LINK_RUNTIME OR STATIC_LINK)
endif()
option(DOWNLOAD_UV "statically compile in libuv" OFF)
# Allow -DDOWNLOAD_UV=FORCE to download without even checking for a local libuv
if(NOT DOWNLOAD_UV STREQUAL "FORCE")
option(NO_SYSTEM_LIBUV "statically compile libuv without even trying to find a system copy" OFF)
add_library(libuv INTERFACE)
if(NOT BUILD_STATIC_DEPS)
find_package(LibUV 1.28.0)
endif()
if(LibUV_FOUND)
message(STATUS "using system libuv")
elseif(DOWNLOAD_UV)
message(STATUS "using libuv submodule")
set(LIBUV_ROOT ${CMAKE_SOURCE_DIR}/external/libuv)
add_subdirectory(${LIBUV_ROOT})
set(LIBUV_INCLUDE_DIRS ${LIBUV_ROOT}/include)
set(LIBUV_LIBRARY uv_a)
if(NOT ANDROID)
add_definitions(-D_LARGEFILE_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64)
endif()
target_link_libraries(libuv INTERFACE ${LIBUV_LIBRARIES})
target_include_directories(libuv INTERFACE ${LIBUV_INCLUDE_DIRS})
else()
message(FATAL_ERROR "libuv not found use -DDOWNLOAD_UV=FORCE to use the submodule")
message(STATUS "using libuv submodule")
add_subdirectory(${PROJECT_SOURCE_DIR}/external/libuv)
target_link_libraries(libuv INTERFACE uv_a)
endif()
include_directories(${LIBUV_INCLUDE_DIRS})
if(EMBEDDED_CFG OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
link_libatomic()
endif()

@ -29,14 +29,6 @@ if (NOT STATIC_LINK AND NOT MSVC)
message("for release builds, turn on STATIC_LINK in cmake options")
endif()
# win32 is the last platform for which we grab libuv manually
# if you want to use the included submodule do
# cmake .. -G Ninja -DLIBUV_ROOT=../external/libuv.
# otherwise grab mine (github.com/despair86/libuv.git) if you need to run on older hardware
# and clone to win32-setup/libuv
# then
# cmake .. -G Ninja -DLIBUV_ROOT=../win32-setup/libuv
# it is literally upward compatible with current windows 10
if (STATIC_LINK)
set(LIBUV_USE_STATIC ON)
if (WOW64_CROSS_COMPILE)
@ -46,14 +38,26 @@ if (STATIC_LINK)
endif()
endif()
if(LIBUV_ROOT)
add_subdirectory(${LIBUV_ROOT})
set(LIBUV_INCLUDE_DIRS ${LIBUV_ROOT}/include)
set(LIBUV_LIBRARY uv_a)
add_definitions(-D_LARGEFILE_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64)
elseif(NOT LIBUV_IN_SOURCE)
find_package(LibUV 1.28.0 REQUIRED)
# win32 is the last platform for which we grab libuv manually.
# If you want to run on older hardware try github.com/despair86/libuv.git and then:
# cmake .. -G Ninja -DLIBUV_ROOT=/path/to/libuv
# Otherwise we'll try either a system one (if not under BUILD_STATIC_DEPS) or else use the submodule
# in external/libuv.
add_library(libuv INTERFACE)
if(NOT LIBUV_ROOT AND NOT BUILD_STATIC_DEPS)
find_package(LibUV 1.28.0)
endif()
include_directories(${LIBUV_INCLUDE_DIRS})
if(LibUV_FOUND)
message(STATUS "using system libuv")
target_link_libraries(libuv INTERFACE ${LIBUV_LIBRARIES})
target_include_directories(libuv INTERFACE ${LIBUV_INCLUDE_DIRS})
else()
if(LIBUV_ROOT)
add_subdirectory(${LIBUV_ROOT})
else()
add_subdirectory(${PROJECT_SOURCE_DIR}/external/libuv)
endif()
target_link_libraries(libuv INTERFACE uv_a)
target_compile_definitions(libuv INTERFACE _LARGEFILE_SOURCE _FILE_OFFSET_BITS=64)
endif()

2
external/libuv vendored

@ -1 +1 @@
Subproject commit 25f4b8b8a3c0f934158cd37a37b0525d75ca488e
Subproject commit 4e69e333252693bd82d6338d6124f0416538dbfc

@ -64,7 +64,7 @@ add_library(lokinet-platform
$<TARGET_OBJECTS:tuntap>
)
target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography lokinet-util Threads::Threads ${LIBS})
target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography lokinet-util Threads::Threads base_libs libuv)
if (ANDROID)
@ -235,7 +235,9 @@ target_link_libraries(liblokinet PRIVATE libunbound)
if(BUILD_SHARED_LIBS)
install(TARGETS lokinet-util lokinet-platform liblokinet LIBRARY DESTINATION lib)
include(GNUInstallDirs)
install(TARGETS lokinet-util lokinet-platform liblokinet LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(WIN32)
target_link_libraries(liblokinet PUBLIC ws2_32 iphlpapi)
endif()

@ -21,10 +21,6 @@
#include <cstdint>
#include <cstdlib>
#if !defined(WIN32)
#include <uv.h>
#endif
#include <constants/evloop.hpp>
/**

@ -8,6 +8,7 @@
#include <chrono>
#include <algorithm>
#include <csignal>
using namespace std::chrono_literals;

Loading…
Cancel
Save