hedgewars/CMakeLists.txt
branchwebgl
changeset 9236 ddd675825672
parent 9160 fc46e75f6b72
parent 9230 035cc97de6aa
child 9244 bb95e351270c
equal deleted inserted replaced
9201:bcf2f7798ebb 9236:ddd675825672
     3 find_package(SDL_net)
     3 find_package(SDL_net)
     4 find_package(SDL_ttf)
     4 find_package(SDL_ttf)
     5 find_package(SDL_mixer)
     5 find_package(SDL_mixer)
     6 
     6 
     7 include (CheckLibraryExists)
     7 include (CheckLibraryExists)
     8 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
     8 
     9 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
     9 
    10 if(HAVE_MIXINIT)
    10 enable_language(Pascal)
    11     list(APPEND pascal_flags "-dSDL_MIXER_NEWER")
       
    12 endif()
       
    13 #IMG_Init/IMG_Quit from SDL_image 1.2.8
       
    14 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
       
    15 if(HAVE_IMGINIT)
       
    16     list(APPEND pascal_flags "-dSDL_IMAGE_NEWER")
       
    17 endif()
       
    18 
       
    19 
       
    20 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    11 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    21 
    12 include_directories(${CMAKE_CURRENT_BINARY_DIR})
    22 #SOURCE AND PROGRAMS SECTION
    13 
    23 if(${LIBENGINE})
       
    24     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
       
    25     set(hwengine_project hwLibrary.pas)
       
    26 else()
       
    27     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
       
    28     set(hwengine_project hwengine.pas)
       
    29 endif()
       
    30 
       
    31 if (APPLE)
       
    32     set(required_fpc_version 2.6)
       
    33 else()
       
    34     set(required_fpc_version 2.2)
       
    35 endif()
       
    36 
    14 
    37 set(engine_sources
    15 set(engine_sources
    38     ${hwengine_project}
    16     SDLh.pas
       
    17     uSinTable.pas
       
    18     uFloat.pas
       
    19     uConsts.pas
    39     LuaPas.pas
    20     LuaPas.pas
    40     PNGh.pas
    21     PNGh.pas
    41     SDLh.pas
    22     uTypes.pas
       
    23     uUtils.pas
       
    24     uVariables.pas
       
    25     uMisc.pas
       
    26     uConsole.pas
       
    27     uDebug.pas
       
    28     uCommands.pas
       
    29     uInputHandler.pas
       
    30     uTextures.pas
       
    31     uRenderUtils.pas
       
    32     uRender.pas
       
    33     uCaptions.pas
       
    34     uLandTexture.pas
       
    35     uIO.pas
       
    36     uChat.pas
       
    37     uPhysFSLayer.pas
       
    38     uStore.pas
       
    39     uSound.pas
       
    40     uRandom.pas
       
    41     uLocale.pas
       
    42     uStats.pas
       
    43     uCursor.pas
       
    44     uVideoRec.pas
       
    45     uAILandMarks.pas
       
    46     adler32.pas
       
    47     uLandTemplates.pas
       
    48     uLandGraphics.pas
       
    49     uLandPainted.pas
       
    50     uLandOutline.pas
       
    51     uLandGenMaze.pas
       
    52     uLandObjects.pas
       
    53     uLand.pas
       
    54     uAmmos.pas
       
    55 
       
    56     uAIMisc.pas
       
    57     uAIActions.pas
    42     uAI.pas
    58     uAI.pas
    43     uAIActions.pas
    59     uWorld.pas
    44     uAILandMarks.pas
    60     uVisualGears.pas
       
    61     uTeams.pas
       
    62 
       
    63     uGearsList.pas
       
    64     uCollisions.pas
    45     uAIAmmoTests.pas
    65     uAIAmmoTests.pas
    46     uAIMisc.pas
    66     uGears.pas
    47     uAmmos.pas
    67     uGame.pas
    48     uCaptions.pas
       
    49     uChat.pas
       
    50     uCollisions.pas
       
    51     uCommands.pas
       
    52     uCommandHandlers.pas
    68     uCommandHandlers.pas
    53     uConsole.pas
       
    54     uConsts.pas
       
    55     uCursor.pas
       
    56     uDebug.pas
       
    57     uFloat.pas
       
    58     uGame.pas
       
    59     uGears.pas
       
    60     uGearsHandlers.pas
    69     uGearsHandlers.pas
    61     uGearsHandlersRope.pas
    70     uGearsHandlersRope.pas
    62     uGearsHedgehog.pas
    71     uGearsHedgehog.pas
    63     uGearsList.pas
       
    64     uGearsRender.pas
    72     uGearsRender.pas
    65     uGearsUtils.pas
    73     uGearsUtils.pas
    66     uIO.pas
       
    67     uInputHandler.pas
       
    68     uLand.pas
       
    69     uLandGenMaze.pas
       
    70     uLandGraphics.pas
       
    71     uLandObjects.pas
       
    72     uLandOutline.pas
       
    73     uLandPainted.pas
       
    74     uLandTemplates.pas
       
    75     uLandTexture.pas
       
    76     uLocale.pas
       
    77     uMatrix.pas
       
    78     uMisc.pas
       
    79     uPhysFSLayer.pas
       
    80     uRandom.pas
       
    81     uRender.pas
       
    82     uRenderUtils.pas
       
    83     uScript.pas
    74     uScript.pas
    84     uSinTable.pas
    75     hwengine.pas
    85     uSound.pas
    76 
    86     uStats.pas
       
    87     uStore.pas
       
    88     uTeams.pas
       
    89     uTextures.pas
       
    90     uTouch.pas
       
    91     uTypes.pas
       
    92     uUtils.pas
       
    93     uVariables.pas
       
    94     uVideoRec.pas
       
    95     uVisualGears.pas
       
    96     uWorld.pas
       
    97     GSHandlers.inc
    77     GSHandlers.inc
    98     VGSHandlers.inc
    78     VGSHandlers.inc
    99     ArgParsers.inc
    79     ArgParsers.inc
   100     options.inc
    80     options.inc
   101     adler32.pas
       
   102     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
    81     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
   103     )
    82     )
   104 
       
   105 if(${LIBENGINE})
       
   106     message("*** Engine will be built as library (experimental) ***")
       
   107     list(APPEND pascal_flags "-dHWLIBRARY")
       
   108 
       
   109     # create position independent code, only required for x68_64 builds, similar to -fPIC
       
   110     if(CMAKE_SIZEOF_VOID_P MATCHES "8")
       
   111         list(APPEND pascal_flags "-Cg")
       
   112     endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
       
   113 
       
   114     # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
       
   115     if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
       
   116         list(APPEND pascal_flags "-k-no_order_inits")
       
   117     endif()
       
   118     set(destination_dir ${target_library_install_dir})
       
   119 else(${LIBENGINE})
       
   120     set(destination_dir ${target_binary_install_dir})
       
   121 endif(${LIBENGINE})
       
   122 
    83 
   123 
    84 
   124 include(${CMAKE_MODULE_PATH}/utils.cmake)
    85 include(${CMAKE_MODULE_PATH}/utils.cmake)
   125 #opengl 2
    86 #opengl 2
   126 IF(${GL2})
    87 IF(${GL2})
   127     set(pascal_flags "-dGL2" ${pascal_flags})
    88     set(pascal_flags "-dGL2" ${pascal_flags})
   128     message(STATUS "Building using OpenGL 2")
    89     message(STATUS "Building using OpenGL 2")
   129 ENDIF(${GL2})
    90 ENDIF(${GL2})
   130 
    91 
   131 find_package_or_fail(FreePascal)
    92 if (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.2 OR # older versions are just ancient
   132 
    93     (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.6 AND APPLE)) # because of 64bit and opengl bindings
   133 #when cmake-2.6 support is dropped, this ought to be inside FindFreePascal.cmake
    94     message(FATAL_ERROR "Your FreePascal installation is too old (fpc ${CMAKE_Pascal_COMPILER_VERSION})!")
   134 if (FREEPASCAL_VERSION VERSION_LESS required_fpc_version)
    95 elseif(CMAKE_Pascal_COMPILER_VERSION VERSION_GREATER 2.4)
   135     message(FATAL_ERROR "Freepascal ${FREEPASCAL_VERSION} is too old, minimum version required is ${required_fpc_version}")
    96     #enable INLINE only with a recent version of fpc
       
    97     add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si)
   136 endif()
    98 endif()
   137 
    99 
   138 
   100 
   139 #DEPENDECIES AND EXECUTABLES SECTION
   101 #DEPENDECIES AND EXECUTABLES SECTION
   140 if(APPLE)
   102 if(APPLE)
   141     string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   103     if(CMAKE_OSX_ARCHITECTURES)
   142     string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   104         #parse this system variable and adjust only the powerpc syntax to be compatible with -P
   143     string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   105         string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   144 
   106         string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   145     if(powerpc_build)
   107         string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   146         set(powerpc_build "powerpc")
   108         if(x86_64_build)
       
   109             add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
       
   110         elseif(i386_build)
       
   111             add_flag_prepend(CMAKE_Pascal_FLAGS -Pi386)
       
   112         elseif(powerpc_build)
       
   113             add_flag_prepend(CMAKE_Pascal_FLAGS -Ppowerpc)
       
   114         else()
       
   115             message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})")
       
   116         endif()
       
   117         list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs)
       
   118         if(num_of_archs GREATER 1)
       
   119             message(${WARNING} "Only one architecture in CMAKE_OSX_ARCHITECTURES is currently supported, picking the first one")
       
   120         endif()
       
   121     elseif(CMAKE_SIZEOF_VOID_P MATCHES "8")
       
   122         #if that variable is not set check if we are on x86_64 and if so force it, else use default
       
   123         add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64)
   147     endif()
   124     endif()
   148 
   125 
   149     #on OSX we need to provide the SDL_main() function when building as executable
   126     #on OSX we need to provide the SDL_main() function when building as executable
   150     if(NOT ${LIBENGINE})
   127     if(NOT BUILD_ENGINE_LIBRARY)
   151         add_subdirectory(sdlmain_osx)
   128         add_subdirectory(sdlmain)
   152         list(APPEND pascal_flags "-k${LIBRARY_OUTPUT_PATH}/libSDLmain.a")
   129         list(APPEND HW_LINK_LIBS SDLmain)
       
   130         add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
   153     endif()
   131     endif()
   154 
   132 
   155     #when you have multiple ld installation make sure you get the one bundled with the compiler
   133     #when sysroot is set, make sure that fpc picks it
   156     get_filename_component(compiler_dir ${CMAKE_C_COMPILER} PATH)
   134     if(CMAKE_OSX_SYSROOT)
   157     list(APPEND pascal_flags "-FD${compiler_dir}")
   135         set(add_flag_append "-XD${CMAKE_OSX_SYSROOT}")
       
   136     endif(CMAKE_OSX_SYSROOT)
   158 endif(APPLE)
   137 endif(APPLE)
       
   138 
       
   139 if(FFMPEG_FOUND)
       
   140     add_subdirectory(avwrapper)
       
   141     list(APPEND HW_LINK_LIBS avwrapper)
       
   142     add_definitions(-dUSE_VIDEO_RECORDING)
       
   143     add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
       
   144 endif()
   159 
   145 
   160 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   146 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   161 if(PNG_FOUND)
   147 if(PNG_FOUND)
   162     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
   148     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
   163     get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
   149     get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
   164     list(APPEND pascal_flags "-dPNG_SCREENSHOTS" "-Fl${PNG_LIBRARY_DIR}" "-k-L${PNG_LIBRARY_DIR}")
   150     add_flag_append(CMAKE_Pascal_FLAGS -Fl${PNG_LIBRARY_DIR})
   165 endif()
   151 endif()
   166 
   152 
   167 
   153 if(LUA_FOUND AND LUA_SYSTEM)
   168 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
   154     get_filename_component(LUA_LIBRARY_DIR ${LUA_LIBRARY} PATH)
   169 if(FREEPASCAL_VERSION VERSION_LESS "2.6")
   155     get_filename_component(LUA_LIBRARY_NAME ${LUA_LIBRARY} NAME)
   170     #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation
   156     #NAME_WE would strip the .1 (or .2) next to the ".so"
   171     if(UNIX)
   157     string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}(.*)${CMAKE_SHARED_LIBRARY_SUFFIX}" "\\1" LUA_LIBRARY_NAME "${LUA_LIBRARY_NAME}")
   172         set(SAFE_BUILD_TOOL $(MAKE))
   158     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LUA_LIBRARY_DIR} -XLAlua=${LUA_LIBRARY_NAME}")
   173     else()
   159 else()
   174         set(SAFE_BUILD_TOOL ${CMAKE_BUILD_TOOL})
   160     add_definitions(-dLUA_INTERNAL)
       
   161     list(APPEND HW_LINK_LIBS lua)
       
   162     add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}")
       
   163 endif()
       
   164 
       
   165 
       
   166 if(NOT PHYSFS_FOUND)
       
   167     add_definitions(-dPHYSFS_INTERNAL)
       
   168     list(APPEND HW_LINK_LIBS physfs)
       
   169     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
       
   170     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
       
   171     #(should be harmless on other platforms)
       
   172     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH} -XLAphysfs=${physfs_output_name}")
       
   173 endif()
       
   174 list(APPEND HW_LINK_LIBS physlayer)
       
   175 
       
   176 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
       
   177 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
       
   178 if(HAVE_MIXINIT)
       
   179     add_definitions(-dSDL_MIXER_NEWER)
       
   180 endif(HAVE_MIXINIT)
       
   181 
       
   182 #IMG_Init/IMG_Quit from SDL_image 1.2.8
       
   183 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
       
   184 if(HAVE_IMGINIT)
       
   185     add_definitions(-dSDL_IMAGE_NEWER)
       
   186 endif(HAVE_IMGINIT)
       
   187 
       
   188 #needs to be last
       
   189 add_definitions(-dDEBUGFILE)
       
   190 
       
   191 #SOURCE AND PROGRAMS SECTION
       
   192 if(BUILD_ENGINE_LIBRARY)
       
   193     message(${WARNING} "Engine will be built as library (experimental)")
       
   194     if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
       
   195         # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
       
   196         add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits")
   175     endif()
   197     endif()
   176     add_custom_target(ENGINECLEAN COMMAND ${SAFE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
   198 
   177 endif()
   199     #workaround for missing <TARGET> support during object generation
   178 
   200     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
   179 
   201     set(destination_dir ${target_library_install_dir})
   180 if(${FFMPEG_FOUND})
   202     add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}")
   181     # TODO: this check is only for SDL < 2
   203 
   182     # fpc will take care of linking but we need to have this library installed
   204     add_definitions(-dHWLIBRARY)
   183     find_package(GLUT REQUIRED)
   205     add_library(hwengine SHARED ${engine_sources} hwLibrary.pas)
   184 
       
   185     #TODO: convert avwrapper to .pas unit so we can skip this step
       
   186     include_directories(${FFMPEG_INCLUDE_DIR})
       
   187     list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING")
       
   188     if(WIN32)
       
   189         # there are some problems with linking our avwrapper as static lib, so link it as shared
       
   190         add_library(avwrapper SHARED videorec/avwrapper.c)
       
   191         target_link_libraries(avwrapper ${FFMPEG_LIBRARIES})
       
   192         install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}avwrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${target_library_install_dir})
       
   193         list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING")
       
   194     else()
       
   195         add_library(avwrapper STATIC videorec/avwrapper.c)
       
   196     endif()
       
   197 endif()
       
   198 
       
   199 
       
   200 set(fpc_flags ${pascal_flags} ${hwengine_project})
       
   201 
       
   202 if(NOT APPLE)
       
   203     #here is the command for standard executables or for shared library
       
   204     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
       
   205         COMMAND "${FREEPASCAL_EXECUTABLE}"
       
   206         ARGS ${fpc_flags} -o${engine_output_name}
       
   207         DEPENDS ${engine_sources}
       
   208         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
       
   209         )
       
   210 else()
   206 else()
   211     #these are the dependencies for building a universal binary on Mac OS X
   207     # no need to change name here because target has same name
   212     foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   208     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   213         list(APPEND lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   209     set(destination_dir ${target_binary_install_dir})
   214         add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   210     add_executable(hwengine ${engine_sources})
   215             COMMAND "${FREEPASCAL_EXECUTABLE}"
   211 endif()
   216             ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch}
   212 
   217             DEPENDS ${engine_sources}
   213 #even though not actually used, this will trigger relink if any lib changes
   218             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
   214 target_link_libraries(hwengine ${HW_LINK_LIBS})
   219             )
       
   220         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
       
   221         add_custom_command(TARGET hwengine.${build_arch} POST_BUILD
       
   222             COMMAND "install_name_tool"
       
   223             ARGS -id @executable_path/../Frameworks/${engine_output_name}
       
   224                 ${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}
       
   225             )
       
   226     endforeach()
       
   227 
       
   228     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
       
   229         COMMAND "lipo"
       
   230         ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}
       
   231         DEPENDS ${lipo_args_list}
       
   232         )
       
   233 endif()
       
   234 
       
   235 
       
   236 add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}")
       
   237 
       
   238 #when system Lua is not found we need to compile it before engine
       
   239 if(NOT LUA_FOUND)
       
   240     add_dependencies(hwengine lua)
       
   241 endif()
       
   242 
       
   243 # same for physfs
       
   244 if(NOT PHYSFS_FOUND)
       
   245     add_dependencies(hwengine physfs)
       
   246 endif()
       
   247 
       
   248 add_dependencies(hwengine physlayer)
       
   249 
       
   250 #when ffmpeg/libav is found we need to compile it before engine
       
   251 #TODO: convert avwrapper to .pas unit so we can skip this step
       
   252 if(${FFMPEG_FOUND})
       
   253     add_dependencies(hwengine avwrapper)
       
   254 endif()
       
   255 
       
   256 if(APPLE)
       
   257     add_dependencies(hwengine SDLmain)
       
   258 endif(APPLE)
       
   259 
       
   260 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
       
   261 if((FREEPASCAL_VERSION VERSION_LESS "2.6") AND (NOT ${FFMPEG_FOUND}))
       
   262     add_dependencies(hwengine ENGINECLEAN)
       
   263 endif()
       
   264 
   215 
   265 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir})
   216 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir})