Override system include directories on MacOS

I’m trying to create imported targets to consume OpenCL components. Previously the project relied on include_directories() to specify non-system include directories. However, once I moved to installing components as proper imported targets, when I consume OpenCL::Headers via target_link_libraries(example1 PRIVATE OpenCL::Headers) it picks up the system headers from

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenCL.framework/Headers/cl.h

How can I tell either when creating the imported target (which I install) or when I consume it, that it should take precendence over the system include?

I suspect that something is not quite correct in the logic of FindOpenCL and it is finding cl.h from the SDK rather than your version. You might try to influence OpenCL_INCLUDE_DIR through the cache or environment.

1 Like