···25252626set(SDL_GPU_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUGFIX}")
27272828-message("Writing version header for v${SDL_GPU_VERSION}")
2929-string(CONCAT VERSION_HEADER_CONTENTS "#ifndef _SDL_GPU_VERSION_H__
2828+if(${CMAKE_CURRENT_SOURCE_DIR}/version.txt IS_NEWER_THAN ${CMAKE_CURRENT_SOURCE_DIR}/include/SDL_gpu_version.h)
2929+ # This is to prevent CMake from rebuilding SDL_gpu, which is important when it is an external project in another project.
3030+ # This works since whenever version.txt is changed, it will be newer than SDL_gpu_version.h. The only time SDL_gpu_version.h
3131+ # will be newer than version.txt is when it is created or modified after the latter file.
3232+ message("Writing version header for v${SDL_GPU_VERSION}")
3333+ string(CONCAT VERSION_HEADER_CONTENTS "#ifndef _SDL_GPU_VERSION_H__
3034#define _SDL_GPU_VERSION_H__
31353236#define SDL_GPU_VERSION_MAJOR ${VERSION_MAJOR}
···3438#define SDL_GPU_VERSION_PATCH ${VERSION_BUGFIX}
35393640#endif")
3737-file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/include/SDL_gpu_version.h ${VERSION_HEADER_CONTENTS})
4141+4242+ file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/include/SDL_gpu_version.h ${VERSION_HEADER_CONTENTS})
4343+endif()
38443945set(DEFAULT_INSTALL_LIBRARY ON)
4046set(DEFAULT_BUILD_SHARED ON)