forked from pguyot/Einstein
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
541 lines (462 loc) · 15.3 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# ==============================
# File: TFLSettings
# Project: Einstein
#
# Copyright 2003-2022 by Paul Guyot ([email protected]) and others.
# ==============================
cmake_minimum_required(VERSION 3.13)
project( "Einstein" VERSION "2022.5.0" )
# ---- Configuration for all targets on all platforms
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CMAKE_CXX_EXTENSIONS OFF )
# ---- Include some additional functionality
include( CheckSymbolExists )
include( CheckFunctionExists )
include( CheckIncludeFile )
include( FetchContent )
# ---- Setup Google Testing
FetchContent_Declare (
googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set( gtest_force_shared_crt ON CACHE BOOL "" FORCE )
# Check if population has already been performed
FetchContent_GetProperties(googletest)
if ( NOT googletest_POPULATED )
# Fetch the content using previously declared details
FetchContent_Populate(googletest)
# Bring the populated content into the build
add_subdirectory( ${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} )
endif ()
enable_testing()
include( GoogleTest )
# ---- Configuration per platform
if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
# TODO: enable this for release builds
#set( CMAKE_OSX_ARCHITECTURES arm64;x86_64 )
# TODO: set this for FLTK and NEWT64 as well
#set( CMAKE_OSX_DEPLOYMENT_TARGET 10.9 ) # Can't go any lower.
# TODO: Fix this for release builds
set( CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO" )
set( CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" )
elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
# Linux: nothing to do here
elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
# allow to build with multithreading libraries with VisualC
cmake_policy( SET CMP0091 NEW )
set( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
else ()
# Warn the caller that this is not supported
message( FATAL_ERROR "Einstein is not configured to build on this platform: " ${CMAKE_SYSTEM_NAME} "." )
endif ()
#
# ==== External Dependencies ===================================================
#
# ---- Newt/64 library ---------------------------------------------------------
#
if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
# Generates Newt64_FOUND, Newt64_DIR
find_package( Newt64 CONFIG HINTS ${CMAKE_CURRENT_SOURCE_DIR}/newt64/build )
endif()
find_library ( newt64_lib NAMES newt64
HINTS
${CMAKE_CURRENT_SOURCE_DIR}/newt64/build/Release
${CMAKE_CURRENT_SOURCE_DIR}/newt64/build/Debug
${CMAKE_CURRENT_SOURCE_DIR}/newt64/build
)
find_file( newt64_incl NAMES NewtCore.h PATH_SUFFIXES newt64 HINTS ${CMAKE_CURRENT_SOURCE_DIR}/newt64/src/newt_core/incs )
if ( newt64_lib MATCHES ".*NOTFOUND" OR newt64_incl MATCHES ".*NOTFOUND" )
message( WARNING "Newt64 not found!" )
set( NEWT64_FOUND false )
else ()
set( NEWT64_FOUND true )
get_filename_component( newt64_lib_path ${newt64_lib} DIRECTORY )
get_filename_component( newt64_incl_path ${newt64_incl} DIRECTORY )
message( STATUS "Newt64 found in " ${newt64_lib_path} )
endif ()
#
# ---- FLTK library ------------------------------------------------------------
#
# TODO: update this to automatically download and build in .../Einstein/fltk
set( FLTK_SKIP_OPENGL true )
find_program( LOCAL_FLTK_FLUID_EXECUTABLE fluid
HINTS
# If we are cross compiling:
# - Fluid must be compiled native, so look in "buildNative" first
# - FLTK is then built again for the target platform in "build"
${CMAKE_SOURCE_DIR}/fltk/buildNative/bin/Release
${CMAKE_SOURCE_DIR}/fltk/buildNative/bin/Debug
${CMAKE_SOURCE_DIR}/fltk/buildNative/bin
${CMAKE_SOURCE_DIR}/fltk/build/bin/Release
${CMAKE_SOURCE_DIR}/fltk/build/bin/Debug
${CMAKE_SOURCE_DIR}/fltk/build/bin
)
find_package( FLTK REQUIRED NO_MODULE HINTS ${CMAKE_SOURCE_DIR}/fltk/build )
if ( ${LOCAL_FLTK_FLUID_EXECUTABLE} MATCHES ".*NOTFOUND" )
message( WARNING "Fluid (FLTK User Interface Designer) not found!" )
else ()
message( STATUS "Fluid (FLTK User Interface Designer) found at " ${LOCAL_FLTK_FLUID_EXECUTABLE})
endif ()
function ( build_with_fluid name dir )
add_custom_command (
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${dir}"
COMMAND ${LOCAL_FLTK_FLUID_EXECUTABLE} -c ${name}.fl
DEPENDS "${CMAKE_SOURCE_DIR}/${dir}/${name}.fl"
DEPENDS "${ARGN}"
OUTPUT "${CMAKE_SOURCE_DIR}/${dir}/${name}.cpp"
OUTPUT "${CMAKE_SOURCE_DIR}/${dir}/${name}.h"
)
set_source_files_properties (
${CMAKE_SOURCE_DIR}/${dir}/${name}.cpp
PROPERTIES GENERATED TRUE
)
set_source_files_properties (
${CMAKE_SOURCE_DIR}/${dir}/${name}.h
PROPERTIES GENERATED TRUE
)
endfunction ()
#
# ==== Configuring Einstein Build ==============================================
#
# ---- Einstein Source Files ---------------------------------------------------
#
set( cmake_sources )
set( common_sources )
set( app_sources )
set( test_sources )
# collect source code from the source code directory tree
include( app/CMakeLists.txt )
include( Emulator/CMakeLists.txt )
include( Monitor/CMakeLists.txt )
include( K/CMakeLists.txt )
if ( NEWT64_FOUND MATCHES true )
include( Toolkit/CMakeLists.txt )
endif ()
include( _Tests_/CMakeLists.txt )
if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
# additional source code
list ( APPEND app_sources
# Apple macOS required resources
Resources/macOS/Info.plist.in
Resources/macOS/Einstein.icns
Resources/macOS/Entitlements.plist
)
endif ()
#
# ---- Common IDE setup --------------------------------------------------------
#
set_property( GLOBAL PROPERTY USE_FOLDERS ON )
source_group( TREE "${CMAKE_SOURCE_DIR}" PREFIX "Sources" FILES ${cmake_sources} )
source_group( TREE "${CMAKE_SOURCE_DIR}" PREFIX "Sources" FILES ${common_sources} )
source_group( TREE "${CMAKE_SOURCE_DIR}" PREFIX "Sources" FILES ${app_sources} )
source_group( TREE "${CMAKE_SOURCE_DIR}" PREFIX "Sources" FILES ${test_sources} )
if ( WIN32 )
source_group(TREE "${CMAKE_SOURCE_DIR}" PREFIX "Sources" FILES Resources/MSWindows/Einstein.rc.in)
endif ()
#
# ---- Platform specific rules ----------------------------------------------------------
#
if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
# take care of the app icon
set( MACOSX_BUNDLE_ICON_FILE Einstein.icns )
set_source_files_properties (
Resources/macOS/${MACOSX_BUNDLE_ICON_FILE}
PROPERTIES MACOSX_PACKAGE_LOCATION "Resources"
)
# create the applications
add_executable ( Einstein MACOSX_BUNDLE
${common_sources}
${app_sources}
${cmake_sources}
)
add_executable ( EinsteinTests
${common_sources}
${test_sources}
${cmake_sources}
)
# how to compile and link
target_compile_options( Einstein PUBLIC
-Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Werror
)
target_compile_options( EinsteinTests PUBLIC
-Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Werror
)
target_compile_definitions ( Einstein PRIVATE
TARGET_UI_FLTK=1 NO_PORT_AUDIO NO_X11 TARGET_OS_OPENSTEP=1
TARGET_OS_MAC=1 NS_BLOCK_ASSERTIONS=1
)
target_compile_definitions ( EinsteinTests PRIVATE
TARGET_UI_FLTK=1 NO_PORT_AUDIO NO_X11 TARGET_OS_OPENSTEP=1
TARGET_OS_MAC=1 NS_BLOCK_ASSERTIONS=1
)
target_link_libraries ( Einstein
${system_libs}
fltk
fltk_images
fltk_png
fltk_z
pthread
"-framework AddressBook"
"-framework AudioUnit"
"-framework AppKit"
"-framework CoreAudio"
"-framework Cocoa"
)
target_link_libraries ( EinsteinTests
${system_libs}
fltk
pthread
"-framework AddressBook"
"-framework AudioUnit"
"-framework AppKit"
"-framework CoreAudio"
"-framework Cocoa"
)
set_target_properties ( Einstein PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Resources/macOS/Info.plist.in"
)
set_target_properties ( Einstein PROPERTIES
CPACK_BUNDLE_APPLE_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/Resources/macOS/EntiXXXtlements.plist"
)
if ( XCODE )
# Fix indentation settings that are cleared by CMake at every generator call.
add_custom_target ( FixTabSettings
COMMAND ${CMAKE_HOME_DIRECTORY}/cmake/xcodeFixIndentation
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Xcode can't use the same file in multiple target if there is no dependency.
add_dependencies( Einstein EinsteinTests )
endif ()
elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
# create the application
add_executable ( Einstein
${common_sources}
${app_sources}
${cmake_sources}
)
add_executable ( EinsteinTests
${common_sources}
${test_sources}
${cmake_sources}
)
# how to compile and link
target_compile_options ( Einstein PUBLIC
-Wall -Wno-multichar -Wno-misleading-indentation
-Wno-missing-field-initializers
# -Wno-unused-result -Werror
)
target_compile_options ( EinsteinTests PUBLIC
-Wall -Wno-multichar -Wno-misleading-indentation
-Wno-missing-field-initializers -Werror
)
target_compile_definitions ( Einstein PRIVATE
TARGET_UI_FLTK=1 TARGET_OS_LINUX=1
)
target_compile_definitions ( EinsteinTests PRIVATE
TARGET_UI_FLTK=1 TARGET_OS_LINUX=1
)
target_link_libraries ( Einstein
${system_libs}
fltk
fltk_images
fltk_png
fltk_z
pulse # sound
)
target_link_libraries ( EinsteinTests
${system_libs}
fltk
pthread
)
elseif ( WIN32 )
# Create a resources file for Windows
configure_file (
Resources/MSWindows/Einstein.rc.in
Einstein.rc
)
# create the binaries
add_executable ( Einstein WIN32
${common_sources} ${app_sources} ${cmake_sources} ${data}
${CMAKE_CURRENT_BINARY_DIR}/Einstein.rc
)
add_executable ( EinsteinTests
${common_sources} ${test_sources}
)
# how to compile and link
target_compile_options( Einstein PUBLIC "/bigobj" )
target_compile_options( EinsteinTests PUBLIC "/bigobj" )
if ( $<CONFIG:Debug> )
target_compile_options( Einstein PUBLIC "/ZI" )
target_compile_options( EinsteinTests PUBLIC "/ZI" )
endif ()
target_compile_definitions ( Einstein PRIVATE
TARGET_UI_FLTK=1 TARGET_OS_WIN32=1
WIN32_LEAN_AND_MEAN=1 _CRT_SECURE_NO_WARNINGS=1
)
target_compile_definitions ( EinsteinTests PRIVATE
TARGET_UI_FLTK=1 TARGET_OS_WIN32=1
WIN32_LEAN_AND_MEAN=1 _CRT_SECURE_NO_WARNINGS=1
)
target_link_libraries ( Einstein
${system_libs}
fltk
fltk_images
fltk_png
fltk_z
winmm
gdiplus
)
target_link_libraries ( EinsteinTests
${system_libs}
fltk
gdiplus
)
endif ()
# ---- Late NEWT64 Processing --------------------------------------------------
if ( NEWT64_FOUND MATCHES true )
if ( WIN32 )
target_include_directories ( Einstein SYSTEM PUBLIC
${newt64_incl_path}
${newt64_incl_path}/win
)
target_link_libraries ( Einstein shlwapi )
else ()
# On Linux/macOS, use darwin includes
target_include_directories ( Einstein SYSTEM PUBLIC
${newt64_incl_path}
${newt64_incl_path}/darwin
)
endif ()
target_link_libraries ( Einstein ${newt64_lib} )
message ( STATUS "NEWT64 library at " ${newt64_lib} )
target_compile_definitions ( Einstein PRIVATE USE_TOOLKIT=1 )
endif ()
#
# ---- Einstein Platform Independent Build Instructions ------------------------
#
target_include_directories (
Einstein PUBLIC
${CMAKE_SOURCE_DIR}
${FLTK_INCLUDE_DIRS}
)
target_include_directories (
EinsteinTests PUBLIC
${CMAKE_SOURCE_DIR}
${FLTK_INCLUDE_DIRS}
)
target_compile_definitions ( Einstein PUBLIC "$<$<CONFIG:DEBUG>:_DEBUG>" USE_CMAKE )
target_compile_definitions ( EinsteinTests PUBLIC "$<$<CONFIG:DEBUG>:_DEBUG>" USE_CMAKE )
target_link_libraries ( EinsteinTests gtest_main )
gtest_discover_tests ( EinsteinTests )
# ---- Generated Files ---------------------------------------------------------
set_source_files_properties (
/app/Version_CMake.h
PROPERTIES GENERATED TRUE
)
string ( TIMESTAMP COMPILE_TIME_YYYY "%Y" )
string ( TIMESTAMP COMPILE_TIME_MM "%m" )
string ( TIMESTAMP COMPILE_TIME_DD "%d" )
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/app/Version_CMake.h.in
${CMAKE_CURRENT_SOURCE_DIR}/app/Version_CMake.h
)
#
# ---- clang-format ------------------------
#
find_program(CLANG_FORMAT_EXECUTABLE
NAMES clang-format-13 clang-format-mp-13 clang-format
HINTS /usr/local/opt/clang-format@13/bin/ /usr/lib/llvm-13/bin/
DOC "clang-format executable")
if(CLANG_FORMAT_EXECUTABLE)
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version
OUTPUT_VARIABLE clang_format_version
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# Ubuntu clang-format version 13.0.1-++20220112083154+b9a243d1cac2-1~exp1~20220112203239.53
# clang-format version 13.0.0
if(clang_format_version MATCHES ".*clang-format version ([0-9]+).*")
string(REGEX
REPLACE ".*clang-format version ([0-9]+).*"
"\\1"
CLANG_FORMAT_VERSION
"${clang_format_version}")
list(GET clang_format_version 0 CLANG_FORMAT_VERSION_MAJOR)
endif()
endif()
if(CLANG_FORMAT_EXECUTABLE)
if (CLANG_FORMAT_VERSION GREATER 12)
set(CLANG_FORMAT_FOUND TRUE)
message(STATUS "Found clang-format at ${CLANG_FORMAT_EXECUTABLE}")
else()
message(STATUS "clang-format not usable, as version of ${CLANG_FORMAT_EXECUTABLE} doesn't match : ${CLANG_FORMAT_VERSION_MAJOR} < 13")
set(CLANG_FORMAT_FOUND FALSE)
endif()
else()
set(CLANG_FORMAT_FOUND FALSE)
message(STATUS "clang-format not found")
endif()
if(CLANG_FORMAT_FOUND)
set( format_sources )
list( APPEND format_sources ${common_sources} )
list( APPEND format_sources ${app_sources} )
list( APPEND format_sources ${tests_sources} )
list( FILTER format_sources INCLUDE REGEX "\\.(h|cpp|mm|t|m)$" )
foreach (SOURCE ${format_sources})
get_property (SOURCE_IS_GENERATED
SOURCE "${SOURCE}"
PROPERTY GENERATED)
if (NOT SOURCE_IS_GENERATED)
list (APPEND format_sources_not_generated "${SOURCE}")
endif ()
endforeach ()
add_custom_target(
clang-format-check
COMMAND ${CLANG_FORMAT_EXECUTABLE}
-n
${format_sources_not_generated}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
add_custom_target(
clang-format
COMMAND ${CLANG_FORMAT_EXECUTABLE}
-i
${format_sources_not_generated}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
#
# ==== MessagePad.org distribution system ======================================
#
# TODO: We are moving to a CI/CD system that will build distributions with
# GitHub tools.
#
# Disable code.
if ( 0 )
set ( EINSTEIN_DIST_DIR "Sites/messagepad.org/htdocs/Downloads/Einstein" )
if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
# MacOS
add_custom_target (
dist
COMMAND ${CMAKE_COMMAND} -E tar "cfv" "/Users/matt/${EINSTEIN_DIST_DIR}/MacOS/Einstein.MacOS.${CMAKE_PROJECT_VERSION}.zip" --format=zip -- "Einstein.app"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_dependencies ( dist Einstein )
elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
# Linux
add_custom_target (
dist
COMMAND ${CMAKE_COMMAND} -E tar "cfv" "/media/psf/Home/${EINSTEIN_DIST_DIR}/Linux/Einstein.Linux.${CMAKE_PROJECT_VERSION}.zip" --format=zip -- "Einstein"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_dependencies( dist Einstein )
elseif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
# MSWindows
add_custom_target (
dist
COMMAND ${CMAKE_COMMAND} -E tar "cfv" "z:/${EINSTEIN_DIST_DIR}/MSWindows/Einstein.Windows.${CMAKE_PROJECT_VERSION}.zip" --format=zip -- "Einstein.exe"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_dependencies ( dist Einstein )
endif ()
endif ()