diff options
author | Nadia Holmquist Pedersen <nadia@nhp.sh> | 2022-05-21 19:54:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-21 19:54:55 +0200 |
commit | 94b33c924e0524452738e077aea03ba7e8b6302f (patch) | |
tree | ad2750a5ed078ca15a3d2bc07b241db064ec26f4 /cmake | |
parent | 6c7485d01786fe92da4c2760d23e4ee26ce872a3 (diff) |
Modernize CMake build system (#1434)
These changes modernize the CMake build system to (hopefully) match newer best practices
* Library linking is simpler and more automatic because of using imported targets
* Multi-configuration builds should be supported (Ninja Multi-Config, Visual Studio, etc. generators)
* Clean up build options using cmake_dependent_option
* Let CMake do its job in more cases, like finding the math/dl libraries and detecting and enabling LTO support
* Remove platform-specific kludges like the Fedora/flatpak LTO workaround and a bunch of Windows stuff
* Simplify Windows static builds
* Consistent formatting
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FixInterfaceIncludes.cmake | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cmake/FixInterfaceIncludes.cmake b/cmake/FixInterfaceIncludes.cmake new file mode 100644 index 0000000..513c111 --- /dev/null +++ b/cmake/FixInterfaceIncludes.cmake @@ -0,0 +1,28 @@ +# The entire codebase quite reasonably does things like #include <SDL2/SDL.h> or <epoxy/gl.h> +# CMake apparently doesn't think you should be doing this, so just includes $PREFIX/include/packagename for a given +# package as include directories when using `target_link_libraries` with an imported target, this hacky function fixes +# that up so includes can keep working as they always did but we can still use fancy imported targets. +# This is stupid. + +function(fix_interface_includes) + foreach (target ${ARGN}) + set(NEW_DIRS) + get_target_property(DIRS "${target}" INTERFACE_INCLUDE_DIRECTORIES) + + if (NOT DIRS) + continue() + endif() + + foreach (DIR ${DIRS}) + get_filename_component(PARENT_DIR "${DIR}" DIRECTORY) + + if (PARENT_DIR MATCHES "include$") + list(APPEND NEW_DIRS "${PARENT_DIR}") + endif() + endforeach() + + list(APPEND DIRS ${NEW_DIRS}) + set_target_properties("${target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${DIRS}") + endforeach() +endfunction() + |