-
Notifications
You must be signed in to change notification settings - Fork 255
/
CMakeLists.txt
368 lines (331 loc) · 12.8 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
set(CMAKE_VERBOSE_MAKEFILE ON)
cmake_minimum_required(VERSION 3.16)
# The version is defined in 2 places:
# - pyproject.toml
# - this file, next line
project(frepple VERSION 9.5.0)
set(PROJECT_EDITION "Community Edition")
set(PROJECT_BRANCH "community")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
# Detect the linux distribution
if(EXISTS "/etc/issue")
file(READ "/etc/issue" LINUX_ISSUE)
# Ubuntu 24
if(LINUX_ISSUE MATCHES "Ubuntu 24")
set(CPACK_GENERATOR "DEB")
set(DISTRO "ubuntu24")
# Ubuntu development
elseif(LINUX_ISSUE MATCHES "Ubuntu.*development")
set(CPACK_GENERATOR "DEB")
set(DISTRO "ubuntudevel")
endif()
endif()
if(NOT DISTRO)
message(WARNING "FrePPLe has not been tested on this linux distribution.")
endif()
endif()
# Check third party libraries
if(WIN32)
# Some hard-coded paths for third party libraries on Windows.
set(XERCESC_FOLDER "/develop/xerces-c-3.2.3")
if(EXISTS "${XERCESC_FOLDER}")
include_directories("${XERCESC_FOLDER}/include")
list(APPEND CMAKE_REQUIRED_INCLUDES "${XERCESC_FOLDER}/include")
add_library(xerces-c STATIC IMPORTED)
set_target_properties(xerces-c PROPERTIES
IMPORTED_LOCATION_DEBUG "${XERCESC_FOLDER}/lib/xerces-c_3D.lib"
IMPORTED_LOCATION_RELEASE "${XERCESC_FOLDER}/lib/xerces-c_3.lib"
IMPORTED_LOCATION_MINSIZEREL "${XERCESC_FOLDER}/lib/xerces-c_3.lib"
IMPORTED_LOCATION_RELWITHDEBINFO "${XERCESC_FOLDER}/lib/xerces-c_3.lib"
)
endif()
# PostgreSQL ZIP-installer from https://www.enterprisedb.com/download-postgresql-binaries
# Used to embed PostgreSQL in frepple's windows installer
set(POSTGRES_FOLDER "c:/develop/pgsql")
else()
find_library(xerces-c NAMES xerces-c)
if(NOT xerces-c)
message(FATAL_ERROR "xerces-c library not found")
endif()
endif()
if(UNIX)
set(CMAKE_INSTALL_PREFIX "/")
include(GNUInstallDirs)
else()
set(CMAKE_INSTALL_LIBDIR "bin")
set(CMAKE_INSTALL_SYSCONFDIR "custom")
set(CMAKE_INSTALL_DATADIR "custom")
set(CMAKE_INSTALL_BINDIR "custom")
set(CMAKE_INSTALL_INCLUDEDIR "include")
endif()
# Check python and create the virtualenv
if(WIN32)
set(Python3_VENV "${PROJECT_SOURCE_DIR}/venv/Scripts")
else()
set(Python3_VENV "${PROJECT_SOURCE_DIR}/venv/bin")
endif()
find_package(Python3 3.8 COMPONENTS Interpreter Development REQUIRED)
add_custom_command(
OUTPUT venv.stamp
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt" "${CMAKE_CURRENT_SOURCE_DIR}/requirements.dev.txt"
COMMAND "${Python3_EXECUTABLE}" -m venv "${PROJECT_SOURCE_DIR}/venv" || cd .
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/requirements.dev.txt" requirements.dev.txt
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt" requirements.txt
COMMAND "${Python3_VENV}/pip" install -r requirements.dev.txt
COMMAND ${CMAKE_COMMAND} -E touch venv.stamp
)
add_custom_target(venv DEPENDS venv.stamp)
find_program(npm NAMES npm)
find_program(grunt NAMES grunt)
if(grunt)
add_custom_target(
grunt
COMMAND grunt
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endif()
# C++ compiler flags and features
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(WIN32)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /EHsc /MP8 ")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG /MTd /EHsc /MP8 ")
add_definitions("-D_CRT_SECURE_NO_DEPRECATE")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=date-time")
set(CMAKE_CXX_FLAGS_PROFILING "${CMAKE_CXX_FLAGS_DEBUG} -DNDEBUG")
set(CMAKE_C_FLAGS_PROFILING "${CMAKE_C_FLAGS_DEBUG} -DNDEBUG")
set(CMAKE_EXE_LINKER_FLAGS_PROFILING "")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "")
endif()
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckFunctionExists)
check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H)
check_include_file(errno.h HAVE_ERRNO_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(crypt.h HAVE_CRYPT_H)
check_function_exists(truncate HAVE_TRUNCATE)
check_function_exists(localtime_r HAVE_LOCALTIME_R)
check_function_exists(dup2 HAVE_DUP2)
check_function_exists(memset HAVE_MEMSET)
check_function_exists(strncasecmp HAVE_STRNCASECMP)
check_function_exists(strnicmp HAVE_STRNICMP)
check_function_exists(strptime HAVE_STRPTIME)
check_function_exists(prctl HAVE_PRCTL)
# Verify third party header files
check_include_file_cxx("xercesc/util/XercesDefs.hpp" HAVE_XERCESC)
if(NOT ${HAVE_XERCESC})
message(FATAL_ERROR "xerces-c include headers not found")
endif()
find_program(pg_config NAMES pg_config)
if(pg_config)
execute_process(
COMMAND ${pg_config} --libdir
OUTPUT_VARIABLE POSTGRES_LIB
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${pg_config} --includedir
OUTPUT_VARIABLE POSTGRES_INCLUDE
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
link_directories("${POSTGRES_LIB}")
include_directories(${POSTGRES_INCLUDE})
list(APPEND CMAKE_REQUIRED_INCLUDES "${POSTGRES_INCLUDE}")
check_include_file("libpq-fe.h" HAVE_LIBPQ)
if(NOT HAVE_LIBPQ)
message("PostgreSQL include headers not found ${HAVE_LIBPQ}")
endif()
else()
message(FATAL_ERROR "PostgreSQL pg_config not found")
endif()
# C++ header file locations
include_directories(
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_BINARY_DIR}/include"
"${Python3_INCLUDE_DIRS}"
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/config.h"
)
# File installation
install(
FILES frepplectl.py
DESTINATION "${CMAKE_INSTALL_BINDIR}"
RENAME frepplectl
PERMISSIONS OWNER_EXECUTE OWNER_READ GROUP_EXECUTE GROUP_READ
)
install(
FILES djangosettings.py
DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/frepple"
)
install(
FILES requirements.txt
DESTINATION "${CMAKE_INSTALL_DATADIR}/frepple"
)
# Packaging of the django app: Python module in a virtual environment
# Note that we use \$ to delay the evaluation till install time
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import sys; print(sys.prefix)"
OUTPUT_VARIABLE PYTHON_PREFIX
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
install(CODE "execute_process(COMMAND mkdir -p \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple)")
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} -m venv \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv)")
install(CODE "execute_process(COMMAND \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/bin/activate)")
install(CODE "execute_process(COMMAND \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/bin/pip3 install pip install --upgrade pip wheel six appdirs setuptools)")
install(CODE "execute_process(COMMAND \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/bin/python3 -m pip install --quiet ${PROJECT_SOURCE_DIR})")
install(CODE "execute_process(COMMAND \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/bin/pip3 install -r ${CMAKE_SOURCE_DIR}/requirements.txt)")
install(CODE "execute_process(COMMAND \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/bin/python3 -m pip install --quiet ${PROJECT_SOURCE_DIR})")
install(CODE "execute_process(COMMAND rm \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/lib64)")
install(CODE "execute_process(COMMAND find \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv -type f -exec sed -i \"s|/usr/bin/env python$ |/usr/bin/env python3|g\" {} \;)")
install(CODE "execute_process(COMMAND find \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/bin -type f -name \"*ctivate*\" -exec sed -i \"s|\$ENV{DESTDIR}||g\" {} \\;)")
install(CODE "execute_process(COMMAND find \$ENV{DESTDIR}/${CMAKE_INSTALL_DATADIR}/frepple/venv/bin -type f -executable -exec sed -i \"s|\$ENV{DESTDIR}||g\" {} \\;)")
# Packaging of the static files
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E env FREPPLE_STATIC=\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/frepple/static ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/frepplectl.py collectstatic --noinput --clear --ignore '*.less' --verbosity=0)")
# Generic packaging
set(CPACK_PACKAGE_VENDOR "frePPLe")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "FrePPLe is an open source production planning and scheduling application.")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_FILE_NAME "${DISTRO}-${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES
"__pycache__"
"^${PROJECT_SOURCE_DIR}/\\\\.git"
"^${PROJECT_SOURCE_DIR}/\\\\.vs"
"^${PROJECT_SOURCE_DIR}/\\\\.settings"
"^${PROJECT_SOURCE_DIR}/logs/"
"^${PROJECT_SOURCE_DIR}/build.*"
"^${PROJECT_SOURCE_DIR}/venv/.*"
"^${PROJECT_SOURCE_DIR}/static$"
"^${PROJECT_SOURCE_DIR}/localsettings.*py$"
"^${PROJECT_SOURCE_DIR}/node_modules"
"^${PROJECT_SOURCE_DIR}/bin/.*\\\\.exe$"
"^${PROJECT_SOURCE_DIR}/bin/frepple$"
"^${PROJECT_SOURCE_DIR}/bin/frepple.dll$"
"^${PROJECT_SOURCE_DIR}/bin/libfrepple.*"
"^${PROJECT_SOURCE_DIR}/bin/.*\\\\.pdb$"
)
# Add folders
add_subdirectory(bin)
add_subdirectory(src)
add_subdirectory(doc)
add_subdirectory(contrib/docker)
add_subdirectory(contrib/linux)
# Test suite
enable_testing()
add_test(NAME engine
COMMAND ${Python3_VENV} ${CMAKE_CURRENT_SOURCE_DIR}/test/runtest.py ${TESTARGS}
)
# Debugging targets
find_program(valgrind NAMES valgrind)
if(valgrind)
add_custom_target(
callgrind
DEPENDS venv
COMMAND ${CMAKE_COMMAND} -E env
FREPPLE_HOME=${CMAKE_SOURCE_DIR}/bin
PYTHONPATH=${CMAKE_SOURCE_DIR}
DJANGO_SETTINGS_MODULE=freppledb.settings
FREPPLE_LOGFILE=frepple.log
LD_BIND_NOW=1
fcst=1
invplan=1
supply=1
nowebservice=1
constraint=13
plantype=1
valgrind --tool=callgrind
${CMAKE_SOURCE_DIR}/bin/frepple
${CMAKE_SOURCE_DIR}/freppledb/common/commands.py
COMMAND callgrind_annotate --show-percs=yes > callgrind.relative.out
COMMAND callgrind_annotate --show-percs=yes --inclusive=yes > callgrind.cumulative.out
COMMAND callgrind_annotate --show-percs=yes --inclusive=yes --tree=calling > callgrind.cumulative_with_calling.out
COMMAND callgrind_annotate --show-percs=yes --inclusive=yes --tree=caller > callgrind.cumulative_with_caller.out
# Useful callgrind commands during a profiling run:
# - callgrind_control: Return process id of the current callgrind rung
# - callgrind_control -i off <pid>: Switch off the collection of metrics
# - callgrind_control -i on <pid>: Switch on the collection of metrics
# - callgrind_control -z <pid>: Clear out all metrics collected so far
)
add_custom_target(
memcheck
DEPENDS venv
COMMAND ${CMAKE_COMMAND} -E
env
FREPPLE_HOME=${CMAKE_SOURCE_DIR}/bin
PYTHONPATH=${CMAKE_SOURCE_DIR}
DJANGO_SETTINGS_MODULE=freppledb.settings
FREPPLE_LOGFILE=frepple.log
LD_BIND_NOW=1
invplan=1
supply=1
nowebservice=1
constraint=13
plantype=1
PYTHONMALLOC=malloc
valgrind --tool=memcheck -v
${CMAKE_SOURCE_DIR}/bin/frepple
${CMAKE_SOURCE_DIR}/freppledb/common/commands.py
)
add_custom_target(
massif
DEPENDS venv
COMMAND ${CMAKE_COMMAND} -E
env
FREPPLE_HOME=${CMAKE_SOURCE_DIR}/bin
PYTHONPATH=${CMAKE_SOURCE_DIR}
DJANGO_SETTINGS_MODULE=freppledb.settings
FREPPLE_LOGFILE=frepple.log
LD_BIND_NOW=1
invplan=1
supply=1
nowebservice=1
constraint=13
plantype=1
PYTHONMALLOC=malloc
valgrind --tool=massif
${CMAKE_SOURCE_DIR}/bin/frepple
${CMAKE_SOURCE_DIR}/freppledb/common/commands.py
COMMAND ls -t massif.out.* | head -1 | xargs ms_print > memory_allocations.log
)
endif()
find_program(gdb NAMES gdb)
if(gdb)
add_custom_target(gdb ${CMAKE_COMMAND} -E
env
FREPPLE_HOME=${CMAKE_SOURCE_DIR}/bin
PYTHONPATH=${CMAKE_SOURCE_DIR}
DJANGO_SETTINGS_MODULE=freppledb.settings
FREPPLE_LOGFILE=frepple.log
supply=1
constraint=13
plantype=1
gdb -ex=r --args ${CMAKE_SOURCE_DIR}/bin/frepple ${CMAKE_SOURCE_DIR}/freppledb/common/commands.py
)
endif()
# Translations process:
# 1) Run "cmake --build . --target translations_extract" to get all translatable strings from the source code.
# 2) Translate all strings local/<LANGUAGE>/<LANGUAGE>.po file. The real work!
# 3) Run "make --build . --target compile-translations" to merge the translations into the right places.
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_custom_target(translations_extract
COMMAND ${CMAKE_SOURCE_DIR}/translations.sh extract
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(translations_compile
COMMAND ${CMAKE_SOURCE_DIR}/translations.sh compile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()