project_files/hwc/CMakeLists.txt
author alfadur
Mon, 27 Aug 2018 22:28:56 +0300
changeset 13800 e335daaa77a9
parent 12391 e4f8bf43224d
child 14466 9844450389a4
permissions -rw-r--r--
Add hogs per team named constant that absolutely no one asked for
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8035
68ec3138c16d comments and runtime list of files to convert and compile
koda
parents: 8029
diff changeset
     1
#the usual set of dependencies
8041
ecb446b9b7d6 fix build
nemo
parents: 8038
diff changeset
     2
find_package(OpenGL REQUIRED)
8004
da4c6db6ea6b correct includes and clang detection
koda
parents: 7999
diff changeset
     3
find_package(GLEW REQUIRED)
11359
c481d087f653 cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents: 11157
diff changeset
     4
find_package(SDL2 REQUIRED)
12391
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
     5
find_package(SDL2_mixer 2 REQUIRED)
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
     6
find_package(SDL2_net 2 REQUIRED)
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
     7
find_package(SDL2_image 2 REQUIRED)
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
     8
find_package(SDL2_ttf 2 REQUIRED)
8004
da4c6db6ea6b correct includes and clang detection
koda
parents: 7999
diff changeset
     9
8035
68ec3138c16d comments and runtime list of files to convert and compile
koda
parents: 8029
diff changeset
    10
#compile our rtl implementation
9201
bcf2f7798ebb redid FindGLEW in the right way (tm)
koda
parents: 9130
diff changeset
    11
include_directories(${GLEW_INCLUDE_DIR})
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
    12
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rtl)
9264
21df1a0ec9ed engine links
unc0rr
parents: 9256
diff changeset
    13
include_directories(${PHYSFS_INCLUDE_DIR})
21df1a0ec9ed engine links
unc0rr
parents: 9256
diff changeset
    14
include_directories(${PHYSLAYER_INCLUDE_DIR})
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 9984
diff changeset
    15
include_directories(${LUA_INCLUDE_DIR})
12391
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
    16
include_directories(${SDL2_INCLUDE_DIRS})
8047
25a4daa6473c cleanup headers, remove -I . from rtl lib to save a few warnings
koda
parents: 8044
diff changeset
    17
add_subdirectory(rtl)
7999
bb503cd46516 add a few cmakefiles for c engine and rtl
koda
parents:
diff changeset
    18
10747
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    19
# convert list into pascal array
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    20
if(FONTS_DIRS)
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    21
  list(LENGTH FONTS_DIRS ndirs)
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    22
  set(FONTS_DIRS_ARRAY "array [0..${ndirs}] of PChar = (")
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    23
  foreach(fontdir ${FONTS_DIRS})
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    24
      set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\n_P'${fontdir}',")
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    25
  endforeach(fontdir)
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    26
  set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\nnil);\n")
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    27
else(FONTS_DIRS)
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    28
  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
    29
endif(FONTS_DIRS)
07ade56c3b4a backporting some build system fixes and pas2c tweaks
sheepluva
parents: 10131
diff changeset
    30
8044
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    31
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
    32
68ec3138c16d comments and runtime list of files to convert and compile
koda
parents: 8029
diff changeset
    33
#get the list of pas files that are going to be converted and compiled
8044
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    34
file(GLOB engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/*.pas")
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    35
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uVideoRec.pas")
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    36
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uTouch.pas")
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    37
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/PNGh.pas")
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    38
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cSystem.pas")
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    39
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas")
796f2653f21d some CMake cleanup
koda
parents: 8041
diff changeset
    40
list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/hwLibrary.pas")
11799
64bbe89e59d6 Compile uMatrix to c too when GL2 is requested
koda
parents: 11796
diff changeset
    41
if(NOT GL2)
64bbe89e59d6 Compile uMatrix to c too when GL2 is requested
koda
parents: 11796
diff changeset
    42
    list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uMatrix.pas")
64bbe89e59d6 Compile uMatrix to c too when GL2 is requested
koda
parents: 11796
diff changeset
    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
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    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
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    55
#add again files for external functions and for fpcrtl_ functions
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    56
list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/pas2cSystem.pas)
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    57
list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas)
9976
a9c8f3f11c71 call pas2c on hwengine only
koda
parents: 9267
diff changeset
    58
a9c8f3f11c71 call pas2c on hwengine only
koda
parents: 9267
diff changeset
    59
11666
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    60
set(pas2c_args -n hwengine
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    61
               -i ${CMAKE_SOURCE_DIR}/hedgewars
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    62
               -o ${CMAKE_CURRENT_BINARY_DIR}
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    63
               -a ${CMAKE_CURRENT_BINARY_DIR}
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    64
               -d ENDIAN_LITTLE
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    65
               -d DEBUGFILE)
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    66
if(BUILD_ENGINE_JS)
11796
3127b0fece81 Set pas2c switches more cleanly
koda
parents: 11686
diff changeset
    67
    set(pas2c_args ${pas2c_args} -d WEBGL)
3127b0fece81 Set pas2c switches more cleanly
koda
parents: 11686
diff changeset
    68
endif()
3127b0fece81 Set pas2c switches more cleanly
koda
parents: 11686
diff changeset
    69
if(BUILD_ENGINE_LIBRARY)
3127b0fece81 Set pas2c switches more cleanly
koda
parents: 11686
diff changeset
    70
    set(pas2c_args ${pas2c_args} -d HWLIBRARY)
3127b0fece81 Set pas2c switches more cleanly
koda
parents: 11686
diff changeset
    71
endif()
3127b0fece81 Set pas2c switches more cleanly
koda
parents: 11686
diff changeset
    72
if(GL2)
3127b0fece81 Set pas2c switches more cleanly
koda
parents: 11686
diff changeset
    73
    set(pas2c_args ${pas2c_args} -d GL2)
11666
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    74
endif()
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    75
9978
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    76
#invoke pas2c on main module, it will call all the others
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    77
add_custom_command(OUTPUT ${engine_sources}
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    78
                   COMMAND "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}"
11666
7d483d400f8d Correctly set WEBGL macro during pas2c conversion
koda
parents: 11664
diff changeset
    79
                   ARGS ${pas2c_args}
9978
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    80
                   DEPENDS pas2c                     #converter tool
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    81
                           ${engine_sources_pas}     #original pascal file
6199f64d3f8a cosmetics
koda
parents: 9976
diff changeset
    82
                  )
8035
68ec3138c16d comments and runtime list of files to convert and compile
koda
parents: 8029
diff changeset
    83
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
    84
#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
    85
add_custom_target(engine_c DEPENDS ${engine_sources})
7999
bb503cd46516 add a few cmakefiles for c engine and rtl
koda
parents:
diff changeset
    86
8006
7ca007615b88 no globs, sources not yet generated
koda
parents: 8004
diff changeset
    87
11684
8f5db41471f4 Add a necessary flag to emscripten
frd
parents: 11666
diff changeset
    88
if(BUILD_ENGINE_JS)
11801
50a462b9454a Add pre/post js stub files and expand the emscripten options
frd
parents: 11799
diff changeset
    89
    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")
11684
8f5db41471f4 Add a necessary flag to emscripten
frd
parents: 11666
diff changeset
    90
endif()
8f5db41471f4 Add a necessary flag to emscripten
frd
parents: 11666
diff changeset
    91
8035
68ec3138c16d comments and runtime list of files to convert and compile
koda
parents: 8029
diff changeset
    92
#compile the c files
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 9984
diff changeset
    93
add_definitions(-DPAS2C)
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10129
diff changeset
    94
add_definitions(-Werror=incompatible-pointer-types)
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 9984
diff changeset
    95
11664
71bdf987e41f Fully support emscripten toolchain in our build system
koda
parents: 11659
diff changeset
    96
add_executable(hwengine WIN32 ${engine_sources})
71bdf987e41f Fully support emscripten toolchain in our build system
koda
parents: 11659
diff changeset
    97
11659
870f22de388b Add support for compiling C engine with emscripten
koda
parents: 11405
diff changeset
    98
if(BUILD_ENGINE_JS)
11664
71bdf987e41f Fully support emscripten toolchain in our build system
koda
parents: 11659
diff changeset
    99
    set_target_properties(hwengine PROPERTIES SUFFIX ".html")
11659
870f22de388b Add support for compiling C engine with emscripten
koda
parents: 11405
diff changeset
   100
endif()
870f22de388b Add support for compiling C engine with emscripten
koda
parents: 11405
diff changeset
   101
8029
7ba43d7e54e7 cmake linking for engine in c
koda
parents: 8023
diff changeset
   102
target_link_libraries(hwengine  fpcrtl
7ba43d7e54e7 cmake linking for engine in c
koda
parents: 8023
diff changeset
   103
                                ${LUA_LIBRARY}
7ba43d7e54e7 cmake linking for engine in c
koda
parents: 8023
diff changeset
   104
                                ${OPENGL_LIBRARY}
11359
c481d087f653 cmake tweaks. make pas2c build with sdl2 (keycodes or something still missing)
sheepluva
parents: 11157
diff changeset
   105
                                ${SDL2_LIBRARY}
12391
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
   106
                                ${SDL2_MIXER_LIBRARIES}
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
   107
                                ${SDL2_NET_LIBRARIES}
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
   108
                                ${SDL2_IMAGE_LIBRARIES}
e4f8bf43224d fix build. sorry 'bout that.
sheepluva
parents: 11801
diff changeset
   109
                                ${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
   110
                                ${GLEW_LIBRARY}
ef59a44a9f08 and now engine in c links too (with more manual intervention as of issue 596)
koda
parents: 8448
diff changeset
   111
                                physfs
ef59a44a9f08 and now engine in c links too (with more manual intervention as of issue 596)
koda
parents: 8448
diff changeset
   112
                                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
   113
                                m
8038
625b628d55f3 and install it too
koda
parents: 8035
diff changeset
   114
                                #TODO: add other libraries
8029
7ba43d7e54e7 cmake linking for engine in c
koda
parents: 8023
diff changeset
   115
                            )
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8108
diff changeset
   116
install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_binary_install_dir})
8038
625b628d55f3 and install it too
koda
parents: 8035
diff changeset
   117