Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of file names, introduced by support for minted #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions UseLatexMk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ function(add_latex_document)
endif()
endif()

# Determine the output name
get_filename_component(output ${LMK_SOURCE} NAME_WE)
set(OUTPUT_PDF ${CMAKE_CURRENT_BINARY_DIR}/${output}.pdf)

# Inspect the EXCLUDE_FROM_ALL option
if(LMK_EXCLUDE_FROM_ALL)
set(ALL_OPTION "")
Expand Down Expand Up @@ -217,10 +213,21 @@ function(add_latex_document)
set(ENV_COMMAND ${CMAKE_COMMAND} -E env openout_any="a")
endif()

# Get an absolute path to the source
set(LMK_SOURCE_REPLACED ${CMAKE_CURRENT_BINARY_DIR}/${LMK_TARGET}_source.cc)
# For LaTeX package minted, replace value of outputdir from CMAKE_CURRENT_BINARY_DIR to
# its actual value by coping the LaTeX file to the build dir
set(LMK_SOURCE_REPLACED ${CMAKE_CURRENT_BINARY_DIR}/${LMK_SOURCE})
# for in-source-build, adjust
if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
get_filename_component(source_filename ${LMK_SOURCE} NAME_WE)
get_filename_component(source_extension ${LMK_SOURCE} LAST_EXT)
set(LMK_SOURCE_REPLACED "${CMAKE_CURRENT_BINARY_DIR}/${source_filename}_source${source_extension}")
endif()
Comment on lines +216 to +224
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dokempf We could search the LaTeX source file and check whether it conains "@CMAKE_CURRNET_SOURCE_DIR@". Only in this case, we have to do the configure_file and renaming steps.
This could help with in-source builds to get the same file name, unless they really use minted. I would prefer this but I wanted to know your opinion.

configure_file(${LMK_SOURCE} ${LMK_SOURCE_REPLACED} @ONLY)

# Determine the output name
get_filename_component(output ${LMK_SOURCE_REPLACED} NAME_WE)
set(OUTPUT_PDF ${CMAKE_CURRENT_BINARY_DIR}/${output}.pdf)

# Call the latexmk executable
# NB: Using add_custom_target here results in the target always being outofdate.
# This offloads the dependency tracking from cmake to latexmk. This is an
Expand Down