project_files/hwc/CMakeLists.txt
branchsdl2transition
changeset 11342 ed5a6478e710
parent 11157 73036e057d32
child 11359 c481d087f653
equal deleted inserted replaced
11340:31570b766315 11342:ed5a6478e710
       
     1 #the usual set of dependencies
       
     2 find_package(OpenGL REQUIRED)
       
     3 find_package(GLEW REQUIRED)
       
     4 find_package(SDL REQUIRED)
       
     5 find_package(SDL_mixer REQUIRED)
       
     6 find_package(SDL_net REQUIRED)
       
     7 find_package(SDL_image REQUIRED)
       
     8 find_package(SDL_ttf REQUIRED)
       
     9 
       
    10 #compile our rtl implementation
       
    11 include_directories(${GLEW_INCLUDE_DIR})
       
    12 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rtl)
       
    13 include_directories(${PHYSFS_INCLUDE_DIR})
       
    14 include_directories(${PHYSLAYER_INCLUDE_DIR})
       
    15 include_directories(${LUA_INCLUDE_DIR})
       
    16 include_directories(${SDL_INCLUDE_DIR})
       
    17 add_subdirectory(rtl)
       
    18 
       
    19 # convert list into pascal array
       
    20 if(FONTS_DIRS)
       
    21   list(LENGTH FONTS_DIRS ndirs)
       
    22   set(FONTS_DIRS_ARRAY "array [0..${ndirs}] of PChar = (")
       
    23   foreach(fontdir ${FONTS_DIRS})
       
    24       set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\n_P'${fontdir}',")
       
    25   endforeach(fontdir)
       
    26   set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\nnil);\n")
       
    27 else(FONTS_DIRS)
       
    28   set(FONTS_DIRS_ARRAY "array [0..1] of PChar = (nil, nil);")
       
    29 endif(FONTS_DIRS)
       
    30 
       
    31 configure_file(${CMAKE_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
       
    32 
       
    33 #get the list of pas files that are going to be converted and compiled
       
    34 file(GLOB engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/*.pas")
       
    35 #TODO: temporary until cmake can configure itself accordingly
       
    36 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uWeb.pas")
       
    37 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uVideoRec.pas")
       
    38 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uTouch.pas")
       
    39 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/PNGh.pas")
       
    40 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cSystem.pas")
       
    41 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas")
       
    42 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/hwLibrary.pas")
       
    43 list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uMatrix.pas")
       
    44 
       
    45 #remove and readd hwengine so that it is compiled first, compiling every other file in the process
       
    46 list(REMOVE_ITEM engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas)
       
    47 list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas)
       
    48 
       
    49 #process files .pas -> .c
       
    50 foreach(sourcefile ${engine_sources_pas})
       
    51     get_filename_component(sourcename ${sourcefile} NAME_WE) #drops .pas
       
    52     list(APPEND engine_sources "${CMAKE_CURRENT_BINARY_DIR}/${sourcename}.c")
       
    53 endforeach()
       
    54 
       
    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)
       
    58 
       
    59 
       
    60 #invoke pas2c on main module, it will call all the others
       
    61 add_custom_command(OUTPUT ${engine_sources}
       
    62                    COMMAND "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}"
       
    63                    ARGS -n "hwengine"
       
    64                         -i "${CMAKE_SOURCE_DIR}/hedgewars"
       
    65                         -o "${CMAKE_CURRENT_BINARY_DIR}"
       
    66                         -a "${CMAKE_CURRENT_BINARY_DIR}"
       
    67                         -d "ENDIAN_LITTLE"
       
    68                         -d "DEBUGFILE"
       
    69                    DEPENDS pas2c                     #converter tool
       
    70                            ${engine_sources_pas}     #original pascal file
       
    71                   )
       
    72 
       
    73 #wrap conversion for all source in this command
       
    74 add_custom_target(engine_c DEPENDS ${engine_sources})
       
    75 
       
    76 
       
    77 #compile the c files
       
    78 add_definitions(-DPAS2C)
       
    79 add_definitions(-Werror=incompatible-pointer-types)
       
    80 
       
    81 add_executable(hwengine WIN32 ${engine_sources})
       
    82 
       
    83 target_link_libraries(hwengine  fpcrtl
       
    84                                 ${LUA_LIBRARY}
       
    85                                 ${OPENGL_LIBRARY}
       
    86                                 ${SDL_LIBRARY}
       
    87                                 ${SDLMIXER_LIBRARY}
       
    88                                 ${SDLNET_LIBRARY}
       
    89                                 ${SDLIMAGE_LIBRARY}
       
    90                                 ${SDLTTF_LIBRARY}
       
    91                                 ${GLEW_LIBRARY}
       
    92                                 physfs
       
    93                                 physlayer
       
    94                                 m
       
    95                                 #TODO: add other libraries
       
    96                             )
       
    97 if(APPLE)
       
    98     target_link_libraries(hwengine IOKit SDLmain)
       
    99 endif()
       
   100 
       
   101 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_binary_install_dir})
       
   102