Skip to content

Commit

Permalink
Merge pull request #290 from bast/radovan/version-in-project
Browse files Browse the repository at this point in the history
define VERSION inside project(); fixes #278
  • Loading branch information
bast authored Mar 29, 2018
2 parents 5ff08de + 9d92730 commit 23fe6b4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
7 changes: 1 addition & 6 deletions Chapter06/recipe-04/c-example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 4 additions & 5 deletions Chapter06/recipe-04/c-example/example.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <stdio.h>

// 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");
}
8 changes: 5 additions & 3 deletions Chapter06/recipe-04/c-example/version.h.in
Original file line number Diff line number Diff line change
@@ -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@"
7 changes: 1 addition & 6 deletions Chapter06/recipe-04/fortran-example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions Chapter06/recipe-04/fortran-example/example.f90
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions Chapter06/recipe-04/fortran-example/version.f90.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 23fe6b4

Please sign in to comment.