cmake-conan
cmake-conan copied to clipboard
Incorrect invocation of AppleClang compiler for detecting libcxx.
The code
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
OUTPUT_VARIABLE string_defines
)
causes the following output
-- Conan: Automatic detection of conan settings from cmake
In file included from <stdin>:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:504:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:175:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:641:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:60:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:60:15: fatal error: 'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
1 error generated.
-- Conan: Settings= -s;build_type=Debug;-s;compiler=apple-clang;-s;compiler.version=12.0;-s;compiler.libcxx=libc++
-isysroot should be always specified for AppleClang, see also https://stackoverflow.com/a/63188875.
Fix:
if(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
set(compile_options -isysroot ${CMAKE_OSX_SYSROOT} ${compile_options})
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
OUTPUT_VARIABLE string_defines
)
Patch for macOS and iOS:
--- conan.cmake
+++ conan.cmake
@@ -264,6 +264,13 @@
endif()
endforeach()
+ if(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
+ set(compile_options -isysroot ${CMAKE_SYSROOT} ${compile_options})
+ if(${CMAKE_SYSTEM_NAME} STREQUAL iOS)
+ set(compile_options ${compile_options} -target arm64-apple-ios${CMAKE_OSX_DEPLOYMENT_TARGET})
+ endif()
+ endif()
+
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
Hi @DmitrySokolov, I think this should have already been fixed by https://github.com/conan-io/cmake-conan/pull/226 that is merged to develop and waiting to be release in 0.16, could you check if that PR fixed the issue? Thanks a lot
Nope. #226 fixes only macOS platform. iOS is still broken. Moreover, CMAKE_OSX_SYSROOT=iphoneos for iOS, it's not a path to SDK.
- The correct variable is
CMAKE_SYSROOT, but this single fix is not enough - Another mandatory option is
-target ...
Hmm...
macOS reguires CMAKE_OSX_SYSROOT, so the patch is
--- conan.cmake
+++ conan.cmake
@@ -264,6 +264,14 @@
endif()
endforeach()
+ if(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
+ if(${CMAKE_SYSTEM_NAME} STREQUAL iOS)
+ set(compile_options -isysroot ${CMAKE_SYSROOT} -target arm64-apple-ios${CMAKE_OSX_DEPLOYMENT_TARGET} ${compile_options})
+ else()
+ set(compile_options -isysroot ${CMAKE_OSX_SYSROOT} ${compile_options})
+ endif()
+ endif()
+
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
Hi, hasn't it been merged?