Merge commit '227425b90e9a671118026689dd30967e127a1090' as 'external/toxcore/c-toxcore'
This commit is contained in:
62
external/toxcore/c-toxcore/cmake/CompileGTest.cmake
vendored
Normal file
62
external/toxcore/c-toxcore/cmake/CompileGTest.cmake
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
# Find and compile the GTest library.
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckIncludeFileCXX)
|
||||
|
||||
message(STATUS "Checking for gtest")
|
||||
|
||||
# Look for the sources.
|
||||
find_file(GTEST_ALL_CC gtest-all.cc PATHS
|
||||
${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/src
|
||||
/usr/src/gtest/src
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if(GTEST_ALL_CC)
|
||||
# ../.. from the source file is the source root.
|
||||
get_filename_component(GTEST_SRC_DIR ${GTEST_ALL_CC} DIRECTORY)
|
||||
get_filename_component(GTEST_SRC_ROOT ${GTEST_SRC_DIR} DIRECTORY)
|
||||
|
||||
# Look for the header file.
|
||||
include(CheckIncludeFileCXX)
|
||||
include_directories(SYSTEM ${GTEST_SRC_ROOT}/include)
|
||||
check_include_file_cxx("gtest/gtest.h" HAVE_GTEST_GTEST_H)
|
||||
|
||||
if(HAVE_GTEST_GTEST_H)
|
||||
message(STATUS "Found gtest: ${GTEST_SRC_ROOT}")
|
||||
|
||||
add_library(gtest
|
||||
${GTEST_SRC_DIR}/gtest-all.cc
|
||||
${GTEST_SRC_DIR}/gtest_main.cc)
|
||||
target_include_directories(gtest PRIVATE ${GTEST_SRC_ROOT})
|
||||
|
||||
# Ignore all warnings for gtest. We don't care about their implementation.
|
||||
check_cxx_compiler_flag("-w" HAVE_CXX_W QUIET)
|
||||
if(HAVE_CXX_W)
|
||||
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
|
||||
endif()
|
||||
|
||||
set(HAVE_GTEST TRUE)
|
||||
set(TEST_CXX_FLAGS "")
|
||||
|
||||
check_cxx_compiler_flag("-Wno-global-constructors" HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS QUIET)
|
||||
if(HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS)
|
||||
set(TEST_CXX_FLAGS "${TEST_CXX_FLAGS} -Wno-global-constructors")
|
||||
endif()
|
||||
|
||||
check_cxx_compiler_flag("-Wno-zero-as-null-pointer-constant" HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT QUIET)
|
||||
if(HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT)
|
||||
set(TEST_CXX_FLAGS "${TEST_CXX_FLAGS} -Wno-zero-as-null-pointer-constant")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
function(unit_test subdir target)
|
||||
if(HAVE_GTEST)
|
||||
add_executable(unit_${target}_test ${subdir}/${target}_test.cc)
|
||||
target_link_modules(unit_${target}_test toxcore gtest)
|
||||
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
|
||||
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
|
||||
set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw")
|
||||
endif()
|
||||
endfunction()
|
76
external/toxcore/c-toxcore/cmake/Dependencies.cmake
vendored
Normal file
76
external/toxcore/c-toxcore/cmake/Dependencies.cmake
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
###############################################################################
|
||||
#
|
||||
# :: For UNIX-like systems that have pkg-config.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
include(ModulePackage)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
find_library(NSL_LIBRARIES nsl )
|
||||
find_library(RT_LIBRARIES rt )
|
||||
find_library(SOCKET_LIBRARIES socket )
|
||||
|
||||
# For toxcore.
|
||||
pkg_use_module(LIBSODIUM libsodium )
|
||||
|
||||
# For toxav.
|
||||
pkg_use_module(OPUS "opus;Opus" )
|
||||
pkg_use_module(VPX "vpx;libvpx" )
|
||||
|
||||
# For tox-bootstrapd.
|
||||
pkg_use_module(LIBCONFIG libconfig )
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# :: For MSVC Windows builds.
|
||||
#
|
||||
# These require specific installation paths of dependencies:
|
||||
# - libsodium in third-party/libsodium/Win32/Release/v140/dynamic
|
||||
# - pthreads in third-party/pthreads-win32/Pre-built.2
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
if(MSVC)
|
||||
# libsodium
|
||||
# ---------
|
||||
if(NOT LIBSODIUM_FOUND)
|
||||
find_library(LIBSODIUM_LIBRARIES
|
||||
NAMES sodium libsodium
|
||||
PATHS
|
||||
"third_party/libsodium/Win32/Release/v140/dynamic"
|
||||
"third_party/libsodium/x64/Release/v140/dynamic"
|
||||
)
|
||||
if(LIBSODIUM_LIBRARIES)
|
||||
include_directories("third_party/libsodium/include")
|
||||
set(LIBSODIUM_FOUND TRUE)
|
||||
message("libsodium: ${LIBSODIUM_LIBRARIES}")
|
||||
else()
|
||||
message(FATAL_ERROR "libsodium libraries not found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# pthreads
|
||||
# --------
|
||||
if(CMAKE_USE_WIN32_THREADS_INIT)
|
||||
find_library(CMAKE_THREAD_LIBS_INIT
|
||||
NAMES pthreadVC2
|
||||
PATHS
|
||||
"third_party/pthreads-win32/Pre-built.2/lib/x86"
|
||||
"third_party/pthreads-win32/Pre-built.2/lib/x64"
|
||||
)
|
||||
if(CMAKE_THREAD_LIBS_INIT)
|
||||
include_directories("third_party/pthreads-win32/Pre-built.2/include")
|
||||
add_definitions(-DHAVE_STRUCT_TIMESPEC)
|
||||
message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}")
|
||||
else()
|
||||
find_package(pthreads4w)
|
||||
if(NOT pthreads4w_FOUND)
|
||||
message(FATAL_ERROR "libpthreads libraries not found")
|
||||
endif()
|
||||
include_directories(${pthreads4w_INCLUDE_DIR})
|
||||
link_libraries(${pthreads4w_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
24
external/toxcore/c-toxcore/cmake/MacRpath.cmake
vendored
Normal file
24
external/toxcore/c-toxcore/cmake/MacRpath.cmake
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Taken from https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH.
|
||||
#
|
||||
# In many cases you will want to make sure that the required libraries are
|
||||
# always found independent from LD_LIBRARY_PATH and the install location. Then
|
||||
# you can use these settings:
|
||||
|
||||
# Use, i.e. don't skip the full RPATH for the build tree.
|
||||
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||
|
||||
# When building, don't use the install RPATH already
|
||||
# (but later on when installing).
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
||||
|
||||
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
|
||||
|
||||
# Add the automatically determined parts of the RPATH
|
||||
# which point to directories outside the build tree to the install RPATH.
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
# The RPATH to be used when installing, but only if it's not a system directory.
|
||||
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
|
||||
if("${isSystemDir}" STREQUAL "-1")
|
||||
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
|
||||
endif()
|
171
external/toxcore/c-toxcore/cmake/ModulePackage.cmake
vendored
Normal file
171
external/toxcore/c-toxcore/cmake/ModulePackage.cmake
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
option(ENABLE_SHARED "Build shared (dynamic) libraries for all modules" ON)
|
||||
option(ENABLE_STATIC "Build static libraries for all modules" ON)
|
||||
|
||||
if(NOT ENABLE_SHARED AND NOT ENABLE_STATIC)
|
||||
message(WARNING
|
||||
"Both static and shared libraries are disabled; "
|
||||
"enabling only shared libraries. Use -DENABLE_SHARED or -DENABLE_STATIC to "
|
||||
"select one manually.")
|
||||
set(ENABLE_SHARED ON)
|
||||
endif()
|
||||
|
||||
option(FULLY_STATIC "Build fully static executables" OFF)
|
||||
if(FULLY_STATIC)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static -no-pie")
|
||||
# remove -Wl,-Bdynamic
|
||||
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
|
||||
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
|
||||
set(ENABLE_SHARED OFF)
|
||||
set(ENABLE_STATIC ON)
|
||||
endif()
|
||||
|
||||
find_package(PkgConfig)
|
||||
|
||||
function(pkg_use_module mod pkgs)
|
||||
foreach(pkg IN ITEMS ${pkgs})
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_search_module(${mod} ${pkg})
|
||||
endif()
|
||||
if(NOT ${mod}_FOUND)
|
||||
find_package(${pkg} QUIET)
|
||||
# This is very very ugly, but the variables are sometimes used in this scope
|
||||
# and sometimes in the parent scope, so we have to set them to both places.
|
||||
set(${mod}_FOUND ${${pkg}_FOUND})
|
||||
set(${mod}_FOUND ${${pkg}_FOUND} PARENT_SCOPE)
|
||||
set(${mod}_LIBRARIES ${${pkg}_LIBS})
|
||||
set(${mod}_LIBRARIES ${${pkg}_LIBS} PARENT_SCOPE)
|
||||
set(${mod}_LIBRARY_DIRS ${${pkg}_LIBRARY_DIRS})
|
||||
set(${mod}_LIBRARY_DIRS ${${pkg}_LIBRARY_DIRS} PARENT_SCOPE)
|
||||
set(${mod}_INCLUDE_DIRS ${${pkg}_INCLUDE_DIRS})
|
||||
set(${mod}_INCLUDE_DIRS ${${pkg}_INCLUDE_DIRS} PARENT_SCOPE)
|
||||
endif()
|
||||
if(${mod}_FOUND)
|
||||
link_directories(${${mod}_LIBRARY_DIRS})
|
||||
include_directories(${${mod}_INCLUDE_DIRS})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
|
||||
|
||||
if(NOT MSVC)
|
||||
foreach(dir ${${mod}_INCLUDE_DIRS})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endif()
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(add_module lib)
|
||||
set(${lib}_SOURCES ${ARGN} PARENT_SCOPE)
|
||||
|
||||
if(ENABLE_SHARED)
|
||||
add_library(${lib}_shared SHARED ${ARGN})
|
||||
set_target_properties(${lib}_shared PROPERTIES OUTPUT_NAME ${lib})
|
||||
endif()
|
||||
if(ENABLE_STATIC)
|
||||
add_library(${lib}_static STATIC ${ARGN})
|
||||
set_target_properties(${lib}_static PROPERTIES OUTPUT_NAME ${lib})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(install_module lib)
|
||||
if(ENABLE_SHARED)
|
||||
set_target_properties(${lib}_shared PROPERTIES
|
||||
VERSION ${SOVERSION}
|
||||
SOVERSION ${SOVERSION_MAJOR}
|
||||
)
|
||||
install(TARGETS ${lib}_shared
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
if(ENABLE_STATIC)
|
||||
install(TARGETS ${lib}_static
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
string(REPLACE ";" " " ${lib}_PKGCONFIG_LIBS "${${lib}_PKGCONFIG_LIBS}")
|
||||
string(REPLACE ";" " " ${lib}_PKGCONFIG_REQUIRES "${${lib}_PKGCONFIG_REQUIRES}")
|
||||
|
||||
configure_file(
|
||||
"${${lib}_SOURCE_DIR}/other/pkgconfig/${lib}.pc.in"
|
||||
"${CMAKE_BINARY_DIR}/${lib}.pc"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
configure_file(
|
||||
"${toxcore_SOURCE_DIR}/other/rpm/${lib}.spec.in"
|
||||
"${CMAKE_BINARY_DIR}/${lib}.spec"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${CMAKE_BINARY_DIR}/${lib}.pc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
|
||||
foreach(sublib ${${lib}_API_HEADERS})
|
||||
string(REPLACE "^" ";" sublib ${sublib})
|
||||
list(GET sublib 0 header)
|
||||
|
||||
install(FILES ${header} ${ARGN})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(target_link_modules target)
|
||||
# If the target we're adding dependencies to is a shared library, add it to
|
||||
# the set of targets.
|
||||
if(TARGET ${target}_shared)
|
||||
set(_targets ${_targets} ${target}_shared)
|
||||
# Shared libraries should first try to link against other shared libraries.
|
||||
set(${target}_shared_primary shared)
|
||||
# If that fails (because the shared target doesn't exist), try linking
|
||||
# against the static library. This requires the static library's objects to
|
||||
# be PIC.
|
||||
set(${target}_shared_secondary static)
|
||||
endif()
|
||||
# It can also be a static library at the same time.
|
||||
if(TARGET ${target}_static)
|
||||
set(_targets ${_targets} ${target}_static)
|
||||
# Static libraries aren't actually linked, but their dependencies are
|
||||
# recorded by "linking" them. If we link an executable to a static library,
|
||||
# we want to also link statically against its transitive dependencies.
|
||||
set(${target}_static_primary static)
|
||||
# If a dependency doesn't exist as static library, we link against the
|
||||
# shared one.
|
||||
set(${target}_static_secondary shared)
|
||||
endif()
|
||||
# If it's neither, then it's an executable.
|
||||
if(NOT _targets)
|
||||
set(_targets ${_targets} ${target})
|
||||
# Executables preferably link against static libraries, so they are
|
||||
# standalone and can be shipped without any external dependencies. As a
|
||||
# frame of reference: tests become roughly 600-800K binaries instead of
|
||||
# 50-100K on x86_64 Linux.
|
||||
set(${target}_primary static)
|
||||
set(${target}_secondary shared)
|
||||
endif()
|
||||
|
||||
foreach(dep ${ARGN})
|
||||
foreach(_target ${_targets})
|
||||
if(TARGET ${dep}_${${_target}_primary})
|
||||
target_link_libraries(${_target} ${dep}_${${_target}_primary})
|
||||
elseif(TARGET ${dep}_${${_target}_secondary})
|
||||
target_link_libraries(${_target} ${dep}_${${_target}_secondary})
|
||||
else()
|
||||
# We record the modules linked to this target, so that we can collect
|
||||
# them later when linking a composed module.
|
||||
list(FIND LINK_MODULES ${dep} _index)
|
||||
if(_index EQUAL -1)
|
||||
set(LINK_MODULES ${LINK_MODULES} ${dep})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${_target} ${dep})
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
set(${target}_LINK_MODULES ${${target}_LINK_MODULES} ${LINK_MODULES} PARENT_SCOPE)
|
||||
endfunction()
|
76
external/toxcore/c-toxcore/cmake/StrictAbi.cmake
vendored
Normal file
76
external/toxcore/c-toxcore/cmake/StrictAbi.cmake
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
################################################################################
|
||||
#
|
||||
# :: Strict ABI
|
||||
#
|
||||
# Enabling the STRICT_ABI flag will generate and use an LD version script.
|
||||
# It ensures that the dynamic libraries (libtoxcore.so, libtoxav.so) only
|
||||
# export the symbols that are defined in their public API (tox.h and toxav.h,
|
||||
# respectively).
|
||||
#
|
||||
################################################################################
|
||||
|
||||
find_program(SHELL NAMES sh dash bash zsh fish)
|
||||
|
||||
macro(make_version_script)
|
||||
if(STRICT_ABI AND SHELL AND ENABLE_SHARED)
|
||||
_make_version_script(${ARGN})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(_make_version_script target)
|
||||
set(${target}_VERSION_SCRIPT "${CMAKE_BINARY_DIR}/${target}.ld")
|
||||
|
||||
file(WRITE ${${target}_VERSION_SCRIPT}
|
||||
"{ global:\n")
|
||||
|
||||
foreach(sublib ${ARGN})
|
||||
string(REPLACE "^" ";" sublib ${sublib})
|
||||
list(GET sublib 0 header)
|
||||
list(GET sublib 1 ns)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '\\w+' | sort -u"
|
||||
OUTPUT_VARIABLE sublib_SYMS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
|
||||
|
||||
foreach(sym ${sublib_SYMS})
|
||||
file(APPEND ${${target}_VERSION_SCRIPT}
|
||||
"${sym};\n")
|
||||
endforeach(sym)
|
||||
endforeach(sublib)
|
||||
|
||||
file(APPEND ${${target}_VERSION_SCRIPT}
|
||||
"local: *; };\n")
|
||||
|
||||
set_target_properties(${target}_shared PROPERTIES
|
||||
LINK_FLAGS -Wl,--version-script,${${target}_VERSION_SCRIPT})
|
||||
endfunction()
|
||||
|
||||
option(STRICT_ABI "Enforce strict ABI export in dynamic libraries" OFF)
|
||||
if(WIN32 OR APPLE)
|
||||
# Windows and OSX don't have this linker functionality.
|
||||
set(STRICT_ABI OFF)
|
||||
endif()
|
||||
|
||||
if(STRICT_ABI AND NOT ENABLE_STATIC)
|
||||
if(AUTOTEST)
|
||||
message("AUTOTEST option is incompatible with STRICT_ABI. Disabling AUTOTEST.")
|
||||
endif()
|
||||
set(AUTOTEST OFF)
|
||||
|
||||
if(BUILD_MISC_TESTS)
|
||||
message("BUILD_MISC_TESTS option is incompatible with STRICT_ABI. Disabling BUILD_MISC_TESTS.")
|
||||
endif()
|
||||
set(BUILD_MISC_TESTS OFF)
|
||||
|
||||
if(BOOTSTRAP_DAEMON)
|
||||
message("BOOTSTRAP_DAEMON option is incompatible with STRICT_ABI. Disabling BOOTSTRAP_DAEMON.")
|
||||
endif()
|
||||
set(BOOTSTRAP_DAEMON OFF)
|
||||
|
||||
if(DHT_BOOTSTRAP)
|
||||
message("DHT_BOOTSTRAP option is incompatible with STRICT_ABI. Disabling DHT_BOOTSTRAP.")
|
||||
endif()
|
||||
set(DHT_BOOTSTRAP OFF)
|
||||
endif()
|
Reference in New Issue
Block a user