Commit c37f4eff authored by Craig Scott's avatar Craig Scott

FindPackageModeMakefileTest: macOS needs isysroot flag

macOS/Xcode no longer populate /usr/include.
Building with the compiler directly instead of using /usr/bin/c++
can result in missing headers without the -isysroot flag.

Relates: #19885
parent 92eb3a44
......@@ -19,6 +19,14 @@ if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Makefile" AND
# configure a FindFoo.cmake so it knows where the library can be found
configure_file(FindFoo.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FindFoo.cmake @ONLY)
# Need the -isysroot flag on recentish macOS after command line tools
# no longer provide headers in /usr/include
if(APPLE AND CMAKE_OSX_SYSROOT)
set(__EXTRA_OSX_SYSROOT_FLAGS "-isysroot ${CMAKE_OSX_SYSROOT}")
else()
set(__EXTRA_OSX_SYSROOT_FLAGS "")
endif()
# now set up the test:
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cmakeExecutable.mk"
CONTENT "CMAKE = \"$<TARGET_FILE:cmake>\"\n"
......
......@@ -5,6 +5,7 @@ CMAKE_CURRENT_BINARY_DIR = "@CMAKE_CURRENT_BINARY_DIR@"
CMAKE_CXX_COMPILER = "@CMAKE_CXX_COMPILER@"
CMAKE_CXX_COMPILER_ID = "@CMAKE_CXX_COMPILER_ID@"
CMAKE_CXX_FLAGS = @CMAKE_CXX_FLAGS@
__EXTRA_OSX_SYSROOT_FLAGS = @__EXTRA_OSX_SYSROOT_FLAGS@
CMAKE_FOO = $(CMAKE) --find-package -DCMAKE_MODULE_PATH=$(CMAKE_CURRENT_BINARY_DIR) -DNAME=Foo -DLANGUAGE=CXX -DCOMPILER_ID=$(CMAKE_CXX_COMPILER_ID)
......@@ -15,7 +16,7 @@ all: pngtest
main.o: clean main.cpp
@$(CMAKE_FOO) -DMODE=COMPILE >$(tmp)
@foo="`cat $(tmp)`"; \
printf '"%s" %s %s -c main.cpp\n' $(CMAKE_CXX_COMPILER) "$(CMAKE_CXX_FLAGS)" "$$foo" >$(tmp)
printf '"%s" %s %s %s -c main.cpp\n' $(CMAKE_CXX_COMPILER) "$(CMAKE_CXX_FLAGS)" "$(__EXTRA_OSX_SYSROOT_FLAGS)" "$$foo" >$(tmp)
@cat $(tmp)
@sh $(tmp)
@rm -f $(tmp)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment