CMake > 3.15 adds extra isystem flag for iOS and build fails
After migrating from cmake 3.14 to 3.15 our project stopped compile (xcode 10.3 and xcode 11 beta). I traced generated build log and found that CMake 3.15 adds new extra flag:
-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include
Which leads to error, because there are two math.h headers:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/math.h
First one includes second one, but not vice versa. So when flag -isystem ... is added second file is found because isystem changes priority and first file not processed.
Update
I spent time to find the root of the problem, so here is all what I've found. The issue appears when ZLIB is linked to static library and static library links to framework. The simple example consist of:
- One file dummy.cpp with included header:
#include <cmath>
bool foo(double arg) {
return std::isfinite(arg);
}
- One dummy.swift file with any code:
func foo() {
}
- CMake script:
cmake_minimum_required (VERSION 3.14)
enable_language (Swift)
set (CMAKE_Swift_LANGUAGE_VERSION 5.0)
find_package(ZLIB REQUIRED)
add_library (framework_dependency STATIC)
target_sources (framework_dependency PRIVATE dummy.cpp)
target_link_libraries(framework_dependency INTERFACE ZLIB::ZLIB)
add_library (framework_test SHARED dummy.cpp dummy.swift)
target_link_libraries (framework_test PRIVATE framework_dependency)
set_target_properties (framework_test PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION A
MACOSX_FRAMEWORK_IDENTIFIER "framework.test"
VERSION "1.0"
SOVERSION 1.0
)
I run configuration as:
cmake -GXcode -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=x86_64 ..
Then build:
cmake --build . --target framework_test --config Debug
And I have next errors:
CompileC build/Project.build/Debug-iphonesimulator/framework_test.build/Objects-normal/x86_64/dummy-DD511A566D3B06C7.o dummy.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler cd /projects/cmake_issue_cmath /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=220 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR="Debug-iphonesimulator" -Dframework_test_EXPORTS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mios-simulator-version-min=12.4 -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/projects/cmake_issue_cmath/build/Debug-iphonesimulator/include -isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include -I/projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/DerivedSources-normal/x86_64 -I/projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/DerivedSources/x86_64 -I/projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/projects/cmake_issue_cmath/build/Debug-iphonesimulator -fPIC -MMD -MT dependencies -MF /projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/Objects-normal/x86_64/dummy-DD511A566D3B06C7.d --serialize-diagnostics /projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/Objects-normal/x86_64/dummy-DD511A566D3B06C7.dia -c /projects/cmake_issue_cmath/dummy.cpp -o /projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/Objects-normal/x86_64/dummy-DD511A566D3B06C7.o In file included from /projects/cmake_issue_cmath/dummy.cpp:2: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace using ::signbit; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace using ::fpclassify; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:315:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'? using ::isfinite; ~~^ In file included from /projects/cmake_issue_cmath/dummy.cpp:2: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:305: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/math.h:749:12: note: 'finite' declared here extern int finite(double) ^ In file included from /projects/cmake_issue_cmath/dummy.cpp:2: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:316:9: error: no member named 'isinf' in the global namespace using ::isinf; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:317:9: error: no member named 'isnan' in the global namespace using ::isnan; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:318:9: error: no member named 'isnormal' in the global namespace using ::isnormal; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:319:9: error: no member named 'isgreater' in the global namespace using ::isgreater; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:320:9: error: no member named 'isgreaterequal' in the global namespace using ::isgreaterequal; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:321:9: error: no member named 'isless' in the global namespace using ::isless; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:322:9: error: no member named 'islessequal' in the global namespace using ::islessequal; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:323:9: error: no member named 'islessgreater' in the global namespace using ::islessgreater; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:324:9: error: no member named 'isunordered' in the global namespace using ::isunordered; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace using ::isunordered; ~~^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:331:9: error: no member named 'abs' in the global namespace; did you mean 'fabs'? using ::abs; ~~^ In file included from /projects/cmake_issue_cmath/dummy.cpp:2: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:305: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include/math.h:417:15: note: 'fabs' declared here extern double fabs(double); ^ In file included from /projects/cmake_issue_cmath/dummy.cpp:2: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:551:28: error: expected a qualified name after 'typename' _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:551:37: error: expected ';' at end of declaration _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:551:37: error: expected unqualified-id /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:563:39: error: use of undeclared identifier 'is_floating_point' _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:563:57: error: '_A1' does not refer to a value _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:561:17: note: declared here template ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.
You may notice that flag -isystem is passed to compiler:
-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk/usr/include
When I manually remove the flag and try to compile then compilation successfully passed:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=220 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR="Debug-iphonesimulator" -Dframework_test_EXPORTS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.4.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mios-simulator-version-min=12.4 -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/projects/cmake_issue_cmath/build/Debug-iphonesimulator/include -I/projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/DerivedSources-normal/x86_64 -I/projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/DerivedSources/x86_64 -I/projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/projects/cmake_issue_cmath/build/Debug-iphonesimulator -fPIC -MMD -MT dependencies -MF /projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/Objects-normal/x86_64/dummy-1EF256537CB1577C.d --serialize-diagnostics /projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/Objects-normal/x86_64/dummy-1EF256537CB1577C.dia -c /projects/cmake_issue_cmath/dummy.cpp -o /projects/cmake_issue_cmath/build/Project.build/Debug-iphonesimulator/framework_test.build/Objects-normal/x86_64/dummy-1EF256537CB1577C.
I attached the example. It works with CMake 3.14, but doesn't work with CMake 3.15 (and CMake 3.16 rc1)