1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00
putty-source/cmake/gitcommit.cmake
Simon Tatham 31f496b59c Integrate the 'doc' subdir into the CMake system.
The standalone separate doc/Makefile is gone, replaced by a
CMakeLists.txt that makes 'doc' function as a subdirectory of the main
CMake build system. This auto-detects Halibut, and if it's present,
uses it to build the man pages and the various forms of the main
manual, including the Windows CHM help file in particular.

One awkward thing I had to do was to move just one config directive in
blurb.but into its own file: the one that cites a relative path to the
stylesheet file to put into the CHM. CMake builds often like to be
out-of-tree, so there's no longer a fixed relative path between the
build directory and chm.css. And Halibut has no concept of an include
path to search for files cited by other files, so I can't fix that
with an -I option on the Halibut command line. So I moved that single
config directive into its own file, and had CMake write out a custom
version of that file in the build directory citing the right path.

(Perhaps in the longer term I should fix that omission in Halibut;
out-of-tree friendliness seems like a useful feature. But even if I
do, I still need this build to work now.)
2021-05-03 17:01:55 +01:00

63 lines
1.8 KiB
CMake

# Pure cmake script to write out cmake_commit.h
set(DEFAULT_COMMIT "unavailable")
set(commit "${DEFAULT_COMMIT}")
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${TOPLEVEL_SOURCE_DIR}
rev-parse --show-toplevel
OUTPUT_VARIABLE git_worktree
ERROR_VARIABLE stderr
RESULT_VARIABLE status)
string(REGEX REPLACE "\n$" "" git_worktree "${git_worktree}")
if(status EQUAL 0)
if(git_worktree STREQUAL TOPLEVEL_SOURCE_DIR)
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${TOPLEVEL_SOURCE_DIR}
rev-parse HEAD
OUTPUT_VARIABLE git_commit
ERROR_VARIABLE stderr
RESULT_VARIABLE status)
if(status EQUAL 0)
string(REGEX REPLACE "\n$" "" commit "${git_commit}")
else()
if(commit STREQUAL "unavailable")
message("Unable to determine git commit: 'git rev-parse HEAD' returned status ${status} and error output:\n${stderr}\n")
endif()
endif()
else()
if(commit STREQUAL "unavailable")
message("Unable to determine git commit: top-level source dir ${TOPLEVEL_SOURCE_DIR} is not the root of a repository")
endif()
endif()
else()
if(commit STREQUAL "unavailable")
message("Unable to determine git commit: 'git rev-parse --show-toplevel' returned status ${status} and error output:\n${stderr}\n")
endif()
endif()
if(OUTPUT_TYPE STREQUAL header)
file(WRITE "${OUTPUT_FILE}" "\
/*
* cmake_commit.h - string literal giving the source git commit, if known.
*
* Generated by cmake/gitcommit.cmake.
*/
const char commitid[] = \"${commit}\";
")
elseif(OUTPUT_TYPE STREQUAL halibut)
if(commit STREQUAL "unavailable")
file(WRITE "${OUTPUT_FILE}" "\
\\versionid no version information available
")
else()
file(WRITE "${OUTPUT_FILE}" "\
\\versionid built from git commit ${commit}
")
endif()
else()
message(FATAL_ERROR "Set OUTPUT_TYPE when running this script")
endif()