1if(NOT BDIR)
2  set(BDIR ${CMAKE_CURRENT_BINARY_DIR})
3endif()
4
5find_package(Git REQUIRED)
6execute_process(COMMAND git describe --tags --match "v[0-9]*" --long --dirty WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE git_version_string RESULT_VARIABLE status ERROR_QUIET)
7
8if(status AND NOT status EQUAL 0)
9  if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../version.txt)
10    # for source package files (generated for ubuntu builds on launchpad) read the version from version.txt
11    if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../version.txt)
12      file(READ ${CMAKE_CURRENT_LIST_DIR}/../version.txt git_version_string )
13    else()
14      get_filename_component(git_version_string ${CMAKE_CURRENT_LIST_DIR}/.. NAME)
15      string(REGEX REPLACE "^netgen(.*)" "\\1" git_version_string "${git_version_string}")
16    endif()
17  else()
18    MESSAGE(WARNING "Could not determine git-version from source code - assuming 6.2.0.0")
19    set(git_version_string "v6.2.0.0")
20  endif()
21endif()
22
23string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" NETGEN_VERSION_MAJOR "${git_version_string}")
24string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" NETGEN_VERSION_MINOR "${git_version_string}")
25string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" NETGEN_VERSION_PATCH "${git_version_string}")
26string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" NETGEN_VERSION_TWEAK "${git_version_string}")
27string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([0-9a-z]+).*" "\\1" NETGEN_VERSION_HASH "${git_version_string}")
28
29set(NETGEN_VERSION_SHORT ${NETGEN_VERSION_MAJOR}.${NETGEN_VERSION_MINOR}.${NETGEN_VERSION_PATCH})
30set(NETGEN_VERSION_LONG ${NETGEN_VERSION_SHORT}-${NETGEN_VERSION_TWEAK}-${NETGEN_VERSION_HASH})
31
32if(NETGEN_VERSION_TWEAK)
33  # no release version - nightly build
34  set(NETGEN_VERSION ${NETGEN_VERSION_LONG})
35else()
36  # TWEAK is 0 -> current version has a tag assigned
37  set(NETGEN_VERSION ${NETGEN_VERSION_SHORT})
38endif()
39
40set(NETGEN_VERSION_LONG ${NETGEN_VERSION_SHORT}-${NETGEN_VERSION_TWEAK}-${NETGEN_VERSION_HASH})
41
42set(version_file ${BDIR}/netgen_version.hpp)
43set(new_version_file_string "\
44#ifndef NETGEN_VERSION_HPP_INCLUDED
45#define NETGEN_VERSION_HPP_INCLUDED
46#define NETGEN_VERSION \"${NETGEN_VERSION}\"
47#define NETGEN_VERSION_MAJOR ${NETGEN_VERSION_MAJOR}
48#define NETGEN_VERSION_MINOR ${NETGEN_VERSION_MINOR}
49#define NETGEN_VERSION_PATCH ${NETGEN_VERSION_PATCH}
50#define NETGEN_VERSION_TWEAK ${NETGEN_VERSION_TWEAK}
51#define NETGEN_VERSION_HASH \"${NETGEN_VERSION_HASH}\"
52#endif // NETGEN_VERSION_HPP_INCLUDED
53")
54if(EXISTS ${version_file})
55  file(READ ${version_file} old_version_file_string )
56  if(${old_version_file_string} STREQUAL ${new_version_file_string})
57  else()
58    file(WRITE ${BDIR}/netgen_version.hpp ${new_version_file_string})
59  endif()
60else()
61    file(WRITE ${BDIR}/netgen_version.hpp ${new_version_file_string})
62endif()
63
64file(GENERATE OUTPUT netgen_config.hpp CONTENT
65"\
66#ifndef NETGEN_CONFIG_HPP_INCLUDED___
67#define NETGEN_CONFIG_HPP_INCLUDED___
68
69#define NETGEN_USE_NATIVE_ARCH          $<BOOL:${USE_NATIVE_ARCH}>
70#define NETGEN_USE_GUI                  $<BOOL:${USE_GUI}>
71#define NETGEN_USE_PYTHON               $<BOOL:${USE_PYTHON}>
72#define NETGEN_USE_MPI                  $<BOOL:${USE_MPI}}>
73#define NETGEN_USE_MPI4PY               $<BOOL:${USE_MPI4PY}>
74#define NETGEN_USE_OCC                  $<BOOL:${USE_OCC}}>
75#define NETGEN_USE_JPEG                 $<BOOL:${USE_JPEG}}>
76#define NETGEN_USE_MPEG                 $<BOOL:${USE_MPEG}}>
77#define NETGEN_USE_CGNS                 $<BOOL:${USE_CGNS}}>
78#define NETGEN_USE_NUMA                 $<BOOL:${USE_NUMA}}>
79#define NETGEN_INTEL_MIC                $<BOOL:${USE_INTEL_MIC}}>
80#define NETGEN_INSTALL_PROFILES         $<BOOL:${INSTALL_PROFILES}>
81#define NETGEN_USE_CCACHE               $<BOOL:${USE_CCACHE}}>
82#define NETGEN_USE_INTERNAL_TCL         $<BOOL:${USE_INTERNAL_TCL}>
83#define NETGEN_ENABLE_UNIT_TESTS        $<BOOL:${ENABLE_UNIT_TESTS}>
84#define NETGEN_ENABLE_CPP_CORE_GUIDELINES_CHECK $<BOOL:${ENABLE_CPP_CORE_GUIDELINES_CHECK}>
85#define NETGEN_USE_SPDLOG               $<BOOL:${USE_SPDLOG}>
86#define NETGEN_DEBUG_LOG                $<BOOL:${DEBUG_LOG}>
87#define NETGEN_USE_CHECK_RANGE          $<BOOL:${CHECK_RANGE}>
88#define NETGEN_BUILD_STUB_FILES         $<BOOL:${BUILD_STUB_FILES}>
89#define NETGEN_BUILD_FOR_CONDA          $<BOOL:${BUILD_FOR_CONDA}>
90
91#endif // NETGEN_CONFIG_HPP_INCLUDED___
92")
93