7e142c5ac2
Teach the project() command to set variables {PROJECT,<PROJECT-NAME>}_VERSION{,_MAJOR,_MINOR,_PATCH,_TWEAK} holding the project version number and its components. Add project() command option "VERSION" to specify the version explicitly, and default to the empty string when it is not given. Since this clears variables when no VERSION is given, this may change behavior for existing projects that set the version variables themselves prior to calling project(). Add policy CMP0048 for compatibility. Suggested-by: Alex Neundorf <neundorf@kde.org>
20 lines
506 B
CMake
20 lines
506 B
CMake
macro(print_versions name)
|
|
foreach(v "" _MAJOR _MINOR _PATCH _TWEAK)
|
|
message(STATUS "PROJECT_VERSION${v}='${PROJECT_VERSION${v}}'")
|
|
message(STATUS "${name}_VERSION${v}='${${name}_VERSION${v}}'")
|
|
endforeach()
|
|
endmacro()
|
|
|
|
cmake_policy(SET CMP0048 NEW)
|
|
|
|
project(ProjectA VERSION 1.2.3.4 LANGUAGES NONE)
|
|
print_versions(ProjectA)
|
|
|
|
project(ProjectB VERSION 0.1.2 LANGUAGES NONE)
|
|
print_versions(ProjectB)
|
|
|
|
set(PROJECT_VERSION 1)
|
|
set(ProjectC_VERSION 1)
|
|
project(ProjectC NONE)
|
|
print_versions(ProjectC)
|