lokinet/cmake/unix.cmake
Jason Rhinelander e47b70a82f
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
2020-10-28 18:26:43 -04:00

55 lines
1.3 KiB
CMake

if(NOT ANDROID)
if(NOT UNIX)
return()
endif()
endif()
include(CheckCXXSourceCompiles)
include(CheckLibraryExists)
if(WITH_JEMALLOC)
find_package(Jemalloc REQUIRED)
if(NOT JEMALLOC_FOUND)
message(FATAL_ERROR "did not find jemalloc")
endif()
add_definitions(-DUSE_JEMALLOC)
message(STATUS "using jemalloc")
endif()
add_definitions(-DUNIX)
add_definitions(-DPOSIX)
if (STATIC_LINK_RUNTIME OR STATIC_LINK)
set(LIBUV_USE_STATIC ON)
endif()
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")
target_link_libraries(libuv INTERFACE ${LIBUV_LIBRARIES})
target_include_directories(libuv INTERFACE ${LIBUV_INCLUDE_DIRS})
else()
message(STATUS "using libuv submodule")
add_subdirectory(${PROJECT_SOURCE_DIR}/external/libuv)
target_link_libraries(libuv INTERFACE uv_a)
endif()
if(EMBEDDED_CFG OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
link_libatomic()
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
add_definitions(-D_BSD_SOURCE)
add_definitions(-D_GNU_SOURCE)
add_definitions(-D_XOPEN_SOURCE=700)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
if (LIBUV_USE_STATIC)
link_libraries(-lkstat -lsendfile)
endif()
endif()