-
Notifications
You must be signed in to change notification settings - Fork 8
/
conanbuildinfo.cmake
184 lines (165 loc) · 8.53 KB
/
conanbuildinfo.cmake
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
set(CONAN_INCLUDE_DIRS ${CONAN_INCLUDE_DIRS})
set(CONAN_LIB_DIRS ${CONAN_LIB_DIRS})
set(CONAN_BIN_DIRS ${CONAN_BIN_DIRS})
set(CONAN_LIBS ${CONAN_LIBS})
set(CONAN_DEFINES ${CONAN_DEFINES})
set(CONAN_CXX_FLAGS " ${CONAN_CXX_FLAGS}")
set(CONAN_SHARED_LINKER_FLAGS " ${CONAN_SHARED_LINKER_FLAGS}")
set(CONAN_EXE_LINKER_FLAGS " ${CONAN_EXE_LINKER_FLAGS}")
set(CONAN_C_FLAGS " ${CONAN_C_FLAGS}")
set(CONAN_CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH})
macro(conan_basic_setup)
conan_check_compiler()
conan_output_dirs_setup()
conan_flags_setup()
# CMake can find findXXX.cmake files in the root of packages
set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})
endmacro()
macro(conan_flags_setup)
include_directories(SYSTEM ${CONAN_INCLUDE_DIRS})
link_directories(${CONAN_LIB_DIRS})
add_definitions(${CONAN_DEFINES})
# For find_library
set(CMAKE_INCLUDE_PATH ${CONAN_INCLUDE_DIRS} ${CMAKE_INCLUDE_PATH})
set(CMAKE_LIBRARY_PATH ${CONAN_LIB_DIRS} ${CMAKE_LIBRARY_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CONAN_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CONAN_C_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CONAN_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CONAN_EXE_LINKER_FLAGS}")
if(APPLE)
# https://cmake.org/Wiki/CMake_RPATH_handling
# CONAN GUIDE: All generated libraries should have the id and dependencies to other
# dylibs without path, just the name, EX:
# libMyLib1.dylib:
# libMyLib1.dylib (compatibility version 0.0.0, current version 0.0.0)
# libMyLib0.dylib (compatibility version 0.0.0, current version 0.0.0)
# /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
# /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
set(CMAKE_SKIP_RPATH 1) # AVOID RPATH FOR *.dylib, ALL LIBS BETWEEN THEM AND THE EXE
# SHOULD BE ON THE LINKER RESOLVER PATH (./ IS ONE OF THEM)
endif()
if(CONAN_LINK_RUNTIME)
if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
string(REPLACE "/MD" ${CONAN_LINK_RUNTIME} CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
endif()
if(DEFINED CMAKE_CXX_FLAGS_DEBUG)
string(REPLACE "/MDd" ${CONAN_LINK_RUNTIME} CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif()
if(DEFINED CMAKE_C_FLAGS_RELEASE)
string(REPLACE "/MD" ${CONAN_LINK_RUNTIME} CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
endif()
if(DEFINED CMAKE_C_FLAGS_DEBUG)
string(REPLACE "/MDd" ${CONAN_LINK_RUNTIME} CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
endif()
endif()
if(DEFINED CONAN_LIBCXX)
message(STATUS "Conan C++ stdlib: ${CONAN_LIBCXX}")
if(CONAN_COMPILER STREQUAL "clang" OR CONAN_COMPILER STREQUAL "apple-clang")
if(CONAN_LIBCXX STREQUAL "libstdc++" OR CONAN_LIBCXX STREQUAL "libstdc++11" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
elseif(CONAN_LIBCXX STREQUAL "libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()
if(CONAN_LIBCXX STREQUAL "libstdc++11")
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
elseif(CONAN_LIBCXX STREQUAL "libstdc++")
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()
endif()
endmacro()
macro(conan_output_dirs_setup)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
endmacro()
macro(conan_split_version VERSION_STRING MAJOR MINOR)
#make a list from the version string
string(REPLACE "." ";" VERSION_LIST ${${VERSION_STRING}})
#write output values
list(GET VERSION_LIST 0 ${MAJOR})
list(GET VERSION_LIST 1 ${MINOR})
endmacro()
macro(conan_error_compiler_version)
message(FATAL_ERROR "Incorrect '${CONAN_COMPILER}' version 'compiler.version=${CONAN_COMPILER_VERSION}'"
" is not the one detected by CMake: '${CMAKE_CXX_COMPILER_ID}=" ${VERSION_MAJOR}.${VERSION_MINOR}')
endmacro()
set(_CONAN_CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR})
function(conan_get_compiler CONAN_INFO_COMPILER CONAN_INFO_COMPILER_VERSION)
MESSAGE(STATUS "Current conanbuildinfo.cmake directory: " ${_CONAN_CURRENT_DIR})
if(NOT EXISTS ${_CONAN_CURRENT_DIR}/conaninfo.txt)
message(STATUS "WARN: conaninfo.txt not found")
return()
endif()
file (READ "${_CONAN_CURRENT_DIR}/conaninfo.txt" CONANINFO)
string(REGEX MATCH "compiler=([A-Za-z0-9_ ]+)" _MATCHED ${CONANINFO})
if(DEFINED CMAKE_MATCH_1)
string(STRIP ${CMAKE_MATCH_1} _CONAN_INFO_COMPILER)
set(${CONAN_INFO_COMPILER} ${_CONAN_INFO_COMPILER} PARENT_SCOPE)
endif()
string(REGEX MATCH "compiler.version=([-A-Za-z0-9_.]+)" _MATCHED ${CONANINFO})
if(DEFINED CMAKE_MATCH_1)
string(STRIP ${CMAKE_MATCH_1} _CONAN_INFO_COMPILER_VERSION)
set(${CONAN_INFO_COMPILER_VERSION} ${_CONAN_INFO_COMPILER_VERSION} PARENT_SCOPE)
endif()
endfunction()
function(check_compiler_version)
CONAN_SPLIT_VERSION(CMAKE_CXX_COMPILER_VERSION VERSION_MAJOR VERSION_MINOR)
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
# https://cmake.org/cmake/help/v3.2/variable/MSVC_VERSION.html
if( (CONAN_COMPILER_VERSION STREQUAL "14" AND NOT VERSION_MAJOR STREQUAL "19") OR
(CONAN_COMPILER_VERSION STREQUAL "12" AND NOT VERSION_MAJOR STREQUAL "18") OR
(CONAN_COMPILER_VERSION STREQUAL "11" AND NOT VERSION_MAJOR STREQUAL "17") OR
(CONAN_COMPILER_VERSION STREQUAL "10" AND NOT VERSION_MAJOR STREQUAL "16") OR
(CONAN_COMPILER_VERSION STREQUAL "9" AND NOT VERSION_MAJOR STREQUAL "15") OR
(CONAN_COMPILER_VERSION STREQUAL "8" AND NOT VERSION_MAJOR STREQUAL "14") OR
(CONAN_COMPILER_VERSION STREQUAL "7" AND NOT VERSION_MAJOR STREQUAL "13") OR
(CONAN_COMPILER_VERSION STREQUAL "6" AND NOT VERSION_MAJOR STREQUAL "12") )
conan_error_compiler_version()
endif()
elseif(CONAN_COMPILER STREQUAL "gcc" OR CONAN_COMPILER MATCHES "Clang")
if(NOT ${VERSION_MAJOR}.${VERSION_MINOR} VERSION_EQUAL CONAN_COMPILER_VERSION)
conan_error_compiler_version()
endif()
else()
message("Skipping version checking of not detected compiler...")
endif()
endfunction()
function(conan_check_compiler)
if(NOT DEFINED CMAKE_CXX_COMPILER_ID)
if(DEFINED CMAKE_C_COMPILER_ID)
message(STATUS "This project seems to be plain C, using '${CMAKE_C_COMPILER_ID}' compiler")
set(CMAKE_CXX_COMPILER_ID ${CMAKE_C_COMPILER_ID})
set(CMAKE_CXX_COMPILER_VERSION ${CMAKE_C_COMPILER_VERSION})
else()
message(FATAL_ERROR "This project seems to be plain C, but no compiler defined")
endif()
endif()
if(CONAN_DISABLE_CHECK_COMPILER)
message(STATUS "WARN: Disabled conan compiler checks")
return()
endif()
if(NOT DEFINED CONAN_COMPILER)
conan_get_compiler(CONAN_COMPILER CONAN_COMPILER_VERSION)
if(NOT DEFINED CONAN_COMPILER)
message(STATUS "WARN: CONAN_COMPILER variable not set, please make sure yourself that "
"your compiler and version matches your declared settings")
return()
endif()
endif()
if( (CONAN_COMPILER STREQUAL "Visual Studio" AND NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC) OR
(CONAN_COMPILER STREQUAL "gcc" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR
(CONAN_COMPILER STREQUAL "apple-clang" AND (NOT APPLE OR NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")) OR
(CONAN_COMPILER STREQUAL "clang" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") )
message(FATAL_ERROR "Incorrect '${CONAN_COMPILER}', is not the one detected by CMake: '${CMAKE_CXX_COMPILER_ID}'")
endif()
if(NOT DEFINED CONAN_COMPILER_VERSION)
message(STATUS "WARN: CONAN_COMPILER_VERSION variable not set, please make sure yourself "
"that your compiler version matches your declared settings")
return()
endif()
check_compiler_version()
endfunction()