89 lines
2.4 KiB
CMake
89 lines
2.4 KiB
CMake
cmake_minimum_required(VERSION 3.1)
|
|
|
|
project(thesis)
|
|
|
|
set(LATEX_COMPILER_FLAGS "-interaction=batchmode -file-line-error -shell-escape"
|
|
CACHE STRING "Flags passed to latex.")
|
|
include(UseLATEX.cmake)
|
|
|
|
# Global
|
|
set(LATEX_USE_SYNCTEX ON)
|
|
set(imgdir img)
|
|
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pdf)
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/buildfig)
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/figures)
|
|
|
|
# Functions
|
|
macro(subdirlist result curdir)
|
|
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${curdir}/*)
|
|
foreach(child ${children})
|
|
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child})
|
|
subdirlist(${result} ${child})
|
|
list(APPEND ${result} ${child})
|
|
endif()
|
|
endforeach()
|
|
endmacro()
|
|
|
|
set(imgdirs ${imgdir})
|
|
subdirlist(imgdirs ${imgdir})
|
|
|
|
# Document
|
|
set(modes oneside twoside print genfigures)
|
|
set(srcdir src)
|
|
set(stydir sty)
|
|
|
|
file(GLOB_RECURSE src RELATIVE ${CMAKE_SOURCE_DIR} ${srcdir}/*.tex)
|
|
file(GLOB_RECURSE bib RELATIVE ${CMAKE_SOURCE_DIR} ${srcdir}/*.bib)
|
|
file(GLOB_RECURSE sty RELATIVE ${CMAKE_SOURCE_DIR} ${stydir}/*.sty)
|
|
|
|
set(latex_document_options)
|
|
set(custom_command_options ALL)
|
|
|
|
foreach(mode ${modes})
|
|
set(maintex main_${mode})
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
|
|
${CMAKE_CURRENT_BINARY_DIR}/${srcdir}/${maintex}.tex
|
|
${CMAKE_CURRENT_BINARY_DIR}/${maintex}.tex
|
|
)
|
|
|
|
add_latex_document(
|
|
${srcdir}/main_${mode}.tex
|
|
INPUTS ${src} ${lst} ${sty}
|
|
BIBFILES ${bib}
|
|
IMAGE_DIRS ${imgdirs}
|
|
USE_BIBLATEX
|
|
USE_GLOSSARY
|
|
${latex_document_options}
|
|
)
|
|
|
|
if(NOT ${mode} STREQUAL genfigures)
|
|
set(synctex_file ${CMAKE_PROJECT_NAME}_${mode}.synctex.gz)
|
|
add_custom_target(pdf_${synctex_file} ${custom_command_options}
|
|
DEPENDS ${maintex}.pdf
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${maintex}.synctex.gz pdf/${synctex_file}
|
|
)
|
|
|
|
set(pdf_file ${CMAKE_PROJECT_NAME}_${mode}.pdf)
|
|
add_custom_target(pdf_${pdf_file} ${custom_command_options}
|
|
DEPENDS ${maintex}.pdf
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${maintex}.pdf pdf/${pdf_file}
|
|
)
|
|
|
|
add_custom_target(pdf_${CMAKE_PROJECT_NAME}_${mode} DEPENDS pdf_${synctex_file} pdf_${pdf_file})
|
|
endif()
|
|
|
|
set(latex_document_options EXCLUDE_FROM_ALL)
|
|
set(custom_command_options)
|
|
endforeach()
|
|
|
|
add_custom_target(generate_figures
|
|
DEPENDS main_genfigures_pdf
|
|
)
|
|
|
|
add_custom_command(TARGET generate_figures POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/buildfig/*.pdf
|
|
${CMAKE_CURRENT_BINARY_DIR}/figures
|
|
)
|