summaryrefslogtreecommitdiff
path: root/cmake/ModulePackage.cmake
diff options
context:
space:
mode:
authorRobin Linden <dev@robinlinden.eu>2020-05-14 01:50:43 +0200
committerRobin Linden <dev@robinlinden.eu>2020-05-29 15:36:26 +0200
commit56992b099eb5b77adfca15678ada9ec4011d8dd3 (patch)
tree4500cb5650fccff7294de22a2f72743984292d83 /cmake/ModulePackage.cmake
parent03a511482ffa643a636cd5bcce596f110ca2d8e0 (diff)
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
Diffstat (limited to 'cmake/ModulePackage.cmake')
-rw-r--r--cmake/ModulePackage.cmake48
1 files changed, 33 insertions, 15 deletions
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()
21 21
22find_package(PkgConfig) 22find_package(PkgConfig)
23 23
24function(pkg_use_module mod pkg) 24function(pkg_use_module mod pkgs)
25 if(PKG_CONFIG_FOUND) 25 foreach(pkg IN ITEMS ${pkgs})
26 pkg_search_module(${mod} ${pkg}) 26 if(PKG_CONFIG_FOUND)
27 endif() 27 pkg_search_module(${mod} ${pkg})
28 if(${mod}_FOUND) 28 endif()
29 link_directories(${${mod}_LIBRARY_DIRS}) 29 if(NOT ${mod}_FOUND)
30 include_directories(${${mod}_INCLUDE_DIRS}) 30 find_package(${pkg} QUIET)
31 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE) 31 # This is very very ugly, but the variables are sometimes used in this scope
32 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE) 32 # and sometimes in the parent scope, so we have to set them to both places.
33 33 set(${mod}_FOUND ${${pkg}_FOUND})
34 foreach(dir ${${mod}_INCLUDE_DIRS}) 34 set(${mod}_FOUND ${${pkg}_FOUND} PARENT_SCOPE)
35 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE) 35 set(${mod}_LIBRARIES ${${pkg}_LIBS})
36 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE) 36 set(${mod}_LIBRARIES ${${pkg}_LIBS} PARENT_SCOPE)
37 endforeach() 37 set(${mod}_LIBRARY_DIRS ${${pkg}_LIBRARY_DIRS})
38 endif() 38 set(${mod}_LIBRARY_DIRS ${${pkg}_LIBRARY_DIRS} PARENT_SCOPE)
39 set(${mod}_INCLUDE_DIRS ${${pkg}_INCLUDE_DIRS})
40 set(${mod}_INCLUDE_DIRS ${${pkg}_INCLUDE_DIRS} PARENT_SCOPE)
41 endif()
42 if(${mod}_FOUND)
43 link_directories(${${mod}_LIBRARY_DIRS})
44 include_directories(${${mod}_INCLUDE_DIRS})
45 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
46 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
47
48 if(NOT MSVC)
49 foreach(dir ${${mod}_INCLUDE_DIRS})
50 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE)
51 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE)
52 endforeach()
53 endif()
54 break()
55 endif()
56 endforeach()
39endfunction() 57endfunction()
40 58
41function(add_module lib) 59function(add_module lib)