-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for building using CMake
- Loading branch information
1 parent
586601f
commit e51efc1
Showing
14 changed files
with
472 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
cmake_minimum_required(VERSION 3.27) | ||
|
||
project(dvisvgm VERSION 3.1.1) | ||
|
||
set(CMAKE_C_STANDARD 17) | ||
set(CMAKE_C_STANDARD_REQUIRED True) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
option(BUILD_SHARED "Build shared library" OFF) | ||
option(BUILD_TESTS "Build tests" ON) | ||
option(ENABLE_ASAN "Enable ASan" OFF) | ||
option(ENABLE_UBSAN "Enable UBSan" OFF) | ||
|
||
if (BUILD_SHARED) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") | ||
endif() | ||
if (ENABLE_ASAN) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -Og") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -Og") | ||
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=address") | ||
endif() | ||
if (ENABLE_UBSAN) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -Og") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -Og") | ||
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=undefined") | ||
endif() | ||
|
||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") | ||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") | ||
|
||
add_subdirectory(libs) | ||
add_subdirectory(src) | ||
if (BUILD_TESTS) | ||
add_subdirectory(tests) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include(FindPkgConfig) | ||
|
||
pkg_check_modules(freetype2 REQUIRED freetype2 IMPORTED_TARGET) | ||
add_library(freetype2 INTERFACE) | ||
target_link_libraries(freetype2 INTERFACE PkgConfig::freetype2) | ||
|
||
add_subdirectory(boost) | ||
add_subdirectory(brotli) | ||
add_subdirectory(clipper) | ||
add_subdirectory(md5) | ||
add_subdirectory(potrace) | ||
add_subdirectory(variant) | ||
add_subdirectory(woff2) | ||
add_subdirectory(xxHash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_library(boost INTERFACE) | ||
target_include_directories(boost INTERFACE .) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
pkg_check_modules(brotlienc libbrotlienc IMPORTED_TARGET) | ||
|
||
if (NOT brotlienc_FOUND) | ||
set(SOURCES | ||
common/constants.c | ||
common/context.c | ||
common/dictionary.c | ||
common/platform.c | ||
common/transform.c | ||
enc/backward_references.c | ||
enc/backward_references_hq.c | ||
enc/bit_cost.c | ||
enc/block_splitter.c | ||
enc/brotli_bit_stream.c | ||
enc/cluster.c | ||
enc/command.c | ||
enc/compound_dictionary.c | ||
enc/compress_fragment.c | ||
enc/compress_fragment_two_pass.c | ||
enc/dictionary_hash.c | ||
enc/encode.c | ||
enc/encoder_dict.c | ||
enc/entropy_encode.c | ||
enc/fast_log.c | ||
enc/histogram.c | ||
enc/literal_cost.c | ||
enc/memory.c | ||
enc/metablock.c | ||
enc/static_dict.c | ||
enc/utf8_util.c | ||
) | ||
add_library(brotli ${SOURCES}) | ||
target_include_directories(brotli PUBLIC include) | ||
target_compile_options(brotli PRIVATE -Wall) | ||
else() | ||
add_library(brotli INTERFACE) | ||
target_link_libraries(brotli INTERFACE PkgConfig::brotlienc) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_library(clipper clipper.cpp) | ||
target_include_directories(clipper PUBLIC .) | ||
target_compile_options(clipper PRIVATE -Wall) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_library(md5 md5.c) | ||
target_include_directories(md5 PUBLIC .) | ||
target_compile_options(md5 PRIVATE -Wall) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pkg_check_modules(potrace potrace IMPORTED_TARGET) | ||
|
||
if (NOT potrace_FOUND) | ||
add_library(potrace curve.c decompose.c potracelib.c trace.c) | ||
target_include_directories(potrace PUBLIC .) | ||
target_compile_definitions(potrace PRIVATE HAVE_CONFIG_H) | ||
target_compile_options(potrace PRIVATE -Wall) | ||
else() | ||
add_library(potrace INTERFACE) | ||
target_link_libraries(potrace INTERFACE PkgConfig::potrace) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_library(mpark_variant INTERFACE) | ||
target_include_directories(mpark_variant INTERFACE include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pkg_check_modules(woff2enc libwoff2enc IMPORTED_TARGET) | ||
|
||
if (NOT woff2enc_FOUND) | ||
set(SOURCES | ||
src/font.cc | ||
src/glyph.cc | ||
src/normalize.cc | ||
src/table_tags.cc | ||
src/transform.cc | ||
src/variable_length.cc | ||
src/woff2_common.cc | ||
src/woff2_enc.cc | ||
src/woff2_out.cc | ||
) | ||
add_library(woff2 ${SOURCES}) | ||
target_include_directories(woff2 PUBLIC include) | ||
target_compile_options(woff2 PRIVATE -Wall) | ||
target_link_libraries(woff2 PRIVATE brotli) | ||
else() | ||
add_library(woff2 INTERFACE) | ||
target_link_libraries(woff2 INTERFACE PkgConfig::woff2enc) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pkg_check_modules(xxhash libxxhash IMPORTED_TARGET) | ||
|
||
if (NOT xxhash_FOUND) | ||
add_library(xxhash xxhash.c) | ||
target_include_directories(xxhash PUBLIC .) | ||
target_compile_options(xxhash PRIVATE -Wall) | ||
else() | ||
add_library(xxhash INTERFACE) | ||
target_link_libraries(xxhash INTERFACE PkgConfig::xxhash) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
set(SOURCES | ||
BasicDVIReader.cpp | ||
Bezier.cpp | ||
BgColorSpecialHandler.cpp | ||
Bitmap.cpp | ||
BoundingBox.cpp | ||
Calculator.cpp | ||
CharMapID.cpp | ||
CLCommandLine.cpp | ||
CMap.cpp | ||
CMapManager.cpp | ||
CMapReader.cpp | ||
Color.cpp | ||
ColorSpecialHandler.cpp | ||
Directory.cpp | ||
DLLoader.cpp | ||
DVIReader.cpp | ||
DvisvgmSpecialHandler.cpp | ||
DVIToSVG.cpp | ||
DVIToSVGActions.cpp | ||
EllipticalArc.cpp | ||
EmSpecialHandler.cpp | ||
EncFile.cpp | ||
EPSFile.cpp | ||
FileFinder.cpp | ||
FilePath.cpp | ||
FileSystem.cpp | ||
Font.cpp | ||
FontCache.cpp | ||
FontEncoding.cpp | ||
FontEngine.cpp | ||
FontManager.cpp | ||
FontMap.cpp | ||
FontMetrics.cpp | ||
fonts/Base14Fonts.cpp | ||
fonts/Dingbats.cff.cpp | ||
fonts/NimbusMonoPS-Bold.cff.cpp | ||
fonts/NimbusMonoPS-BoldItalic.cff.cpp | ||
fonts/NimbusMonoPS-Italic.cff.cpp | ||
fonts/NimbusMonoPS-Regular.cff.cpp | ||
fonts/NimbusRoman-Bold.cff.cpp | ||
fonts/NimbusRoman-BoldItalic.cff.cpp | ||
fonts/NimbusRoman-Italic.cff.cpp | ||
fonts/NimbusRoman-Regular.cff.cpp | ||
fonts/NimbusSans-Bold.cff.cpp | ||
fonts/NimbusSans-BoldItalic.cff.cpp | ||
fonts/NimbusSans-Italic.cff.cpp | ||
fonts/NimbusSans-Regular.cff.cpp | ||
fonts/StandardSymbolsPS.cff.cpp | ||
FontWriter.cpp | ||
GFGlyphTracer.cpp | ||
GFReader.cpp | ||
GFTracer.cpp | ||
Ghostscript.cpp | ||
HashFunction.cpp | ||
HtmlSpecialHandler.cpp | ||
HyperlinkManager.cpp | ||
ImageToSVG.cpp | ||
InputBuffer.cpp | ||
InputReader.cpp | ||
JFM.cpp | ||
Length.cpp | ||
MapLine.cpp | ||
Matrix.cpp | ||
Message.cpp | ||
MetafontWrapper.cpp | ||
NoPsSpecialHandler.cpp | ||
OFM.cpp | ||
Opacity.cpp | ||
optimizer/AttributeExtractor.cpp | ||
optimizer/ClipPathReassigner.cpp | ||
optimizer/GroupCollapser.cpp | ||
optimizer/RedundantElementRemover.cpp | ||
optimizer/SVGOptimizer.cpp | ||
optimizer/TextSimplifier.cpp | ||
optimizer/TransformSimplifier.cpp | ||
optimizer/WSNodeRemover.cpp | ||
PageRanges.cpp | ||
PageSize.cpp | ||
PapersizeSpecialHandler.cpp | ||
PathClipper.cpp | ||
PDFHandler.cpp | ||
PDFParser.cpp | ||
PdfSpecialHandler.cpp | ||
PDFToSVG.cpp | ||
PreScanDVIReader.cpp | ||
Process.cpp | ||
psdefs.cpp | ||
PSInterpreter.cpp | ||
PSPattern.cpp | ||
PSPreviewHandler.cpp | ||
PsSpecialHandler.cpp | ||
RangeMap.cpp | ||
ShadingPatch.cpp | ||
SignalHandler.cpp | ||
SourceInput.cpp | ||
SpecialManager.cpp | ||
StreamReader.cpp | ||
StreamWriter.cpp | ||
Subfont.cpp | ||
SVGCharHandler.cpp | ||
SVGCharHandlerFactory.cpp | ||
SVGCharPathHandler.cpp | ||
SVGCharTspanTextHandler.cpp | ||
SVGElement.cpp | ||
SVGOutput.cpp | ||
SVGSingleCharTextHandler.cpp | ||
SVGTree.cpp | ||
System.cpp | ||
TensorProductPatch.cpp | ||
Terminal.cpp | ||
TFM.cpp | ||
ToUnicodeMap.cpp | ||
TpicSpecialHandler.cpp | ||
TriangularPatch.cpp | ||
ttf/CmapTable.cpp | ||
ttf/GlyfTable.cpp | ||
ttf/HeadTable.cpp | ||
ttf/HheaTable.cpp | ||
ttf/HmtxTable.cpp | ||
ttf/MaxpTable.cpp | ||
ttf/NameTable.cpp | ||
ttf/OS2Table.cpp | ||
ttf/PostTable.cpp | ||
ttf/TTFAutohint.cpp | ||
ttf/TTFTable.cpp | ||
ttf/TTFWriter.cpp | ||
ttf/VheaTable.cpp | ||
ttf/VmtxTable.cpp | ||
Unicode.cpp | ||
utility.cpp | ||
VFReader.cpp | ||
XMLDocument.cpp | ||
XMLNode.cpp | ||
XMLParser.cpp | ||
XMLString.cpp | ||
) | ||
|
||
# ===== dvisvgm library ===== | ||
if (BUILD_SHARED) | ||
add_library(dvisvgm SHARED ${SOURCES}) | ||
else() | ||
add_library(dvisvgm ${SOURCES}) | ||
endif() | ||
|
||
target_compile_options(dvisvgm PRIVATE -Wall) | ||
target_link_libraries(dvisvgm PUBLIC boost brotli clipper freetype2 kpathsea md5 mpark_variant potrace woff2 xxhash z) | ||
target_include_directories(dvisvgm INTERFACE .) | ||
|
||
include(CheckCXXSourceCompiles) | ||
check_cxx_source_compiles( | ||
"#include <signal.h> | ||
struct sigaction test; | ||
int main() {}" | ||
HAVE_SIGACTION) | ||
check_cxx_source_compiles( | ||
"#include <sys/stat.h> | ||
void f() { umask(0); } | ||
int main() {}" | ||
HAVE_UMASK) | ||
check_cxx_source_compiles( | ||
"int main() { __builtin_clz(1); }" | ||
HAVE___BUILTIN_CLZ) | ||
|
||
include(CheckIncludeFileCXX) | ||
CHECK_INCLUDE_FILE_CXX(unistd.h HAVE_UNISTD_H) | ||
CHECK_INCLUDE_FILE_CXX(sys/time.h HAVE_SYS_TIME_H) | ||
CHECK_INCLUDE_FILE_CXX(sys/timeb.h HAVE_SYS_TIMEB_H) | ||
CHECK_INCLUDE_FILE_CXX(termios.h HAVE_TERMIOS_H) | ||
|
||
configure_file(config.h.in config.h) | ||
target_include_directories(dvisvgm PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
target_compile_definitions(dvisvgm PUBLIC DVISVGM_CMAKE_BUILD) | ||
|
||
|
||
# ===== dvisvgm executable ===== | ||
add_executable(dvisvgm_exe dvisvgm.cpp) | ||
target_link_libraries(dvisvgm_exe PRIVATE dvisvgm) | ||
set_target_properties(dvisvgm_exe PROPERTIES OUTPUT_NAME "dvisvgm") | ||
|
||
install(TARGETS dvisvgm_exe) | ||
|
||
|
||
# ===== texmf.cnf ===== | ||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
option(TEXMF_CNF_PATH "Path to texmf.cnf file") | ||
option(TEX_DISTRIBUTION_PATH "Path to TeX Live distribution (i. e. /usr/share/texmf-dist)") | ||
|
||
# Try to find determine paths automatically | ||
if (NOT TEXMF_CNF_PATH AND NOT TEX_DISTRIBUTION_PATH) | ||
execute_process(COMMAND which kpsewhich OUTPUT_VARIABLE kpsewhich_path) | ||
execute_process(COMMAND kpsewhich -format=cnf texmf.cnf OUTPUT_VARIABLE texmf_path) | ||
|
||
if (NOT kpsewhich_path STREQUAL "" AND NOT texmf_path STREQUAL "") | ||
string(STRIP "${texmf_path}" texmf_stripped_path) | ||
set(TEXMF_CNF_PATH "${texmf_stripped_path}" CACHE PATH "" FORCE) | ||
|
||
cmake_path(REMOVE_FILENAME kpsewhich_path OUTPUT_VARIABLE kpsewhich_folder) | ||
set(distribution_raw_path "${kpsewhich_folder}/../share/texmf-dist") | ||
cmake_path(NORMAL_PATH distribution_raw_path OUTPUT_VARIABLE distribution_path) | ||
|
||
set(TEX_DISTRIBUTION_PATH "${distribution_path}" CACHE PATH "" FORCE) | ||
endif() | ||
endif() | ||
|
||
if (TEXMF_CNF_PATH AND TEX_DISTRIBUTION_PATH) | ||
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/texmf.cnf" | ||
COMMAND cp "${TEXMF_CNF_PATH}" "${CMAKE_BINARY_DIR}/texmf.cnf" | ||
COMMAND sed -i "'s:$$SELFAUTODIR:${TEX_DISTRIBUTION_PATH}/../..:g'" "${CMAKE_BINARY_DIR}/texmf.cnf") | ||
add_custom_target(texmf_generation DEPENDS "${CMAKE_BINARY_DIR}/texmf.cnf") | ||
add_dependencies(dvisvgm texmf_generation) | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/************************************************************************* | ||
** config.h.in ** | ||
** ** | ||
** This file is part of dvisvgm -- a fast DVI to SVG converter ** | ||
** Copyright (C) 2005-2023 Martin Gieseking <[email protected]> ** | ||
** ** | ||
** This program is free software; you can redistribute it and/or ** | ||
** modify it under the terms of the GNU General Public License as ** | ||
** published by the Free Software Foundation; either version 3 of ** | ||
** the License, or (at your option) any later version. ** | ||
** ** | ||
** This program is distributed in the hope that it will be useful, but ** | ||
** WITHOUT ANY WARRANTY; without even the implied warranty of ** | ||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | ||
** GNU General Public License for more details. ** | ||
** ** | ||
** You should have received a copy of the GNU General Public License ** | ||
** along with this program; if not, see <http://www.gnu.org/licenses/>. ** | ||
*************************************************************************/ | ||
|
||
#ifndef CONFIG_H_IN | ||
#define CONFIG_H_IN | ||
|
||
#cmakedefine HAVE___BUILTIN_CLZ | ||
#cmakedefine HAVE_SIGACTION | ||
#cmakedefine HAVE_SYS_TIME_H | ||
#cmakedefine HAVE_SYS_TIMEB_H | ||
#cmakedefine HAVE_TERMIOS_H | ||
#cmakedefine HAVE_UMASK | ||
#cmakedefine HAVE_UNISTD_H | ||
|
||
#endif |
Oops, something went wrong.