From 56992b099eb5b77adfca15678ada9ec4011d8dd3 Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Thu, 14 May 2020 01:50:43 +0200 Subject: Add support for the conan C/C++ package manager * Don't overwrite the CMAKE_MODULE_PATH * Allow linking libsodium statically with MSVC * Allow finding libsodium the normal way on MSVC * Allow using pthreads4w for pthreads on MSVC * Fall back to find_package if pkg_find_module fails * Don't pass incompatible compile flags to MSVC * Also try to find Opus and libvpx using their canonical names * Support building using conan * Allow pkg_use_module to take a list of libraries to look for * Build for Windows on Appveyor using conan --- cmake/Dependencies.cmake | 37 +++++++++++++++++++++--------------- cmake/ModulePackage.cmake | 48 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 30 deletions(-) (limited to 'cmake') diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 8361e8e1..37eb40bd 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -16,8 +16,8 @@ find_library(SOCKET_LIBRARIES socket ) pkg_use_module(LIBSODIUM libsodium ) # For toxav. -pkg_use_module(OPUS opus ) -pkg_use_module(VPX vpx ) +pkg_use_module(OPUS "opus;Opus" ) +pkg_use_module(VPX "vpx;libvpx" ) # For tox-bootstrapd. pkg_use_module(LIBCONFIG libconfig ) @@ -38,18 +38,20 @@ pkg_use_module(MSGPACK msgpack ) if(MSVC) # libsodium # --------- - 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") + 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 @@ -66,7 +68,12 @@ if(MSVC) add_definitions(-DHAVE_STRUCT_TIMESPEC) message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}") else() - message(FATAL_ERROR "libpthreads libraries not found") + 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() diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake index 9cc21863..04dbf16d 100644 --- a/cmake/ModulePackage.cmake +++ b/cmake/ModulePackage.cmake @@ -21,21 +21,39 @@ endif() find_package(PkgConfig) -function(pkg_use_module mod pkg) - if(PKG_CONFIG_FOUND) - pkg_search_module(${mod} ${pkg}) - 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) - - 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() +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) -- cgit v1.2.3