-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmake_common.txt
76 lines (64 loc) · 2.83 KB
/
cmake_common.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function(compiler_minimum_required COMPILER_ID VERSION)
if(CMAKE_CXX_COMPILER_ID STREQUAL "${COMPILER_ID}")
if("${VERSION}" STREQUAL "UNSUPPORTED")
message(FATAL_ERROR "${COMPILER_ID} compiler is NOT supported")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${VERSION})
message(FATAL_ERROR "${COMPILER_ID} ${VERSION} or later is required. You are running version ${CMAKE_CXX_COMPILER_VERSION}")
endif()
endif()
endfunction()
macro(check_connection)
if(CHECK_CONNECTION)
if(UNIX AND NOT APPLE)
execute_process(COMMAND ping conan.io -c 2 -w 1000 RESULT_VARIABLE NO_CONNECTION OUTPUT_QUIET ERROR_QUIET)
elseif(APPLE)
execute_process(COMMAND ping conan.io -c 2 -W 1000 RESULT_VARIABLE NO_CONNECTION OUTPUT_QUIET ERROR_QUIET)
endif()
endif()
endmacro()
function(setup_conan)
if(NOT USE_CONAN)
return()
endif()
check_connection()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" PARENT_SCOPE)
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake" AND NOT NO_CONNECTION)
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/0.18.1/conan.cmake" "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake" TLS_VERIFY ON)
endif()
include(conan)
if(NOT CONAN_PACKAGES)
if(APPLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/packages_macos.txt)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/packages_macos.txt CONAN_PACKAGES)
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/packages.txt)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/packages.txt CONAN_PACKAGES)
else()
message(FATAL_ERROR "require CONAN_PACKAGES variable or packages.txt file")
endif()
endif()
conan_cmake_configure(REQUIRES ${CONAN_PACKAGES} GENERATORS cmake_find_package)
set(PROJECT_BUILD_TYPE ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE Release)
conan_cmake_autodetect(CONAN_SETTINGS)
set(CMAKE_BUILD_TYPE ${PROJECT_BUILD_TYPE})
# HACK: remove c++ standard version from conan settings to use prebuilt binaries
string(REPLACE ";compiler.cppstd=20" "" CONAN_SETTINGS "${CONAN_SETTINGS}")
if(NOT NO_CONNECTION)
conan_cmake_install(PATH_OR_REFERENCE . BUILD missing REMOTE conancenter SETTINGS ${CONAN_SETTINGS})
endif()
endfunction()
macro(setup_macos_path)
if(APPLE)
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(BREW_ROOT "/usr/local/opt")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set(BREW_ROOT "/opt/homebrew/opt")
endif()
set(BOOST_ROOT "${BREW_ROOT}/boost" CACHE STRING "boost root directory")
set(OPENSSL_ROOT_DIR "${BREW_ROOT}/openssl" CACHE STRING "openssl root directory")
endif()
endmacro()