Skip to content

Commit 9397026

Browse files
committed
Add CMake module to extract Git info
1 parent a17a204 commit 9397026

23 files changed

+106
-95
lines changed

cmake/custom/autogenerated.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ if(BUILD_CUSTOM_BOOST)
1616
endif()
1717
install(FILES ${PROJECT_BINARY_DIR}/include/Config.hpp DESTINATION include)
1818

19-
# Move the autogenerated git_info.h to ${PROJECT_BINARY_DIR}/include
20-
file(RENAME ${PROJECT_BINARY_DIR}/git_info.h ${PROJECT_BINARY_DIR}/include/git_info.h)
19+
generate_git_info_header(${PROJECT_BINARY_DIR}/include GitInfo.hpp)
2120

2221
# Configure the input parsing script
2322
configure_file(${PROJECT_SOURCE_DIR}/tools/pcmsolver.py.in ${PROJECT_BINARY_DIR}/bin/tmp-pcmsolver-py @ONLY)

cmake/custom/compilers/CheckCXX11.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ macro(discover_cxx11_support _CXX_STANDARD_FLAG)
7878
cxx11_check_feature("${_discovered_flag}" "static_assert" HAS_CXX11_STATIC_ASSERT)
7979
cxx11_check_feature("${_discovered_flag}" "variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES)
8080
cxx11_check_feature("${_discovered_flag}" "noexcept" HAS_CXX11_NOEXCEPT)
81+
cxx11_check_feature("${_discovered_flag}" "noreturn" HAS_CXX11_NORETURN)
8182

8283
# Add feature definitions
8384
foreach(_feature_def ${CXX11_DEFINITIONS})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[[noreturn]] void do_not_return() {
2+
throw "error";
3+
// OK
4+
}
5+
6+
int main() { return 0; }

cmake/custom/compilers/GNU.CXX.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ if(NOT DEFINED ENV{CXXFLAGS})
1414
endif()
1515

1616
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD_FLAG}")
17-
set(EXDIAG_CXX_FLAGS "-Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wuseless-cast -Wunsafe-loop-optimizations")
18-
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DDEBUG -Wall -Wextra -Winit-self -Woverloaded-virtual -Wuninitialized -Wmissing-declarations -Wwrite-strings -Wno-sign-compare ${EXDIAG_CXX_FLAGS}")
17+
set(EXDIAG_CXX_FLAGS -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wuseless-cast -Wunsafe-loop-optimizations)
18+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DDEBUG -Wall -Wextra -Winit-self -Woverloaded-virtual -Wuninitialized -Wmissing-declarations -Wwrite-strings -Wno-sign-compare")
1919
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -Wno-unused")
2020
endif()
2121
endif()

cmake/downloaded/autocmake_git_info.cmake

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,70 @@
99
#
1010
# url_root: https://github.com/coderefinery/autocmake/raw/master/
1111
# fetch:
12-
# - "%(url_root)modules/git_info/git_info_sub.cmake"
1312
# - "%(url_root)modules/git_info/git_info.h.in"
1413

15-
# CMAKE_CURRENT_LIST_DIR is undefined in CMake 2.8.2
16-
# see https://public.kitware.com/Bug/print_bug_page.php?bug_id=11675
17-
# workaround: create CMAKE_CURRENT_LIST_DIR
18-
get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
19-
add_custom_command(
20-
OUTPUT ${PROJECT_BINARY_DIR}/git_info.h
21-
COMMAND ${CMAKE_COMMAND} -D_target_dir=${PROJECT_BINARY_DIR} -P git_info_sub.cmake
22-
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
14+
function(generate_git_info_header)
15+
# _header_location: where the Git info header file should be generated
16+
# _header_name: the Git info header name, complete with extension (.h, .hpp, .hxx or whatever)
17+
if(${ARGC} EQUAL 2)
18+
set(_header_location ${ARGV0})
19+
set(_header_name ${ARGV1})
20+
elseif(${ARGC} EQUAL 0)
21+
set(_header_location ${PROJECT_BINARY_DIR})
22+
set(_header_name git_info.h)
23+
else()
24+
message(FATAL_ERROR "generate_git_info_header function accepts either two or no arguments")
25+
endif()
26+
find_package(Git)
27+
28+
set(_git_last_commit_hash "unknown")
29+
set(_git_last_commit_author "unknown")
30+
set(_git_last_commit_date "unknown")
31+
set(_git_branch "unknown")
32+
33+
if(GIT_FOUND)
34+
execute_process(
35+
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%h -n 1
36+
OUTPUT_VARIABLE _git_last_commit_hash
37+
OUTPUT_STRIP_TRAILING_WHITESPACE
38+
ERROR_QUIET
39+
)
40+
41+
execute_process(
42+
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%aN -n 1
43+
OUTPUT_VARIABLE _git_last_commit_author
44+
OUTPUT_STRIP_TRAILING_WHITESPACE
45+
ERROR_QUIET
46+
)
47+
48+
execute_process(
49+
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%ad -n 1
50+
OUTPUT_VARIABLE _git_last_commit_date
51+
OUTPUT_STRIP_TRAILING_WHITESPACE
52+
ERROR_QUIET
53+
)
54+
55+
execute_process(
56+
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
57+
OUTPUT_VARIABLE _git_branch
58+
OUTPUT_STRIP_TRAILING_WHITESPACE
59+
ERROR_QUIET
60+
)
61+
endif()
62+
63+
configure_file(
64+
${PROJECT_SOURCE_DIR}/cmake/downloaded/git_info.h.in
65+
${_header_location}/${_header_name}
66+
@ONLY
2367
)
2468

25-
add_custom_target(
69+
unset(_git_last_commit_hash)
70+
unset(_git_last_commit_author)
71+
unset(_git_last_commit_date)
72+
unset(_git_branch)
73+
74+
add_custom_target(
2675
git_info
27-
ALL DEPENDS ${PROJECT_BINARY_DIR}/git_info.h
76+
ALL DEPENDS ${_header_location}/${_header_name}
2877
)
78+
endfunction()

cmake/downloaded/git_info_sub.cmake

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

doc/Doxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ EXCLUDE_SYMBOLS = EIGEN_MAKE_ALIGNED_OPERATOR_NEW \
838838
__final \
839839
__override \
840840
__noexcept \
841+
__noreturn \
841842
__nullptr
842843

843844
# The EXAMPLE_PATH tag can be used to specify one or more files or directories

include/Citation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <string>
3030

3131
#include "Config.hpp"
32-
#include "git_info.h"
32+
#include "GitInfo.hpp"
3333

3434
// This is to stringify the PROJECT_VERSION preprocessor constant
3535
#define STRINGIFY(x) #x

include/Cxx11Workarounds.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,15 @@ template <typename Source> std::string to_string(const Source & arg) {
143143
#define __nullptr NULL
144144
#endif /* HAS_CXX11_NULLPTR */
145145

146+
/* Workaround for [[noreturn]] */
147+
#ifdef HAS_CXX11_NORETURN
148+
#define __noreturn [[noreturn]]
149+
#elif defined(__GNUC__)
150+
#define __noreturn __attribute__((noreturn))
151+
#elif defined(_MSC_VER)
152+
#define __declspec(noreturn)
153+
#else /* HAS_CXX11_NORETURN */
154+
#define __noreturn
155+
#endif /* HAS_CXX11_NORETURN */
156+
146157
#endif /* CXX11WORKAROUNDS_HPP */

src/bi_operators/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ list(APPEND sources_list BoundaryIntegralOperator.cpp Collocation.cpp Purisima.c
77
add_library(bi_operators OBJECT ${headers_list} ${sources_list})
88
set_target_properties(bi_operators PROPERTIES POSITION_INDEPENDENT_CODE 1 )
99
add_dependencies(bi_operators generate-config-hpp)
10+
target_compile_options(bi_operators PRIVATE "$<$<CONFIG:DEBUG>:${EXDIAG_CXX_FLAGS}>")
1011
# Sets install directory for all the headers in the list
1112
foreach(_header ${headers_list})
1213
install(FILES ${_header} DESTINATION include/bi_operators)

0 commit comments

Comments
 (0)