Skip to content

Commit b4628ec

Browse files
committed
build: Don't write site_config.hpp if it hasn't changed.
1 parent 0100b24 commit b4628ec

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ option(pfasst_DEFAULT_RAND_SEED "Using a hardcoded random seed"
2525

2626
if(${pfasst_WITH_MPI})
2727
find_package(MPI REQUIRED)
28-
if(NOT "${CMAKE_CXX_COMPILER}" STREQUAL "${MPI_CXX_COMPILER}" OR
28+
if(NOT "${CMAKE_CXX_COMPILER}" STREQUAL "${MPI_CXX_COMPILER}" OR
2929
NOT "${CMAKE_C_COMPILER}" STREQUAL "${MPI_C_COMPILER}")
3030
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER}")
3131
message(STATUS "MPI C++ Compiler Wrapper: ${MPI_CXX_COMPILER}")
@@ -156,7 +156,7 @@ message(STATUS "Configuring sources")
156156
update_site_config()
157157

158158
add_custom_target(set_version ALL
159-
COMMAND ${pfasst_SOURCE_DIR}/tools/get_pfasst_version.sh
159+
COMMAND ${pfasst_SOURCE_DIR}/tools/get_pfasst_version.py
160160
WORKING_DIRECTORY ${pfasst_SOURCE_DIR}
161161
COMMENT "Updating PFASST++ version number"
162162
USES_TERMINAL

cmake/site_config.hpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace std;
1212

1313
namespace pfasst
1414
{
15-
static constexpr const char* VERSION = "pfasst_VERSION";
15+
static constexpr const char* VERSION = "@pfasst_VERSION@";
1616
} // ::pfasst
1717

1818
#endif // _PFASST__SITE_CONFIG_HPP

cmake/utility_functions.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ macro(update_site_config)
3333
if(pfasst_RANDOM_SEED)
3434
add_definitions(-DPFASST_DEFAULT_RANDOM_SEED)
3535
endif()
36+
execute_process(COMMAND git describe --dirty
37+
OUTPUT_VARIABLE pfasst_VERSION
38+
OUTPUT_STRIP_TRAILING_WHITESPACE)
3639
configure_file(
3740
"${pfasst_SOURCE_DIR}/cmake/site_config.hpp.in"
3841
"${CMAKE_CURRENT_SOURCE_DIR}/include/pfasst/site_config.hpp"

tools/get_pfasst_version.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
#
3+
#
4+
#
5+
6+
import re
7+
import subprocess
8+
9+
from os.path import dirname, abspath, join
10+
11+
# get git version
12+
version = str(subprocess.check_output(['git', 'describe', '--dirty'])).strip()
13+
14+
# read in site_config.hpp
15+
base = dirname(dirname(abspath(__file__)))
16+
site_config = abspath(join(base, 'include', 'pfasst', 'site_config.hpp'))
17+
18+
with open(site_config, 'r') as f:
19+
config = f.read()
20+
21+
# reset version
22+
new_config = re.sub('VERSION = "[^"]*"', 'VERSION = "{version}"'.format(version=version), config)
23+
24+
# write site_config if it has changed
25+
if config != new_config:
26+
with open(site_config, 'w') as f:
27+
f.write(new_config)

tools/get_pfasst_version.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)