author | alfadur |
Sat, 08 Apr 2023 01:23:47 +0300 | |
changeset 15946 | 69479ac8f4c8 |
parent 15555 | 107170c05bac |
child 15962 | 4013354585be |
permissions | -rw-r--r-- |
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
1 |
#the usual set of dependencies |
8041 | 2 |
find_package(OpenGL REQUIRED) |
15555
107170c05bac
Add patch to correctly handle libsdl2 from system/cmake
LocutusOfBorg
parents:
15362
diff
changeset
|
3 |
find_package(SDL2 REQUIRED CONFIG) |
12386 | 4 |
find_package(SDL2_mixer 2 REQUIRED) |
5 |
find_package(SDL2_net 2 REQUIRED) |
|
6 |
find_package(SDL2_image 2 REQUIRED) |
|
7 |
find_package(SDL2_ttf 2 REQUIRED) |
|
8004 | 8 |
|
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
9 |
#compile our rtl implementation |
8448
14f736ca7eb3
update FindGLEW to use the same variables as in later CMake files and make sure to include its headers before compiling c stuff
koda
parents:
8332
diff
changeset
|
10 |
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rtl) |
9264 | 11 |
include_directories(${PHYSFS_INCLUDE_DIR}) |
12 |
include_directories(${PHYSLAYER_INCLUDE_DIR}) |
|
10127 | 13 |
include_directories(${LUA_INCLUDE_DIR}) |
12386 | 14 |
include_directories(${SDL2_INCLUDE_DIRS}) |
8047
25a4daa6473c
cleanup headers, remove -I . from rtl lib to save a few warnings
koda
parents:
8044
diff
changeset
|
15 |
add_subdirectory(rtl) |
7999 | 16 |
|
10747
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
17 |
# convert list into pascal array |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
18 |
if(FONTS_DIRS) |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
19 |
list(LENGTH FONTS_DIRS ndirs) |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
20 |
set(FONTS_DIRS_ARRAY "array [0..${ndirs}] of PChar = (") |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
21 |
foreach(fontdir ${FONTS_DIRS}) |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
22 |
set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\n_P'${fontdir}',") |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
23 |
endforeach(fontdir) |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
24 |
set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\nnil);\n") |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
25 |
else(FONTS_DIRS) |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
26 |
set(FONTS_DIRS_ARRAY "array [0..1] of PChar = (nil, nil);") |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
27 |
endif(FONTS_DIRS) |
07ade56c3b4a
backporting some build system fixes and pas2c tweaks
sheepluva
parents:
10131
diff
changeset
|
28 |
|
8044 | 29 |
configure_file(${CMAKE_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc) |
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
30 |
|
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
31 |
#get the list of pas files that are going to be converted and compiled |
8044 | 32 |
file(GLOB engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/*.pas") |
33 |
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uTouch.pas") |
|
34 |
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/PNGh.pas") |
|
35 |
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cSystem.pas") |
|
36 |
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas") |
|
37 |
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/hwLibrary.pas") |
|
14476 | 38 |
if(NOVIDEOREC) |
39 |
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uVideoRec.pas") |
|
40 |
endif() |
|
11794 | 41 |
if(NOT GL2) |
42 |
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uMatrix.pas") |
|
43 |
endif() |
|
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
44 |
|
9259
872dd30deb7b
compile hwengine first, so that all other files are compiled too and don't call pas2c again
koda
parents:
9256
diff
changeset
|
45 |
#remove and readd hwengine so that it is compiled first, compiling every other file in the process |
872dd30deb7b
compile hwengine first, so that all other files are compiled too and don't call pas2c again
koda
parents:
9256
diff
changeset
|
46 |
list(REMOVE_ITEM engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas) |
872dd30deb7b
compile hwengine first, so that all other files are compiled too and don't call pas2c again
koda
parents:
9256
diff
changeset
|
47 |
list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas) |
872dd30deb7b
compile hwengine first, so that all other files are compiled too and don't call pas2c again
koda
parents:
9256
diff
changeset
|
48 |
|
872dd30deb7b
compile hwengine first, so that all other files are compiled too and don't call pas2c again
koda
parents:
9256
diff
changeset
|
49 |
#process files .pas -> .c |
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
50 |
foreach(sourcefile ${engine_sources_pas}) |
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
51 |
get_filename_component(sourcename ${sourcefile} NAME_WE) #drops .pas |
9256
5a2e94a4c2d0
set one rule per file, only compiles a minimum number of files when one pascal file is modified
koda
parents:
9252
diff
changeset
|
52 |
list(APPEND engine_sources "${CMAKE_CURRENT_BINARY_DIR}/${sourcename}.c") |
9978 | 53 |
endforeach() |
9256
5a2e94a4c2d0
set one rule per file, only compiles a minimum number of files when one pascal file is modified
koda
parents:
9252
diff
changeset
|
54 |
|
9978 | 55 |
#add again files for external functions and for fpcrtl_ functions |
56 |
list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/pas2cSystem.pas) |
|
57 |
list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas) |
|
9976 | 58 |
|
59 |
||
11661 | 60 |
set(pas2c_args -n hwengine |
61 |
-i ${CMAKE_SOURCE_DIR}/hedgewars |
|
62 |
-o ${CMAKE_CURRENT_BINARY_DIR} |
|
63 |
-a ${CMAKE_CURRENT_BINARY_DIR} |
|
64 |
-d ENDIAN_LITTLE |
|
65 |
-d DEBUGFILE) |
|
66 |
if(BUILD_ENGINE_JS) |
|
11791 | 67 |
set(pas2c_args ${pas2c_args} -d WEBGL) |
68 |
endif() |
|
69 |
if(BUILD_ENGINE_LIBRARY) |
|
70 |
set(pas2c_args ${pas2c_args} -d HWLIBRARY) |
|
71 |
endif() |
|
72 |
if(GL2) |
|
73 |
set(pas2c_args ${pas2c_args} -d GL2) |
|
11661 | 74 |
endif() |
15362
c8f37fc9c266
Add DARWIN flag to fix BUILD_ENGINE_C compilation on macOS
raptor <buckyballreaction@gmail.com>
parents:
15361
diff
changeset
|
75 |
if(APPLE) |
c8f37fc9c266
Add DARWIN flag to fix BUILD_ENGINE_C compilation on macOS
raptor <buckyballreaction@gmail.com>
parents:
15361
diff
changeset
|
76 |
set(pas2c_args ${pas2c_args} -d DARWIN) |
c8f37fc9c266
Add DARWIN flag to fix BUILD_ENGINE_C compilation on macOS
raptor <buckyballreaction@gmail.com>
parents:
15361
diff
changeset
|
77 |
endif() |
11661 | 78 |
|
14461
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
12386
diff
changeset
|
79 |
if(LIBAV_FOUND) |
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
12386
diff
changeset
|
80 |
add_subdirectory(${CMAKE_SOURCE_DIR}/hedgewars/avwrapper ${CMAKE_CURRENT_BINARY_DIR}/avwrapper) |
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
12386
diff
changeset
|
81 |
list(APPEND HW_LINK_LIBS avwrapper) |
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
12386
diff
changeset
|
82 |
set(pas2c_args ${pas2c_args} -d USE_VIDEO_RECORDING) |
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
12386
diff
changeset
|
83 |
endif() |
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
12386
diff
changeset
|
84 |
|
9978 | 85 |
#invoke pas2c on main module, it will call all the others |
86 |
add_custom_command(OUTPUT ${engine_sources} |
|
87 |
COMMAND "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}" |
|
11661 | 88 |
ARGS ${pas2c_args} |
9978 | 89 |
DEPENDS pas2c #converter tool |
90 |
${engine_sources_pas} #original pascal file |
|
91 |
) |
|
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
92 |
|
9256
5a2e94a4c2d0
set one rule per file, only compiles a minimum number of files when one pascal file is modified
koda
parents:
9252
diff
changeset
|
93 |
#wrap conversion for all source in this command |
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
94 |
add_custom_target(engine_c DEPENDS ${engine_sources}) |
7999 | 95 |
|
8006 | 96 |
|
11679 | 97 |
if(BUILD_ENGINE_JS) |
11796
50a462b9454a
Add pre/post js stub files and expand the emscripten options
frd
parents:
11794
diff
changeset
|
98 |
add_flag_append(CMAKE_C_FLAGS "--memory-init-file 0 -O0 --js-opts 0 -g4 --use-preload-plugins -s ASSERTIONS=2 -s USE_SDL=2 -s USE_SDL_IMAGE=1 -s USE_LIBPNG=1 -s USE_SDL_TTF=2 -s USE_VORBIS=1 -s USE_OGG=1 -s TOTAL_MEMORY=100000000 -s GL_UNSAFE_OPTS=0 -s EXPORTED_FUNCTIONS=\"['_hwengine_RunEngine', '_hwengine_MainLoop']\" --post-js ${CMAKE_SOURCE_DIR}/project_files/web/post.js --pre-js ${CMAKE_SOURCE_DIR}/project_files/web/pre.js") |
11679 | 99 |
endif() |
100 |
||
8035
68ec3138c16d
comments and runtime list of files to convert and compile
koda
parents:
8029
diff
changeset
|
101 |
#compile the c files |
10127 | 102 |
add_definitions(-DPAS2C) |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10129
diff
changeset
|
103 |
add_definitions(-Werror=incompatible-pointer-types) |
10127 | 104 |
|
11659
71bdf987e41f
Fully support emscripten toolchain in our build system
koda
parents:
11654
diff
changeset
|
105 |
add_executable(hwengine WIN32 ${engine_sources}) |
71bdf987e41f
Fully support emscripten toolchain in our build system
koda
parents:
11654
diff
changeset
|
106 |
|
11654 | 107 |
if(BUILD_ENGINE_JS) |
11659
71bdf987e41f
Fully support emscripten toolchain in our build system
koda
parents:
11654
diff
changeset
|
108 |
set_target_properties(hwengine PROPERTIES SUFFIX ".html") |
11654 | 109 |
endif() |
110 |
||
8029 | 111 |
target_link_libraries(hwengine fpcrtl |
112 |
${LUA_LIBRARY} |
|
113 |
${OPENGL_LIBRARY} |
|
15555
107170c05bac
Add patch to correctly handle libsdl2 from system/cmake
LocutusOfBorg
parents:
15362
diff
changeset
|
114 |
${SDL2_LIBRARIES} |
12386 | 115 |
${SDL2_MIXER_LIBRARIES} |
116 |
${SDL2_NET_LIBRARIES} |
|
117 |
${SDL2_IMAGE_LIBRARIES} |
|
118 |
${SDL2_TTF_LIBRARIES} |
|
8853
ef59a44a9f08
and now engine in c links too (with more manual intervention as of issue 596)
koda
parents:
8448
diff
changeset
|
119 |
physfs |
ef59a44a9f08
and now engine in c links too (with more manual intervention as of issue 596)
koda
parents:
8448
diff
changeset
|
120 |
physlayer |
9984
84835d0ceb64
Fixed build failure to a missing math library linked with BUILD_ENGINE_C=1 and clang
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9982
diff
changeset
|
121 |
m |
14461
9844450389a4
Attempt to allow building video recording in pas2c mode, currently fails parsing
unc0rr
parents:
12386
diff
changeset
|
122 |
${HW_LINK_LIBS} |
8038 | 123 |
#TODO: add other libraries |
8029 | 124 |
) |
8332
9333216f2054
fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents:
8108
diff
changeset
|
125 |
install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_binary_install_dir}) |
8038 | 126 |