diff --git a/Chapter06/recipe-04/c-example/CMakeLists.txt b/Chapter06/recipe-04/c-example/CMakeLists.txt index 759aa4be0..a12eeffbb 100644 --- a/Chapter06/recipe-04/c-example/CMakeLists.txt +++ b/Chapter06/recipe-04/c-example/CMakeLists.txt @@ -2,12 +2,7 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # project name and language -project(recipe-04 LANGUAGES C) - -# version of our project -set(VERSION_MAJOR 2) -set(VERSION_MINOR 0) -set(VERSION_PATCH 1) +project(recipe-04 VERSION 2.0.1 LANGUAGES C) # generate file version.h based on version.h.in configure_file( diff --git a/Chapter06/recipe-04/c-example/example.c b/Chapter06/recipe-04/c-example/example.c index 611994d60..ffff811be 100644 --- a/Chapter06/recipe-04/c-example/example.c +++ b/Chapter06/recipe-04/c-example/example.c @@ -1,13 +1,12 @@ #include -// provides VERSION_MAJOR, VERSION_MINOR, and VERSION_PATCH +// provides PROJECT_VERSION, PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR #include "version.h" int main() { - printf("This is output from example code v%i.%i.%i:\n", - VERSION_MAJOR, - VERSION_MINOR, - VERSION_PATCH); + printf("This is output from example code %s\n", PROJECT_VERSION); + printf("The major version number is %i\n", PROJECT_VERSION_MAJOR); + printf("The minor version number is %i\n", PROJECT_VERSION_MINOR); printf("Hello CMake world!\n"); } diff --git a/Chapter06/recipe-04/c-example/version.h.in b/Chapter06/recipe-04/c-example/version.h.in index eb6e5cb58..deb9578fa 100644 --- a/Chapter06/recipe-04/c-example/version.h.in +++ b/Chapter06/recipe-04/c-example/version.h.in @@ -1,5 +1,7 @@ #pragma once -#define VERSION_MAJOR @VERSION_MAJOR@ -#define VERSION_MINOR @VERSION_MINOR@ -#define VERSION_PATCH @VERSION_PATCH@ +#define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@ + +#define PROJECT_VERSION "v@PROJECT_VERSION@" diff --git a/Chapter06/recipe-04/fortran-example/CMakeLists.txt b/Chapter06/recipe-04/fortran-example/CMakeLists.txt index 033e1881f..e216405ec 100644 --- a/Chapter06/recipe-04/fortran-example/CMakeLists.txt +++ b/Chapter06/recipe-04/fortran-example/CMakeLists.txt @@ -2,12 +2,7 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # project name and language -project(recipe-04 LANGUAGES Fortran) - -# version of our project -set(VERSION_MAJOR 2) -set(VERSION_MINOR 0) -set(VERSION_PATCH 1) +project(recipe-04 VERSION 2.0.1 LANGUAGES Fortran) # generate version module based on version.f90.in configure_file( diff --git a/Chapter06/recipe-04/fortran-example/example.f90 b/Chapter06/recipe-04/fortran-example/example.f90 index 13f67ca07..fa6c975b4 100644 --- a/Chapter06/recipe-04/fortran-example/example.f90 +++ b/Chapter06/recipe-04/fortran-example/example.f90 @@ -1,11 +1,13 @@ program example - use version, only: VERSION_STRING, VERSION_MAJOR + use version, only: PROJECT_VERSION, PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR implicit none - print *, "This is output from example code ", VERSION_STRING - print *, "The major version number is", VERSION_MAJOR + print *, "This is output from example code ", PROJECT_VERSION + print *, "The major version number is", PROJECT_VERSION_MAJOR + print *, "The minor version number is", PROJECT_VERSION_MINOR + print *, "Hello CMake world!" end program diff --git a/Chapter06/recipe-04/fortran-example/version.f90.in b/Chapter06/recipe-04/fortran-example/version.f90.in index 7bba40452..7a6d39739 100644 --- a/Chapter06/recipe-04/fortran-example/version.f90.in +++ b/Chapter06/recipe-04/fortran-example/version.f90.in @@ -2,10 +2,10 @@ module version implicit none - integer, parameter :: VERSION_MAJOR = @VERSION_MAJOR@ - integer, parameter :: VERSION_MINOR = @VERSION_MINOR@ - integer, parameter :: VERSION_PATCH = @VERSION_PATCH@ + integer, parameter :: PROJECT_VERSION_MAJOR = @PROJECT_VERSION_MAJOR@ + integer, parameter :: PROJECT_VERSION_MINOR = @PROJECT_VERSION_MINOR@ + integer, parameter :: PROJECT_VERSION_PATCH = @PROJECT_VERSION_PATCH@ - character(*), parameter :: VERSION_STRING = "v@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@" + character(*), parameter :: PROJECT_VERSION = "v@PROJECT_VERSION@" end module