Skip to content

Commit 9405a69

Browse files
chore: improve manpage building logic
* Use TARGET_FILE generator expression to get the executable path. * Only build man-pages for binaries that are being built/installed. * Skip the RUNTIME_OUTPUT_DIRECTORY logic; it's not really necessary. * Skip setting up CMAKE_INSTALL_MANDIR; it's already set up by GNUInstallDirs. * Pass --no-info to help2man; there are no Info pages for jsonnet.
1 parent a16d93a commit 9405a69

2 files changed

Lines changed: 32 additions & 26 deletions

File tree

CMakeLists.txt

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ option(BUILD_TESTS "Build and run jsonnet tests." ON)
4848
option(BUILD_STATIC_LIBS "Build a static libjsonnet." ON)
4949
option(BUILD_SHARED_LIBS "Build shared libjsonnet." ON)
5050
option(BUILD_SHARED_BINARIES "Link binaries to the shared libjsonnet instead of the static one." OFF)
51-
option(BUILD_MAN_PAGES "Build manpages." OFF)
51+
option(BUILD_MAN_PAGES "Build manpages." ON)
5252
option(USE_SYSTEM_GTEST "Use system-provided gtest library" OFF)
5353
option(USE_SYSTEM_JSON "Use the system-provided json library" OFF)
5454
# TODO: Support using a system Rapid YAML install.
@@ -330,37 +330,40 @@ endif() # if(BUILD_TESTS)
330330
#### Man pages
331331
#
332332

333-
if(BUILD_MAN_PAGES)
333+
if(BUILD_MAN_PAGES AND (BUILD_JSONNET OR BUILD_JSONNETFMT))
334334
find_program(HELP2MAN_BINARY NAMES help2man)
335335
if (HELP2MAN_BINARY)
336336
message(STATUS "help2man found, man pages will be generated.")
337-
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1)
338-
set(CMAKE_INSTALL_MANDIR "share/man" CACHE STRING "Directory for man pages")
339-
340-
add_custom_command(
341-
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1
342-
COMMAND ${HELP2MAN_BINARY}
343-
ARGS --section=1 --name="Jsonnet data templating language interpreter" --output=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/jsonnet
344-
DEPENDS jsonnet
345-
)
346-
add_custom_command(
347-
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1
348-
COMMAND ${HELP2MAN_BINARY}
349-
ARGS --section=1 --name="Jsonnet data templating language interpreter" --output=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/jsonnetfmt
350-
DEPENDS jsonnetfmt
351-
)
352-
353-
add_custom_target(jsonnet-man ALL DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1)
354-
add_custom_target(jsonnetfmt-man ALL DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1)
355-
356-
install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
357-
install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
337+
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/man/man1")
338+
if(BUILD_JSONNET)
339+
add_custom_command(
340+
OUTPUT "${PROJECT_BINARY_DIR}/man/man1/jsonnet.1"
341+
COMMAND "${HELP2MAN_BINARY}"
342+
ARGS --section=1 --no-info --name="Jsonnet data templating language interpreter" --output="${PROJECT_BINARY_DIR}/man/man1/jsonnet.1" "$<TARGET_FILE:jsonnet>"
343+
DEPENDS jsonnet
344+
)
345+
endif()
346+
if(BUILD_JSONNETFMT)
347+
add_custom_command(
348+
OUTPUT "${PROJECT_BINARY_DIR}/man/man1/jsonnetfmt.1"
349+
COMMAND "${HELP2MAN_BINARY}"
350+
ARGS --section=1 --no-info --name="Jsonnet data templating language auto-formatter" --output="${PROJECT_BINARY_DIR}/man/man1/jsonnetfmt.1" "$<TARGET_FILE:jsonnetfmt>"
351+
DEPENDS jsonnetfmt
352+
)
353+
endif()
354+
355+
add_custom_target(jsonnet-man ALL DEPENDS "${PROJECT_BINARY_DIR}/man/man1/jsonnet.1")
356+
add_custom_target(jsonnetfmt-man ALL DEPENDS "${PROJECT_BINARY_DIR}/man/man1/jsonnetfmt.1")
357+
358+
install(FILES ${PROJECT_BINARY_DIR}/man/man1/jsonnet.1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
359+
install(FILES ${PROJECT_BINARY_DIR}/man/man1/jsonnetfmt.1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
358360
else()
359361
message(STATUS "help2man not found, man pages will not be generated.")
360362
endif()
361363
endif() # if(BUILD_MAN_PAGES)
362364

363-
# --- CMake debugging outputs.
365+
#### CMake debugging outputs
366+
#
364367

365368
# Note cmake_language GET_MESSAGE_LOG_LEVEL exists only in 3.25 and above.
366369
if(CMAKE_VERSION VERSION_GREATER "3.25")
@@ -380,7 +383,9 @@ if(CMAKE_VERSION VERSION_GREATER "3.25")
380383
jsonnet_cpp_shared
381384
jsonnet_cmd_utils
382385
jsonnet
383-
jsonnetfmt
386+
jsonnetfmt
387+
jsonnet-man
388+
jsonnetfmt-man
384389
PROPERTIES
385390
TYPE
386391
C_STANDARD
@@ -394,6 +399,7 @@ if(CMAKE_VERSION VERSION_GREATER "3.25")
394399
INTERFACE_INCLUDE_DIRECTORIES
395400
OUTPUT_NAME
396401
PUBLIC_HEADER
402+
RUNTIME_OUTPUT_DIRECTORY
397403
)
398404
endif()
399405
endif()

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ core/desugarer.cpp: core/std.jsonnet.h
169169
# Target to generate the man page
170170

171171
$(MAN1_DIR)/%.1: % | $(MAN1_DIR)
172-
$(HELP2MAN) --output=$@ ./$<
172+
$(HELP2MAN) --no-info --output=$@ ./$<
173173

174174
man: $(addprefix $(MAN1_DIR)/, $(BINS:=.1))
175175

0 commit comments

Comments
 (0)