Fix cmake build for git submodules on unix #179
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CMake build when including SDL_image as git submodule was broken for unix:
looking at the
scripts/genout.cmake
created by cmake, you can see how the includes are generatedwhich results in the following compile commands while compiling the generated file
pnglibconf.c
:Note that the relative include "external/zlib-1.2.11" resolves to
/home/cvarner/workspace/game-template/external/SDL_image/external/libpng-1.6.37/external/zlib-1.2.11
instead of the zlib source, causing the original error.Updating the top level CMakeLists.txt to use an absolute path results in the following compile command, which is better
We are still missing zlib's output directory though so we get the following error:
zlibs include directories should include both the original source and the binary dir. This PR does that with 2 changes:
CMake: including current src directory into include path madler/zlib#218 is a long standing zlib issue with a known solution CMake: use CMAKE_CURRENT_SOURCE_DIR, *not* top-level src dir. Fixes #218 madler/zlib#219 that only appears to remain unfixed because the repo hasn't been updated since 2017.
With (1) fixed, ZLIB_INCLUDE_DIR can be set using the
INCLUDE_DIRECTORIES
property of the zlib target created by adding the zlib subdirectory. This variable now correctly contains all include directories resulting in the following compile command:The build succeeds with no issues from there on