hedgewars/CMakeLists.txt
branchwebgl
changeset 8096 453917e94e55
parent 8044 796f2653f21d
parent 8093 2286a39140da
child 8330 aaefa587e277
equal deleted inserted replaced
8053:2e836bebb518 8096:453917e94e55
     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_MODULE_PATH}/FindSDL_Extras.cmake)
     7 include(${CMAKE_SOURCE_DIR}/cmake_modules/FindSDL_Extras.cmake)
     8 
     8 
     9 configure_file(${CMAKE_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
     9 configure_file(${CMAKE_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    10 
    10 
    11 #SOURCE AND PROGRAMS SECTION
    11 #SOURCE AND PROGRAMS SECTION
    12 set(hwengine_project ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas)
    12 set(hwengine_project ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas)
    53     uLandTexture.pas
    53     uLandTexture.pas
    54     uLocale.pas
    54     uLocale.pas
    55     uMatrix.pas
    55     uMatrix.pas
    56     uMisc.pas
    56     uMisc.pas
    57     uMobile.pas
    57     uMobile.pas
       
    58     uPhysFSLayer.pas
    58     uRandom.pas
    59     uRandom.pas
    59     uRender.pas
    60     uRender.pas
    60     uRenderUtils.pas
    61     uRenderUtils.pas
    61     uScript.pas
    62     uScript.pas
    62     uSinTable.pas
    63     uSinTable.pas
    93     # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
    94     # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
    94     if(APPLE AND current_macosx_version GREATER "10.5")
    95     if(APPLE AND current_macosx_version GREATER "10.5")
    95         set(pascal_flags "-k-no_order_inits" ${pascal_flags})
    96         set(pascal_flags "-k-no_order_inits" ${pascal_flags})
    96     endif()
    97     endif()
    97 
    98 
    98     if (APPLE)
    99     if(APPLE)
    99         set(engine_output_name "hwengine.dylib")
   100         set(engine_output_name "libhwengine.dylib")
   100     endif (APPLE)
   101     endif (APPLE)
   101 endif(LIBENGINE)
   102 endif(LIBENGINE)
   102 
   103 
       
   104 
       
   105 #PASCAL DETECTION SECTION
   103 IF(FPC)
   106 IF(FPC)
   104     set(fpc_executable ${FPC})
   107     set(fpc_executable ${FPC})
   105 ELSE()
   108 ELSE()
   106     find_program(fpc_executable fpc)
   109     find_program(fpc_executable fpc)
   107 ENDIF()
   110 ENDIF()
   108 
   111 
   109 if(fpc_executable)
   112 message(STATUS "Check for working FPC compiler: ${fpc_executable}")
   110     exec_program(${fpc_executable} ARGS "-iV" OUTPUT_VARIABLE fpc_output)
   113 execute_process(COMMAND ${fpc_executable} -iV OUTPUT_VARIABLE fpc_output ERROR_VARIABLE fpc_error)
   111 endif(fpc_executable)
   114 if(fpc_error)
   112 
   115     message(STATUS "Check for working FPC compiler: ${fpc_executable} -- broken")
       
   116 else(fpc_error)
       
   117     message(STATUS "Check for working FPC compiler: ${fpc_executable} -- works")
       
   118 endif(fpc_error)
       
   119 
       
   120 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
       
   121 if(fpc_version)
       
   122     string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
       
   123     string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
       
   124     string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
       
   125     message(STATUS "Found Freepascal: ${fpc_executable} (version ${fpc_vers_major}.${fpc_vers_minor})")
       
   126     math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
       
   127 
       
   128     if(fpc_version LESS "020200")
       
   129         message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
       
   130     elseif(APPLE AND (fpc_version LESS "020600"))
       
   131         message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X")
       
   132     endif()
       
   133 else()
       
   134     message(FATAL_ERROR "No FreePascal compiler found!")
       
   135 endif()
       
   136 
       
   137 message(STATUS "Checking whether linker supports noexecstack flag")
   113 set(noexecstack_flags "-k-z" "-knoexecstack")
   138 set(noexecstack_flags "-k-z" "-knoexecstack")
   114 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
   139 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
   115 
   140 
   116 exec_program(${fpc_executable} ${EXECUTABLE_OUTPUT_PATH}
   141 execute_process(COMMAND ${fpc_executable} ${noexecstack_flags} checkstack.pas
   117     ARGS ${noexecstack_flags} checkstack.pas
   142     WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
   118     OUTPUT_VARIABLE noout
   143     RESULT_VARIABLE testnoexecstack
   119     RETURN_VALUE testnoexecstack
   144     OUTPUT_QUIET ERROR_QUIET
   120     )
   145     )
   121 
   146 
   122 if(${testnoexecstack})
   147 if(${testnoexecstack})
   123     set (noexecstack_flags "")
   148     set (noexecstack_flags "")
       
   149     message(STATUS "Checking whether linker supports noexecstack flag -- no")
       
   150 else(${testnoexecstack})
       
   151     message(STATUS "Checking whether linker supports noexecstack flag -- yes")
   124 endif(${testnoexecstack})
   152 endif(${testnoexecstack})
   125 
   153 
   126 
   154 #DEPENDECIES AND EXECUTABLES SECTION
   127 if(APPLE)
   155 if(APPLE)
   128     string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   156     string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
   129     string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   157     string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
   130     string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   158     string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   131 
   159 
   150             set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a")
   178             set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a")
   151         endif()
   179         endif()
   152 
   180 
   153         set(pascal_flags "-k${SDLMAIN_LIB}" ${pascal_flags})
   181         set(pascal_flags "-k${SDLMAIN_LIB}" ${pascal_flags})
   154     endif()
   182     endif()
       
   183     set(pascal_flags "-k${LIBRARY_OUTPUT_PATH}/libphysfs.a" ${pascal_flags})
   155 endif(APPLE)
   184 endif(APPLE)
   156 
   185 
   157 
       
   158 #PASCAL DETECTION SECTION
       
   159 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
       
   160 
       
   161 if(fpc_version)
       
   162     string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
       
   163     string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
       
   164     string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
       
   165     message(STATUS "Found Freepascal: ${fpc_executable} (version ${fpc_vers_major}.${fpc_vers_minor})")
       
   166     math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
       
   167 
       
   168     if(fpc_version LESS "020200")
       
   169         message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
       
   170     elseif(APPLE AND (fpc_version LESS "020600"))
       
   171         message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X")
       
   172     endif()
       
   173 else()
       
   174     message(FATAL_ERROR "No FreePascal compiler found!")
       
   175 endif()
       
   176 
       
   177 
       
   178 #DEPENDECIES AND EXECUTABLES SECTION
       
   179 if(NOT NOPNG)
   186 if(NOT NOPNG)
   180     find_package(PNG)
   187     find_package(PNG)
   181     if(${PNG_FOUND})
   188     if(${PNG_FOUND})
   182         set(pascal_flags "-dPNG_SCREENSHOTS" ${pascal_flags})
   189         set(pascal_flags "-dPNG_SCREENSHOTS" ${pascal_flags})
   183         if(APPLE)  # fpc png unit doesn't pull the library (see bug 21833)
   190         if(APPLE)  # fpc png unit doesn't pull the library (see bug 21833)
   184             set(pascal_flags "-k${PNG_LIBRARY}" ${pascal_flags})
   191             set(pascal_flags "-k${PNG_LIBRARY}" ${pascal_flags})
   185         endif()
   192         endif()
   186     else()
   193     else()
   187         message(STATUS "Screenshots will be in BMP format because libpng was not found")
   194         message(WARNING "Screenshots will be in BMP format because libpng was not found")
   188     endif()
   195     endif()
   189 else()
   196 else()
   190     message(STATUS "Screenshots will be in BMP format per user request")
   197     message(STATUS "Screenshots will be in BMP format per user request")
   191 endif()
   198 endif()
   192 
       
   193 
   199 
   194 
   200 
   195 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
   201 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
   196 if(fpc_version LESS "020600")
   202 if(fpc_version LESS "020600")
   197     #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation
   203     #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation
   224         ELSE()
   230         ELSE()
   225             add_library(avwrapper STATIC videorec/avwrapper.c)
   231             add_library(avwrapper STATIC videorec/avwrapper.c)
   226             set(pascal_flags "-k${FFMPEG_LIBAVCODEC}" "-k${FFMPEG_LIBAVFORMAT}" "-k${FFMPEG_LIBAVUTIL}" ${pascal_flags})
   232             set(pascal_flags "-k${FFMPEG_LIBAVCODEC}" "-k${FFMPEG_LIBAVFORMAT}" "-k${FFMPEG_LIBAVUTIL}" ${pascal_flags})
   227         ENDIF()
   233         ENDIF()
   228     else()
   234     else()
   229         message(STATUS "Could NOT find FFMPEG/LibAV, video recording will be disabled")
   235         message(WARNING "Could NOT find FFMPEG/LibAV, video recording will be disabled")
   230     endif()
   236     endif()
   231 else()
   237 else()
   232     message(STATUS "Video recording disabled by user")
   238     message(STATUS "Video recording disabled by user")
   233 endif()
   239 endif()
       
   240 
       
   241 set(pascal_flags "-Fl${LIBRARY_OUTPUT_PATH}" ${pascal_flags})
   234 
   242 
   235 set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project})
   243 set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project})
   236 
   244 
   237 IF(NOT APPLE)
   245 IF(NOT APPLE)
   238     #here is the command for standard executables or for shared library
   246     #here is the command for standard executables or for shared library
   268 #when system Lua is not found we need to compile it before engine
   276 #when system Lua is not found we need to compile it before engine
   269 if(NOT LUA_FOUND)
   277 if(NOT LUA_FOUND)
   270     add_dependencies(${engine_output_name} lua)
   278     add_dependencies(${engine_output_name} lua)
   271 endif()
   279 endif()
   272 
   280 
       
   281 # compile physfs before engine
       
   282 add_dependencies(${engine_output_name} physfs)
       
   283 
   273 #when ffmpeg/libav is found we need to compile it before engine
   284 #when ffmpeg/libav is found we need to compile it before engine
   274 #TODO: convert avwrapper to .pas unit so we can skip this step
   285 #TODO: convert avwrapper to .pas unit so we can skip this step
   275 if(${FFMPEG_FOUND})
   286 if(${FFMPEG_FOUND})
   276     add_dependencies(${engine_output_name} avwrapper)
   287     add_dependencies(${engine_output_name} avwrapper)
   277 endif()
   288 endif()