hedgewars/CMakeLists.txt
branchwebgl
changeset 8833 c13ebed437cb
parent 8444 75db7bb8dce8
parent 8830 343d3f0d6a86
child 8847 ff7fbab7cd56
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
     2 find_package(SDL_image)
     2 find_package(SDL_image)
     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(${CMAKE_SOURCE_DIR}/cmake_modules/FindSDL_Extras.cmake)
     7 include (CheckLibraryExists)
       
     8 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
       
     9 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
       
    10 if(HAVE_MIXINIT)
       
    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 
     8 
    19 
     9 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    20 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    10 
    21 
    11 #SOURCE AND PROGRAMS SECTION
    22 #SOURCE AND PROGRAMS SECTION
    12 if(${LIBENGINE})
    23 if(${LIBENGINE})
    13     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
    24     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
    14     set(hwengine_project ${CMAKE_CURRENT_SOURCE_DIR}/hwLibrary.pas)
    25     set(hwengine_project hwLibrary.pas)
    15 else()
    26 else()
    16     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
    27     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
    17     set(hwengine_project ${CMAKE_CURRENT_SOURCE_DIR}/hwengine.pas)
    28     set(hwengine_project hwengine.pas)
    18 endif()
    29 endif()
    19 
    30 
    20 if (APPLE)
    31 if (APPLE)
    21     set(required_fpc_version 2.6)
    32     set(required_fpc_version 2.6)
    22 else()
    33 else()
    90     adler32.pas
   101     adler32.pas
    91     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
   102     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
    92     )
   103     )
    93 
   104 
    94 if(${LIBENGINE})
   105 if(${LIBENGINE})
    95     message(WARNING "Engine will be built as library (experimental)")
   106     message(${WARNING} "Engine will be built as library (experimental)")
    96     list(APPEND pascal_flags "-dHWLIBRARY")
   107     list(APPEND pascal_flags "-dHWLIBRARY")
    97 
   108 
    98     # create position independent code, only required for x68_64 builds, similar to -fPIC
   109     # create position independent code, only required for x68_64 builds, similar to -fPIC
    99     if(CMAKE_SIZEOF_VOID_P MATCHES "8")
   110     if(CMAKE_SIZEOF_VOID_P MATCHES "8")
   100         list(APPEND pascal_flags "-Cg")
   111         list(APPEND pascal_flags "-Cg")
   108 else(${LIBENGINE})
   119 else(${LIBENGINE})
   109     set(destination_dir ${target_binary_install_dir})
   120     set(destination_dir ${target_binary_install_dir})
   110 endif(${LIBENGINE})
   121 endif(${LIBENGINE})
   111 
   122 
   112 
   123 
       
   124 include(${CMAKE_MODULE_PATH}/utils.cmake)
   113 #opengl 2
   125 #opengl 2
   114 IF(${GL2})
   126 IF(${GL2})
   115     set(pascal_flags "-dGL2" ${pascal_flags})
   127     set(pascal_flags "-dGL2" ${pascal_flags})
   116     message(STATUS "Building using OpenGL 2")
   128     message(STATUS "Building using OpenGL 2")
   117 ENDIF(${GL2})
   129 ENDIF(${GL2})
   118 # Check Freepascal version
   130 
   119 find_package(Freepascal)
   131 find_package_or_fail(FreePascal)
   120 
   132 
   121 if (FPC_VERSION VERSION_LESS required_fpc_version)
   133 #when cmake-2.6 support is dropped, this ought to be inside FindFreePascal.cmake
   122     message(FATAL_ERROR "Freepascal is too old, minimum version required is ${required_fpc_version}")
   134 if (FREEPASCAL_VERSION VERSION_LESS required_fpc_version)
       
   135     message(FATAL_ERROR "Freepascal ${FREEPASCAL_VERSION} is too old, minimum version required is ${required_fpc_version}")
   123 endif()
   136 endif()
   124 
   137 
   125 
   138 
   126 #DEPENDECIES AND EXECUTABLES SECTION
   139 #DEPENDECIES AND EXECUTABLES SECTION
   127 if(APPLE)
   140 if(APPLE)
   150             set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a")
   163             set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a")
   151         endif()
   164         endif()
   152 
   165 
   153         list(APPEND pascal_flags "-k${SDLMAIN_LIB}")
   166         list(APPEND pascal_flags "-k${SDLMAIN_LIB}")
   154     endif()
   167     endif()
       
   168 
       
   169     #when you have multiple ld installation make sure you get the one bundled with the compiler
       
   170     get_filename_component(compiler_dir ${CMAKE_C_COMPILER} PATH)
       
   171     list(APPEND pascal_flags "-FD${compiler_dir}")
   155 endif(APPLE)
   172 endif(APPLE)
   156 
   173 
   157 if(NOT NOPNG)
   174 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   158     find_package(PNG)
   175 if(PNG_FOUND)
   159     if(${PNG_FOUND})
   176     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
   160         list(APPEND pascal_flags "-dPNG_SCREENSHOTS")
   177     get_filename_component(PNG_LIB_DIR ${PNG_LIBRARIES} PATH)
   161         if(APPLE)  # fpc png unit doesn't pull the library (see bug 21833)
   178     list(APPEND pascal_flags "-dPNG_SCREENSHOTS" "-Fl${PNG_LIB_DIR}")
   162             list(APPEND pascal_flags "-k${PNG_LIBRARY}")
       
   163         endif()
       
   164     else()
       
   165         message(WARNING "Screenshots will be in BMP format because libpng was not found")
       
   166     endif()
       
   167 else()
       
   168     message(STATUS "Screenshots will be in BMP format per user request")
       
   169 endif()
   179 endif()
   170 
   180 
   171 
   181 
   172 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
   182 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
   173 if(FPC_VERSION VERSION_LESS "2.6")
   183 if(FREEPASCAL_VERSION VERSION_LESS "2.6")
   174     #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation
   184     #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation
   175     if(UNIX)
   185     if(UNIX)
   176         set(SAFE_BUILD_TOOL $(MAKE))
   186         set(SAFE_BUILD_TOOL $(MAKE))
   177     else()
   187     else()
   178         set(SAFE_BUILD_TOOL ${CMAKE_BUILD_TOOL})
   188         set(SAFE_BUILD_TOOL ${CMAKE_BUILD_TOOL})
   179     endif()
   189     endif()
   180     add_custom_target(ENGINECLEAN COMMAND ${SAFE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/hedgewars")
   190     add_custom_target(ENGINECLEAN COMMAND ${SAFE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
   181 endif()
   191 endif()
   182 
   192 
   183 
   193 
   184 if(NOT NOVIDEOREC)
   194 if(${FFMPEG_FOUND})
   185     set(FFMPEG_FIND_QUIETLY true)
   195     # TODO: this check is only for SDL < 2
   186     find_package(FFMPEG)
   196     # fpc will take care of linking but we need to have this library installed
   187     if(${FFMPEG_FOUND})
   197     find_package(GLUT REQUIRED)
   188         # TODO: this check is only for SDL < 2
   198 
   189         # fpc will take care of linking but we need to have this library installed
   199     #TODO: convert avwrapper to .pas unit so we can skip this step
   190         find_package(GLUT REQUIRED)
   200     include_directories(${FFMPEG_INCLUDE_DIR})
   191 
   201     list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING")
   192         #TODO: convert avwrapper to .pas unit so we can skip this step
   202     if(WIN32)
   193         include_directories(${FFMPEG_INCLUDE_DIR})
   203         # there are some problems with linking our avwrapper as static lib, so link it as shared
       
   204         add_library(avwrapper SHARED videorec/avwrapper.c)
       
   205         target_link_libraries(avwrapper ${FFMPEG_LIBRARIES})
       
   206         install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}avwrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${target_library_install_dir})
   194         list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING")
   207         list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING")
   195         IF (WIN32)
       
   196             # there are some problems with linking our avwrapper as static lib, so link it as shared
       
   197             add_library(avwrapper SHARED videorec/avwrapper.c)
       
   198             target_link_libraries(avwrapper ${FFMPEG_LIBRARIES})
       
   199             install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}avwrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${target_library_install_dir})
       
   200         ELSE()
       
   201             add_library(avwrapper STATIC videorec/avwrapper.c)
       
   202             list(APPEND pascal_flags "-k${FFMPEG_LIBAVCODEC}" "-k${FFMPEG_LIBAVFORMAT}" "-k${FFMPEG_LIBAVUTIL}")
       
   203         ENDIF()
       
   204     else()
   208     else()
   205         message(WARNING "Could NOT find FFMPEG/LibAV, video recording will be disabled")
   209         add_library(avwrapper STATIC videorec/avwrapper.c)
   206     endif()
   210     endif()
   207 else()
   211 endif()
   208     message(STATUS "Video recording disabled by user")
   212 
   209 endif()
   213 
   210 
   214 set(fpc_flags ${pascal_flags} ${hwengine_project})
   211 
       
   212 set(fpc_flags ${NOEXECSTACK_FLAGS} ${pascal_flags} ${hwengine_project})
       
   213 
   215 
   214 if(NOT APPLE)
   216 if(NOT APPLE)
   215     #here is the command for standard executables or for shared library
   217     #here is the command for standard executables or for shared library
   216     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
   218     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
   217         COMMAND "${FPC_EXECUTABLE}"
   219         COMMAND "${FREEPASCAL_EXECUTABLE}"
   218         ARGS ${fpc_flags} -o${engine_output_name}
   220         ARGS ${fpc_flags} -o${engine_output_name}
   219         MAIN_DEPENDENCY ${hwengine_project}
       
   220         DEPENDS ${engine_sources}
   221         DEPENDS ${engine_sources}
       
   222         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
   221         )
   223         )
   222 else()
   224 else()
   223     #these are the dependencies for building a universal binary on Mac OS X
   225     #these are the dependencies for building a universal binary on Mac OS X
   224     foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   226     foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   225         list(APPEND lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   227         list(APPEND lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   226         add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   228         add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   227             COMMAND "${FPC_EXECUTABLE}"
   229             COMMAND "${FREEPASCAL_EXECUTABLE}"
   228             ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch}
   230             ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch}
   229             MAIN_DEPENDENCY ${hwengine_project}
       
   230             DEPENDS ${engine_sources}
   231             DEPENDS ${engine_sources}
       
   232             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
   231             )
   233             )
   232         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   234         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   233         add_custom_command(TARGET hwengine.${build_arch} POST_BUILD
   235         add_custom_command(TARGET hwengine.${build_arch} POST_BUILD
   234             COMMAND "install_name_tool"
   236             COMMAND "install_name_tool"
   235             ARGS -id @executable_path/../Frameworks/${engine_output_name}
   237             ARGS -id @executable_path/../Frameworks/${engine_output_name}
   250 #when system Lua is not found we need to compile it before engine
   252 #when system Lua is not found we need to compile it before engine
   251 if(NOT LUA_FOUND)
   253 if(NOT LUA_FOUND)
   252     add_dependencies(hwengine lua)
   254     add_dependencies(hwengine lua)
   253 endif()
   255 endif()
   254 
   256 
   255 # compile physfs before engine
   257 # same for physfs
   256 add_dependencies(hwengine physfs)
   258 if(NOT PHYSFS_FOUND)
       
   259     add_dependencies(hwengine physfs)
       
   260 endif()
       
   261 
       
   262 add_dependencies(hwengine physlayer)
   257 
   263 
   258 #when ffmpeg/libav is found we need to compile it before engine
   264 #when ffmpeg/libav is found we need to compile it before engine
   259 #TODO: convert avwrapper to .pas unit so we can skip this step
   265 #TODO: convert avwrapper to .pas unit so we can skip this step
   260 if(${FFMPEG_FOUND})
   266 if(${FFMPEG_FOUND})
   261     add_dependencies(hwengine avwrapper)
   267     add_dependencies(hwengine avwrapper)
   262 endif()
   268 endif()
   263 
   269 
   264 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
   270 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
   265 if((FPC_VERSION VERSION_LESS "2.6") AND (NOVIDEOREC OR NOT ${FFMPEG_FOUND}))
   271 if((FREEPASCAL_VERSION VERSION_LESS "2.6") AND (NOT ${FFMPEG_FOUND}))
   266     add_dependencies(hwengine ENGINECLEAN)
   272     add_dependencies(hwengine ENGINECLEAN)
   267 endif()
   273 endif()
   268 
   274 
   269 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir})
   275 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir})