forked from KiCad/kicad-doc
-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
155 lines (123 loc) · 5.74 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#
# Part of the KiCad ASCIIDOC Documentation Project
#
# (c)2015 KiCad Developers
# (c)2015 Brian Sidebotham <[email protected]>
#
# Require CMake V2.8 as a minimum. You can experiment with setting this lower if that's all you
# have available, but it's not guaranteed to work or be supported.
cmake_minimum_required( VERSION 2.8 )
project( KiCadDocumentation NONE )
# Provide an option for deciding which PDF generation scheme to use
# Desired targets are DBLATEX,FOP and ASCIIDOCTOR-PDF
set( PDF_GENERATOR "DBLATEX" CACHE STRING "Specify which PDF generator to use: DBLATEX|FOP" )
# Provide an option for a single language build. If nothing else, this will at
# least help developers to speed up a build they're working on
set( SINGLE_LANGUAGE "" CACHE STRING "Specify a single language to build: en|fr|it|ja|nl|pl" )
# Provide an option to decide which documentation formats to build.
set( BUILD_FORMATS "html;pdf;epub" CACHE LIST "Specify which output formats to build html/pdf/epub" )
# Add our custom modules to the module path
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules" ${CMAKE_MODULE_PATH} )
# Include the Asciidoc target helpers
include( AsciidocHelpers )
# Add the common asciidoc options
add_adoc_option( -b html5 )
add_adoc_option( -a toc2 )
add_adoc_option( --section-numbers )
add_adoc_option( --theme flask )
# Add the common a2x options
add_a2x_option( --xsltproc-opts=--nonet )
add_a2x_option( --no-xmllint )
add_a2x_option( -f pdf )
#add_a2x_option( --verbose )
# Add a2x options depending on which PDF generator we're using
if( ${PDF_GENERATOR} MATCHES DBLATEX )
# When the a2x target macro knows we're using dblatex, it adds in the
# --dblatex-opts command and uses the following options for that
add_dblatex_option( -P latex.output.revhistory=0 )
add_dblatex_option( -P doc.publisher.show=0 )
add_dblatex_option( -s ${PROJECT_SOURCE_DIR}/CMakeSupport/pdf-cover-dblatex.sty )
find_package( DBLATEX REQUIRED )
endif()
if( ${PDF_GENERATOR} MATCHES FOP )
add_a2x_option( --fop )
add_a2x_option( --xsl-file ${PROJECT_SOURCE_DIR}/xsl/kicad.xsl )
find_package( FOP REQUIRED )
endif()
if( ${PDF_GENERATOR} MATCHES ASCIIDOCTORPDF )
message( FATAL_ERROR "AsciiDoctor-pdf is not currently supported!" )
# Discover if the AsciiDoctor toolchain is available
# find_package( ASCIIDOCTOR )
# find_package( ASCIIDOCTORPDF )
endif()
# Discover if the PO4A package is available
find_package( PO4A REQUIRED )
# Discover if the Asciidoc toolchain is available
find_package( ASCIIDOC REQUIRED )
find_package( A2X REQUIRED )
include( KiCadDocumentation )
add_subdirectory( src )
# Start with the package version being unknown, then prove otherwise
set( CPACK_PACKAGE_VERSION "unknown" )
# Use Git to determine parts of the package name
find_package( Git )
if( GIT_FOUND )
# Discover information about the build (AT CONFIGURE TIME, not as a target that updates in
# subsequent builds)
execute_process( COMMAND "${GIT_EXECUTABLE}" describe --tags
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE git_tags_output
RESULT_VARIABLE git_tags_result
ERROR_VARIABLE git_tags_error
OUTPUT_STRIP_TRAILING_WHITESPACE )
execute_process( COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE git_branch_output
RESULT_VARIABLE git_branch_result
ERROR_VARIABLE git_branch_error
OUTPUT_STRIP_TRAILING_WHITESPACE )
# Due to how tags work in Git it's necessary for us to ensure a few things. For a start, if we
# create a new branch, switch to it and create a tag, that tag becomes visible in the master
# branch. Make sure if we're on the master branch that we use that in the
if( "${git_branch_output}" STREQUAL "master" )
# TODO: Should we include a 6-digit hash here too?
set( CPACK_PACKAGE_VERSION "master" )
else()
if( NOT "${git_tags_output}" STREQUAL "" )
# Make sure the tag is associated with the current branch. Otherwise we'll use the branch
# name instead. The tag and branch schema means we need branches in the format 1.0, 2.0,
# etc. and tags in the format 1.0.1, 2.0.1, etc. to match
string( SUBSTRING "${git_tags_output}" 0 3 GIT_TAG )
if( "${GIT_TAG}" STREQUAL "${git_branch_output}" )
# The tag matches the branch so use the tag as the package version
set( CPACK_PACKAGE_VERSION ${git_tags_output} )
else()
# Tag didn't match so assume it's there in error and use the more generic branch
# name as the package version instead
set( CPACK_PACKAGE_VERSION ${git_branch_output} )
endif()
endif()
endif()
endif()
# Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
set( KICAD_DOC_INSTALL_PATH share/doc/kicad
CACHE PATH "Install path of KiCad documentation files relative to CMAKE_INSTALL_PREFIX." )
# Set the language in the package name if the package only contains a single
# language
if( "${SINGLE_LANGUAGE}" STREQUAL "" )
set( PACKAGE_LANGUAGE "" )
else()
set( PACKAGE_LANGUAGE "-${SINGLE_LANGUAGE}" )
endif()
# If there is more than one build format, do not bother transforming the
# package name, otherwise if there's only one, add it to the package name
list( LENGTH BUILD_FORMATS BUILD_FORMATS_LENGTH )
if( ${BUILD_FORMATS_LENGTH} GREATER 1 )
set( PACKAGE_BUILD_FORMAT "" )
else()
set( PACKAGE_BUILD_FORMAT "-${BUILD_FORMATS}" )
endif()
# Generate both .tar.gz and .zip package targets
set( CPACK_GENERATOR "TGZ;ZIP" )
set( CPACK_PACKAGE_FILE_NAME "kicad-doc${PACKAGE_BUILD_FORMAT}${PACKAGE_LANGUAGE}-${CPACK_PACKAGE_VERSION}" )
include( CPack )