Skip to content

Commit

Permalink
CMake: Try to put /usr/local/include last
Browse files Browse the repository at this point in the history
  • Loading branch information
TellowKrinkle committed Jun 17, 2024
1 parent 779b175 commit 1855be2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
55 changes: 55 additions & 0 deletions cmake/Pcsx2Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,58 @@ int main() {
set(HOST_CACHE_LINE_SIZE ${detect_cache_line_size_output} CACHE STRING "Reported host cache line size")
endif()
endfunction()

function(get_recursive_include_directories output target inc_prop link_prop)
get_target_property(dirs ${target} ${inc_prop})
if(NOT dirs)
set(dirs)
endif()
get_target_property(deps ${target} ${link_prop})
if(deps)
foreach(dep IN LISTS deps)
if(TARGET ${dep})
get_recursive_include_directories(depdirs ${dep} INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES)
foreach(depdir IN LISTS depdirs)
# Only match absolute paths
# We'll hope any non-absolute paths will not get set as system directories
if(depdir MATCHES "^/")
list(APPEND dirs ${depdir})
endif()
endforeach()
endif()
endforeach()
list(REMOVE_DUPLICATES dirs)
endif()
set(${output} "${dirs}" PARENT_SCOPE)
endfunction()

function(force_include_last_impl target include inc_prop link_prop)
get_recursive_include_directories(dirs ${target} ${inc_prop} ${link_prop})
set(remove)
foreach(dir IN LISTS dirs)
if("${dir}" MATCHES "${include}")
list(APPEND remove ${dir})
endif()
endforeach()
if(NOT "${remove}" STREQUAL "")
get_target_property(sysdirs ${target} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
if(NOT sysdirs)
set(sysdirs)
endif()
# Move matching items to the end
list(REMOVE_ITEM dirs ${remove})
list(APPEND dirs ${remove})
# Set them as system include directories
list(APPEND sysdirs ${remove})
list(REMOVE_DUPLICATES sysdirs)
set_target_properties(${target} PROPERTIES
${inc_prop} "${dirs}"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${sysdirs}"
)
endif()
endfunction()

function(force_include_last target include)
force_include_last_impl(${target} "${include}" INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES)
force_include_last_impl(${target} "${include}" INCLUDE_DIRECTORIES LINK_LIBRARIES)
endfunction()
4 changes: 4 additions & 0 deletions pcsx2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,10 @@ if (NOT APPLE)
endif()

fixup_file_properties(PCSX2)
# Directories like /usr/local/include, /opt/local/include, etc tend to include lots of headers from lots of libraries.
# Possibly including libraries that we compiled versions of with the dependency build script.
# To ensure the dependency build script's headers are preferred, push any directories that look like */local/include to the end.
force_include_last(PCSX2_FLAGS "/(usr|local)/include/?$")

if (APPLE)
find_library(METAL_LIBRARY Metal)
Expand Down

0 comments on commit 1855be2

Please sign in to comment.