Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect invocation of AppleClang compiler for detecting libcxx. #296

Open
DmitrySokolov opened this issue Nov 12, 2020 · 5 comments
Open

Comments

@DmitrySokolov
Copy link

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
    )
@DmitrySokolov
Copy link
Author

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 -

@czoido
Copy link
Contributor

czoido commented Nov 13, 2020

Hi @DmitrySokolov,
I think this should have already been fixed by #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

@DmitrySokolov
Copy link
Author

Nope. #226 fixes only macOS platform. iOS is still broken. Moreover, CMAKE_OSX_SYSROOT=iphoneos for iOS, it's not a path to SDK.

  1. The correct variable is CMAKE_SYSROOT, but this single fix is not enough
  2. Another mandatory option is -target ...

@DmitrySokolov
Copy link
Author

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 -

@ink-splatters
Copy link

Hi, hasn't it been merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants