cmake: pass VERSION to project() + don't use SDL_VERSION

main
Anonymous Maarten 2023-01-09 14:11:54 +01:00 committed by Anonymous Maarten
parent 3aa456dead
commit 9cf34908a1
5 changed files with 25 additions and 35 deletions

View File

@ -1,9 +1,11 @@
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) cmake_minimum_required(VERSION 3.0.0)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR "Prevented in-tree build. Please create a build directory outside of the SDL source code and run \"cmake -S ${CMAKE_SOURCE_DIR} -B .\" from there") message(FATAL_ERROR "Prevented in-tree build. Please create a build directory outside of the SDL source code and run \"cmake -S ${CMAKE_SOURCE_DIR} -B .\" from there")
endif() endif()
cmake_minimum_required(VERSION 3.0.0) # See docs/release_checklist.md
project(SDL3 C CXX) project(SDL3 LANGUAGES C CXX VERSION "3.0.0")
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(SDL3_SUBPROJECT OFF) set(SDL3_SUBPROJECT OFF)
@ -75,36 +77,30 @@ if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4)
target_compile_definitions(sdl-build-options INTERFACE "_FILE_OFFSET_BITS=64") target_compile_definitions(sdl-build-options INTERFACE "_FILE_OFFSET_BITS=64")
endif() endif()
# See docs/release_checklist.md
set(SDL_MAJOR_VERSION 3)
set(SDL_MINOR_VERSION 0)
set(SDL_MICRO_VERSION 0)
set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
# Increment this if there is an incompatible change - but if that happens, # Increment this if there is an incompatible change - but if that happens,
# we should rename the library from SDL3 to SDL4, at which point this would # we should rename the library from SDL3 to SDL4, at which point this would
# reset to 0 anyway. # reset to 0 anyway.
set(SDL_SO_VERSION_MAJOR "0") set(SDL_SO_VERSION_MAJOR "0")
set(SDL_SO_VERSION_MINOR "${SDL_MINOR_VERSION}") set(SDL_SO_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(SDL_SO_VERSION_MICRO "${SDL_MICRO_VERSION}") set(SDL_SO_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(SDL_SO_VERSION "${SDL_SO_VERSION_MAJOR}.${SDL_SO_VERSION_MINOR}.${SDL_SO_VERSION_MICRO}") set(SDL_SO_VERSION "${SDL_SO_VERSION_MAJOR}.${SDL_SO_VERSION_MINOR}.${SDL_SO_VERSION_PATCH}")
if(SDL_MINOR_VERSION MATCHES "[02468]$") if(PROJECT_VERSION_MINOR MATCHES "[02468]$")
math(EXPR SDL_DYLIB_COMPAT_VERSION_MAJOR "100 * ${SDL_MINOR_VERSION} + 1") math(EXPR SDL_DYLIB_COMPAT_VERSION_MAJOR "100 * ${PROJECT_VERSION_MINOR} + 1")
set(SDL_DYLIB_COMPAT_VERSION_MINOR "0") set(SDL_DYLIB_COMPAT_VERSION_MINOR "0")
math(EXPR SDL_DYLIB_CURRENT_VERSION_MAJOR "${SDL_DYLIB_COMPAT_VERSION_MAJOR}") math(EXPR SDL_DYLIB_CURRENT_VERSION_MAJOR "${SDL_DYLIB_COMPAT_VERSION_MAJOR}")
set(SDL_DYLIB_CURRENT_VERSION_MINOR "${SDL_MICRO_VERSION}") set(SDL_DYLIB_CURRENT_VERSION_MINOR "${PROJECT_VERSION_PATCH}")
else() else()
math(EXPR SDL_DYLIB_COMPAT_VERSION_MAJOR "100 * ${SDL_MINOR_VERSION} + ${SDL_MICRO_VERSION} + 1") math(EXPR SDL_DYLIB_COMPAT_VERSION_MAJOR "100 * ${PROJECT_VERSION_MINOR} + ${PROJECT_VERSION_PATCH} + 1")
set(SDL_DYLIB_COMPAT_VERSION_MINOR "0") set(SDL_DYLIB_COMPAT_VERSION_MINOR "0")
math(EXPR SDL_DYLIB_CURRENT_VERSION_MAJOR "${SDL_DYLIB_COMPAT_VERSION_MAJOR}") math(EXPR SDL_DYLIB_CURRENT_VERSION_MAJOR "${SDL_DYLIB_COMPAT_VERSION_MAJOR}")
set(SDL_DYLIB_CURRENT_VERSION_MINOR "0") set(SDL_DYLIB_CURRENT_VERSION_MINOR "0")
endif() endif()
set(SDL_DYLIB_COMPAT_VERSION_MICRO "0") set(SDL_DYLIB_COMPAT_VERSION_PATCH "0")
set(SDL_DYLIB_CURRENT_VERSION_MICRO "0") set(SDL_DYLIB_COMPAT_VERSION_PATCH "0")
set(SDL_DYLIB_CURRENT_VERSION "${SDL_DYLIB_CURRENT_VERSION_MAJOR}.${SDL_DYLIB_CURRENT_VERSION_MINOR}.${SDL_DYLIB_CURRENT_VERSION_MICRO}") set(SDL_DYLIB_CURRENT_VERSION "${SDL_DYLIB_CURRENT_VERSION_MAJOR}.${SDL_DYLIB_CURRENT_VERSION_MINOR}.${SDL_DYLIB_COMPAT_VERSION_PATCH}")
set(SDL_DYLIB_COMPAT_VERSION "${SDL_DYLIB_COMPAT_VERSION_MAJOR}.${SDL_DYLIB_COMPAT_VERSION_MINOR}.${SDL_DYLIB_COMPAT_VERSION_MICRO}") set(SDL_DYLIB_COMPAT_VERSION "${SDL_DYLIB_COMPAT_VERSION_MAJOR}.${SDL_DYLIB_COMPAT_VERSION_MINOR}.${SDL_DYLIB_COMPAT_VERSION_PATCH}")
#message("SDL_SO_VERSION=${SDL_SO_VERSION} SDL_DYLIB_CURRENT_VERSION=${SDL_DYLIB_CURRENT_VERSION} SDL_DYLIB_COMPAT_VERSION=${SDL_DYLIB_COMPAT_VERSION}") #message("SDL_SO_VERSION=${SDL_SO_VERSION} SDL_DYLIB_CURRENT_VERSION=${SDL_DYLIB_CURRENT_VERSION} SDL_DYLIB_COMPAT_VERSION=${SDL_DYLIB_COMPAT_VERSION}")
@ -2868,7 +2864,7 @@ else()
# If VERSION does not exist, use git to calculate a version # If VERSION does not exist, use git to calculate a version
git_describe(SDL_REVISION_CENTER) git_describe(SDL_REVISION_CENTER)
if(NOT SDL_REVISION_CENTER) if(NOT SDL_REVISION_CENTER)
set(SDL_REVISION_CENTER "${SDL_VERSION}-no-vcs") set(SDL_REVISION_CENTER "${SDL3_VERSION}-no-vcs")
endif() endif()
endif() endif()
set(SDL_REVISION "SDL-${SDL_REVISION_CENTER}${SDL_REVISION_SUFFIX}") set(SDL_REVISION "SDL-${SDL_REVISION_CENTER}${SDL_REVISION_SUFFIX}")
@ -3197,9 +3193,9 @@ if(SDL_STATIC)
endif() endif()
target_compile_definitions(sdl-build-options INTERFACE target_compile_definitions(sdl-build-options INTERFACE
"SDL_BUILD_MAJOR_VERSION=${SDL_MAJOR_VERSION}" "SDL_BUILD_MAJOR_VERSION=${PROJECT_VERSION_MAJOR}"
"SDL_BUILD_MINOR_VERSION=${SDL_MINOR_VERSION}" "SDL_BUILD_MINOR_VERSION=${PROJECT_VERSION_MINOR}"
"SDL_BUILD_MICRO_VERSION=${SDL_MICRO_VERSION}" "SDL_BUILD_MICRO_VERSION=${PROJECT_VERSION_PATCH}"
) )
##### Tests ##### ##### Tests #####
@ -3318,7 +3314,6 @@ if(NOT SDL3_DISABLE_INSTALL)
INSTALL_DESTINATION "${SDL_INSTALL_CMAKEDIR}" INSTALL_DESTINATION "${SDL_INSTALL_CMAKEDIR}"
) )
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SDL3ConfigVersion.cmake" write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SDL3ConfigVersion.cmake"
VERSION ${SDL_VERSION}
COMPATIBILITY AnyNewerVersion COMPATIBILITY AnyNewerVersion
) )

View File

@ -25,10 +25,7 @@ not_ok () {
failed=1 failed=1
} }
major=$(sed -ne 's/^set(SDL_MAJOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt) version=$(sed -Ene 's/^project\(SDL[0-9]+ LANGUAGES C CXX VERSION "([0-9.]*)"\)$/\1/p' CMakeLists.txt)
minor=$(sed -ne 's/^set(SDL_MINOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
micro=$(sed -ne 's/^set(SDL_MICRO_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
version="${major}.${minor}.${micro}"
if [ "$ref_version" = "$version" ]; then if [ "$ref_version" = "$version" ]; then
ok "CMakeLists.txt $version" ok "CMakeLists.txt $version"

View File

@ -54,9 +54,7 @@ if [ "x$PATCH" != "x0" ]; then
fi fi
fi fi
perl -w -pi -e 's/\A(set\(SDL_MAJOR_VERSION\s+)\d+/${1}'$MAJOR'/;' CMakeLists.txt perl -w -pi -e 's/\A(project\(SDL[0-9]+ LANGUAGES C CXX VERSION ")[0-9.]+/${1}'$NEWVERSION'/;' CMakeLists.txt
perl -w -pi -e 's/\A(set\(SDL_MINOR_VERSION\s+)\d+/${1}'$MINOR'/;' CMakeLists.txt
perl -w -pi -e 's/\A(set\(SDL_MICRO_VERSION\s+)\d+/${1}'$PATCH'/;' CMakeLists.txt
perl -w -pi -e 's/\A(.* SDL_MAJOR_VERSION = )\d+/${1}'$MAJOR'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java perl -w -pi -e 's/\A(.* SDL_MAJOR_VERSION = )\d+/${1}'$MAJOR'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
perl -w -pi -e 's/\A(.* SDL_MINOR_VERSION = )\d+/${1}'$MINOR'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java perl -w -pi -e 's/\A(.* SDL_MINOR_VERSION = )\d+/${1}'$MINOR'/;' android-project/app/src/main/java/org/libsdl/app/SDLActivity.java

View File

@ -7,7 +7,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: sdl3 Name: sdl3
Description: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. Description: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.
Version: @SDL_VERSION@ Version: @PROJECT_VERSION@
Requires.private: @SDL_PC_PRIVATE_REQUIRES@ Requires.private: @SDL_PC_PRIVATE_REQUIRES@
Conflicts: Conflicts:
Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_PC_LIBS@ @PKGCONFIG_LIBS_PRIV@ @SDL_PC_STATIC_LIBS@ Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_PC_LIBS@ @PKGCONFIG_LIBS_PRIV@ @SDL_PC_STATIC_LIBS@

View File

@ -351,8 +351,8 @@ if(APPLE)
foreach(CURRENT_TARGET ${SDL_TEST_EXECUTABLES}) foreach(CURRENT_TARGET ${SDL_TEST_EXECUTABLES})
set_target_properties("${CURRENT_TARGET}" PROPERTIES set_target_properties("${CURRENT_TARGET}" PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}" MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}"
MACOSX_BUNDLE_BUNDLE_VERSION "${SDL_VERSION}" MACOSX_BUNDLE_BUNDLE_VERSION "${SDL3_VERSION}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL_VERSION}" MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL3_VERSION}"
) )
endforeach() endforeach()
endif() endif()