-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
215 lines (160 loc) · 7.7 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
cmake_minimum_required(VERSION 3.12..3.26)
project(docling_parse VERSION 1.0.0 LANGUAGES CXX C)
#set(CMAKE_VERBOSE_MAKEFILE off)
message(STATUS "cmake osx-deployment: " ${CMAKE_OSX_DEPLOYMENT_TARGET})
# minimum macosx, ignored on other platforms
if(APPLE)
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
message(STATUS "cmake is not set")
elseif(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.15)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum macOS version" FORCE)
endif()
endif()
message(STATUS "cmake system-version: " ${CMAKE_SYSTEM_VERSION})
message(STATUS "cmake osx-deployment: " ${CMAKE_OSX_DEPLOYMENT_TARGET})
# ************************
# *** paths ***
# ************************
if(NOT DEFINED TOPLEVEL_PREFIX_PATH)
set(TOPLEVEL_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${TOPLEVEL_PREFIX_PATH}/install_dir)
endif()
if(NOT DEFINED EXTERNALS_PREFIX_PATH)
set(EXTERNALS_PREFIX_PATH "${TOPLEVEL_PREFIX_PATH}/externals" CACHE INTERNAL "")
endif()
if(NOT DEFINED RESOURCES_PREFIX_PATH)
set(RESOURCES_PREFIX_PATH "${TOPLEVEL_PREFIX_PATH}/resources" CACHE INTERNAL "")
endif()
if(NOT "${TOPLEVEL_PREFIX_PATH}/cmake" IN_LIST CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${TOPLEVEL_PREFIX_PATH}/cmake")
endif()
if(NOT DEFINED CMAKE_PDF_DATA_DIR)
set(CMAKE_PDF_DATA_DIR "${TOPLEVEL_PREFIX_PATH}/docling_parse/pdf_resources")
endif()
set(ENV_ARCH $ENV{CIBW_ARCHS})
message(STATUS "cibw arch: " ${ENV_ARCH})
set(CMAKE_OSX_ARCHITECTURES $ENV{CIBW_ARCHS})
#message(STATUS "cibw arch: " ${ENV_ARCH})
set(ENV_ARCHFLAGS $ENV{ARCHFLAGS})
message(STATUS "arch flags: " ${ENV_ARCHFLAGS})
message(STATUS " top path: " ${TOPLEVEL_PREFIX_PATH})
message(STATUS " lib path: " ${EXTERNALS_PREFIX_PATH})
message(STATUS " install path: " ${CMAKE_INSTALL_PREFIX})
message(STATUS " cmake path: " ${CMAKE_MODULE_PATH})
message(STATUS " cmake system: " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "cmake osx arch: " ${CMAKE_OSX_ARCHITECTURES})
# ************************
# *** cxx-flags ***
# ************************
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-sign-compare -g3 -DROOT_PATH='\"${TOPLEVEL_PREFIX_PATH}\"' ${ENV_ARCHFLAGS}")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-sign-compare -O3 -DROOT_PATH='\"${TOPLEVEL_PREFIX_PATH}\"' ${ENV_ARCHFLAGS}")
if (WIN32)
set(TEST_PATH "\\\"${TOPLEVEL_PREFIX_PATH}\\\"")
add_definitions(-DROOT_PATH="\\\"${TOPLEVEL_PREFIX_PATH}\\\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-sign-compare -O3 ${ENV_ARCHFLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-sign-compare -O3 -DROOT_PATH='\"${TOPLEVEL_PREFIX_PATH}\"' ${ENV_ARCHFLAGS}")
endif()
message(STATUS "cxx-compiler: " ${CMAKE_CXX_COMPILER})
message(STATUS "cxx-flags : " ${CMAKE_CXX_FLAGS})
message(STATUS "cxx-standard: " ${CMAKE_CXX_STANDARD})
# ************************
# *** dependencies ***
# ************************
option(USE_SYSTEM_DEPS OFF "If enabled, the build will find and link to system dependencies, otherwise they are sourced from the original repos and compiled on the fly.")
# prepare setup for building external packages
if(NOT USE_SYSTEM_DEPS)
if(NOT EXISTS ${EXTERNALS_PREFIX_PATH})
file(MAKE_DIRECTORY ${EXTERNALS_PREFIX_PATH})
file(MAKE_DIRECTORY ${EXTERNALS_PREFIX_PATH}/bin)
file(MAKE_DIRECTORY ${EXTERNALS_PREFIX_PATH}/lib)
file(MAKE_DIRECTORY ${EXTERNALS_PREFIX_PATH}/include)
file(MAKE_DIRECTORY ${EXTERNALS_PREFIX_PATH}/resources)
endif()
endif()
# include dependencies
include(cmake/extlib_cxxopts.cmake)
include(cmake/extlib_loguru.cmake)
include(cmake/extlib_json.cmake)
include(cmake/extlib_utf8.git.cmake)
include(cmake/extlib_jpeg.cmake)
include(cmake/extlib_qpdf_v11.cmake)
# aggregate the targets created by the dependencies
set(DEPENDENCIES qpdf jpeg utf8 json loguru cxxopts)
# ************************
# *** libraries ***
# ************************
# define LIB_LINK and OS_DEPENDENCIES
include(cmake/os_opts.cmake)
list(APPEND DEPENDENCIES ${OS_DEPENDENCIES})
# ***********************
# *** includes ***
# ***********************
# define subdirlist utility
include(cmake/subdirlist.cmake)
include_directories(${TOPLEVEL_PREFIX_PATH}/src)
subdirlist(SUBDIRS ${TOPLEVEL_PREFIX_PATH}/src)
message(STATUS "subdirs: " ${SUBDIRS})
include_directories(${SUBDIRS})
# **********************
# *** Executables ***
# **********************
string(REPLACE ";" ";" SUBDIRS_SEMICOLON "${SUBDIRS}")
message(STATUS "subdirs: ${SUBDIRS_SEMICOLON}")
string(REPLACE ";" ";" DEPENDENCIES_SEMICOLON "${DEPENDENCIES}")
message(STATUS "cmake dependencies: ${DEPENDENCIES_SEMICOLON}")
string(REPLACE ";" ";" LIBLINK_SEMICOLON "${LIB_LINK}")
message(STATUS "cmake lib-link: ${LIBLINK_SEMICOLON}")
add_executable(parse_v1.exe "${TOPLEVEL_PREFIX_PATH}/app/parse_v1.cpp")
add_executable(parse_v2.exe "${TOPLEVEL_PREFIX_PATH}/app/parse_v2.cpp")
add_executable(parse_v2_fonts.exe "${TOPLEVEL_PREFIX_PATH}/app/parse_v2_fonts.cpp")
set_property(TARGET parse_v1.exe PROPERTY CXX_STANDARD 20)
set_property(TARGET parse_v2.exe PROPERTY CXX_STANDARD 20)
set_property(TARGET parse_v2_fonts.exe PROPERTY CXX_STANDARD 20)
add_dependencies(parse_v1.exe ${DEPENDENCIES})
add_dependencies(parse_v2.exe ${DEPENDENCIES})
add_dependencies(parse_v2_fonts.exe ${DEPENDENCIES})
target_include_directories(parse_v1.exe INTERFACE ${DEPENDENCIES})
target_include_directories(parse_v2.exe INTERFACE ${DEPENDENCIES})
target_include_directories(parse_v2_fonts.exe INTERFACE ${DEPENDENCIES})
target_link_libraries(parse_v1.exe ${DEPENDENCIES} ${LIB_LINK})
target_link_libraries(parse_v2.exe ${DEPENDENCIES} ${LIB_LINK})
target_link_libraries(parse_v2_fonts.exe ${DEPENDENCIES} ${LIB_LINK})
# **********************
# *** Libraries ***
# **********************
add_library(parse_v1 STATIC "${TOPLEVEL_PREFIX_PATH}/app/parse_v1.cpp")
add_library(parse_v2 STATIC "${TOPLEVEL_PREFIX_PATH}/app/parse_v1.cpp")
add_dependencies(parse_v1 ${DEPENDENCIES})
add_dependencies(parse_v2 ${DEPENDENCIES})
target_include_directories(parse_v1 INTERFACE ${DEPENDENCIES})
target_include_directories(parse_v2 INTERFACE ${DEPENDENCIES})
set_target_properties(parse_v1 PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(parse_v2 PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(parse_v1 ${DEPENDENCIES} ${LIB_LINK})
target_link_libraries(parse_v2 ${DEPENDENCIES} ${LIB_LINK})
# ***************************
# *** Python-binding ***
# ***************************
# https://pybind11.readthedocs.io/en/stable/compiling.html
# https://pybind11.readthedocs.io/en/stable/compiling.html#configuration-variables
find_package(pybind11 CONFIG REQUIRED)
#pybind11_add_module(docling_parse "${TOPLEVEL_PREFIX_PATH}/app/pybind_parse.cpp")
pybind11_add_module(pdf_parsers "${TOPLEVEL_PREFIX_PATH}/app/pybind_parse.cpp")
#add_dependencies(docling_parse parse_v1 parse_v2)
add_dependencies(pdf_parsers parse_v1 parse_v2)
#target_include_directories(docling_parse INTERFACE ${DEPENDENCIES})
target_include_directories(pdf_parsers INTERFACE ${DEPENDENCIES})
#target_compile_definitions(docling_parse PRIVATE VERSION_INFO=${CMAKE_PROJECT_VERSION})
target_compile_definitions(pdf_parsers PRIVATE VERSION_INFO=${CMAKE_PROJECT_VERSION})
#target_link_libraries(docling_parse PRIVATE parse_v1 parse_v2)
target_link_libraries(pdf_parsers PRIVATE parse_v1 parse_v2)
# *****************
# *** Install ***
# *****************
#install(TARGETS docling_parse DESTINATION "${TOPLEVEL_PREFIX_PATH}/docling_parse")
install(TARGETS pdf_parsers DESTINATION "${TOPLEVEL_PREFIX_PATH}/docling_parse")