Skip to content

Commit 8627627

Browse files
committed
Add an option to completely bypass the git management of the version header.
1 parent 9b09175 commit 8627627

File tree

7 files changed

+41
-31
lines changed

7 files changed

+41
-31
lines changed

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ endif(COMMAND CMAKE_POLICY)
6262
# CMake derives much of its functionality from modules, typically
6363
# stored in one directory - let CMake know where to find them.
6464
set(SC_CMAKE_DIR "${SC_SOURCE_DIR}/cmake")
65-
if(NOT IS_SUBBUILD)
65+
if(NOT SC_IS_SUBBUILD)
6666
set(CMAKE_MODULE_PATH "${SC_CMAKE_DIR};${CMAKE_MODULE_PATH}")
67-
else(NOT IS_SUBBUILD)
67+
else(NOT SC_IS_SUBBUILD)
6868
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${SC_CMAKE_DIR}")
69-
endif(NOT IS_SUBBUILD)
69+
endif(NOT SC_IS_SUBBUILD)
7070

7171
# testing and compilation options, build output dirs, install dirs, uninstall, package creation, etc
7272
include(${SC_CMAKE_DIR}/SC_Build_opts.cmake)
@@ -95,10 +95,12 @@ if(NOT DEFINED SC_BUILD_SCHEMAS)
9595
set(SC_BUILD_SCHEMAS "ALL" CACHE string "Semicolon-separated list of paths to EXPRESS schemas to be built")
9696
endif(NOT DEFINED SC_BUILD_SCHEMAS)
9797

98-
list(APPEND CONFIG_END_MESSAGES
99-
".. Don't worry about any messages above about missing headers or failed tests, as long as"
100-
" you see 'Configuring done' below. Headers and features vary by compiler."
101-
".. Generating step can take a while if you are building several schemas.")
98+
if(NOT SC_IS_SUBBUILD)
99+
list(APPEND CONFIG_END_MESSAGES
100+
".. Don't worry about any messages above about missing headers or failed tests, as long as"
101+
" you see 'Configuring done' below. Headers and features vary by compiler."
102+
".. Generating step can take a while if you are building several schemas.")
103+
endif(NOT SC_IS_SUBBUILD)
102104

103105
# create config headers sc_cf.h and sc_version_string.h
104106
include(${SC_CMAKE_DIR}/SC_Config_Headers.cmake)

cmake/SC_Build_opts.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ OPTION_WITH_DEFAULT(SC_TRACE_FPRINTF "Enable extra comments in generated code so
5454
# Should we use C++11?
5555
OPTION_WITH_DEFAULT(SC_ENABLE_CXX11 "Build with C++ 11 features" ON)
5656

57+
# Get version from git
58+
OPTION_WITH_DEFAULT(SC_GIT_VERSION "Build using version from git" ON)
59+
5760
option(SC_BUILD_EXPRESS_ONLY "Only build express parser." OFF)
5861
mark_as_advanced(SC_BUILD_EXPRESS_ONLY)
5962

cmake/SC_Config_Headers.cmake

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,23 @@ configure_file(${CONFIG_H_FILE} ${SC_BINARY_DIR}/${INCLUDE_INSTALL_DIR}/sc_cf.h)
103103
# Using 'ver_string' instead of 'sc_version_string.h' is a trick to force the
104104
# command to always execute when the custom target is built. It works because
105105
# a file by that name never exists.
106-
configure_file(${SC_CMAKE_DIR}/sc_version_string.cmake ${SC_BINARY_DIR}/sc_version_string.cmake @ONLY)
107-
add_custom_target(version_string ALL DEPENDS ver_string )
108-
# creates sc_version_string.h using cmake script
109-
add_custom_command(OUTPUT ver_string ${CMAKE_CURRENT_BINARY_DIR}/${INCLUDE_INSTALL_DIR}/sc_version_string.h
110-
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${SC_SOURCE_DIR}
111-
-DBINARY_DIR=${SC_BINARY_DIR}
112-
-P ${SC_BINARY_DIR}/sc_version_string.cmake)
113-
# sc_version_string.h is a generated file
106+
if(SC_GIT_VERSION)
107+
configure_file(${SC_CMAKE_DIR}/sc_version_string.cmake ${SC_BINARY_DIR}/sc_version_string.cmake @ONLY)
108+
add_custom_target(version_string ALL DEPENDS ver_string)
109+
# creates sc_version_string.h using cmake script
110+
add_custom_command(OUTPUT ver_string
111+
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${SC_SOURCE_DIR} -DBINARY_DIR=${SC_BINARY_DIR} -P ${SC_BINARY_DIR}/sc_version_string.cmake
112+
)
113+
# sc_version_string.h is a generated file
114+
else(SC_GIT_VERSION)
115+
set(VER_HDR "
116+
#ifndef SC_VERSION_STRING
117+
#define SC_VERSION_STRING
118+
static char sc_version[512] = {\"${SC_VERSION}\"};
119+
#endif"
120+
)
121+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${INCLUDE_INSTALL_DIR}/sc_version_string.h "${VER_HDR}")
122+
endif(SC_GIT_VERSION)
114123
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${INCLUDE_INSTALL_DIR}/sc_version_string.h
115124
PROPERTIES GENERATED TRUE
116125
HEADER_FILE_ONLY TRUE )

cmake/sc_version_string.cmake

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,10 @@ set(header_string "/* sc_version_string.h - written by cmake. Changes will be lo
7474
"#endif\n"
7575
)
7676

77-
#compare the new and old commit versions, don't update the file if only the timestamp differs
78-
if(EXISTS ${SC_VERSION_HEADER})
79-
file(READ ${SC_VERSION_HEADER} OLD_VER_STRING LIMIT 600) #file is ~586 bytes
80-
string(FIND "${OLD_VER_STRING}" "git commit id: ${GIT_COMMIT_ID}" COMMIT_MATCH )
81-
# ${COMMIT_MATCH} == -1 if no match
82-
else()
83-
set(COMMIT_MATCH -1)
84-
endif(EXISTS ${SC_VERSION_HEADER})
85-
86-
if(${COMMIT_MATCH} LESS 1 )
87-
file(WRITE ${SC_VERSION_HEADER} ${header_string})
88-
endif(${COMMIT_MATCH} LESS 1)
77+
#don't update the file unless somethig changed
78+
file(WRITE ${SC_VERSION_HEADER}.tmp ${header_string})
79+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SC_VERSION_HEADER}.tmp ${SC_VERSION_HEADER})
80+
execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${SC_VERSION_HEADER}.tmp)
8981

9082
if(NOT SC_IS_SUBBUILD)
9183
message("-- sc_version_string.h is up-to-date.")

src/exp2cxx/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ include_directories(
3939

4040
SC_ADDEXEC(exp2cxx "${exp2cxx_SOURCES}" "libexppp;express;base")
4141

42-
add_dependencies(exp2cxx version_string)
42+
if(NOT SC_IS_SUBBUILD AND SC_GIT_VERSION)
43+
add_dependencies(exp2cxx version_string)
44+
endif(NOT SC_IS_SUBBUILD AND SC_GIT_VERSION)
4345

4446
if(SC_ENABLE_TESTING)
4547
add_subdirectory(test)

src/exp2python/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ if(SC_PYTHON_GENERATOR)
3131
)
3232
SC_ADDEXEC(exp2python "${exp2python_SOURCES}" "express;base")
3333

34-
add_dependencies(exp2python version_string)
34+
if(NOT SC_IS_SUBBUILD AND SC_GIT_VERSION)
35+
add_dependencies(exp2python version_string)
36+
endif(NOT SC_IS_SUBBUILD AND SC_GIT_VERSION)
3537
endif(SC_PYTHON_GENERATOR)
3638

3739
# Local Variables:

src/express/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ else(SC_GENERATE_LP_SOURCES)
127127
add_dependencies(express express_verify)
128128
endif(SC_GENERATE_LP_SOURCES)
129129

130-
if(NOT SC_IS_SUBBUILD)
130+
if(NOT SC_IS_SUBBUILD AND SC_GIT_VERSION)
131131
add_dependencies(express version_string)
132-
endif(NOT SC_IS_SUBBUILD)
132+
endif(NOT SC_IS_SUBBUILD AND SC_GIT_VERSION)
133133
SC_ADDEXEC("check-express" "${CHECK_EXPRESS_SOURCES}" "express;base" ${SC_EXEC_NOINSTALL})
134134

135135
if(SC_ENABLE_TESTING)

0 commit comments

Comments
 (0)