hedgewars/CMakeLists.txt
changeset 7125 bfb759d07288
parent 7114 e0110a1229b7
child 7180 53ffc8853008
child 7223 b554726ff468
equal deleted inserted replaced
7111:5ba5a92d74fb 7125:bfb759d07288
    70     )
    70     )
    71 
    71 
    72 if(BUILD_ENGINE_LIBRARY)
    72 if(BUILD_ENGINE_LIBRARY)
    73     message(STATUS "Engine will be built as library (experimental)")
    73     message(STATUS "Engine will be built as library (experimental)")
    74     set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
    74     set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
    75     set(engine_sources ${hwengine_project} PascalExports.pas ${engine_sources})
    75     set(pascal_flags "-dHWLIBRARY" ${pascal_flags})
    76     set(pascal_compiler_flags_cmn "-dHWLIBRARY" ${pascal_compiler_flags_cmn})
       
    77 
    76 
    78     # create position independent code, only required for x68_64 builds, similar to -fPIC
    77     # create position independent code, only required for x68_64 builds, similar to -fPIC
    79     if(CMAKE_SIZEOF_VOID_P MATCHES "8")
    78     if(CMAKE_SIZEOF_VOID_P MATCHES "8")
    80         set(pascal_compiler_flags_cmn "-Cg" ${pascal_compiler_flags_cmn})
    79         set(pascal_flags "-Cg" ${pascal_flags})
    81     endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
    80     endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
    82 
    81 
    83     # due to compiling/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
    82     # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
    84     if(APPLE AND current_macosx_version GREATER "10.5")
    83     if(APPLE AND current_macosx_version GREATER "10.5")
    85         set(pascal_compiler_flags_cmn "-k-no_order_inits" ${pascal_compiler_flags_cmn})
    84         set(pascal_flags "-k-no_order_inits" ${pascal_flags})
    86     endif()
    85     endif()
    87 
    86 
    88     if (APPLE)
    87     if (APPLE)
    89         set(engine_output_name "hwengine.dylib")
    88         set(engine_output_name "hwengine.dylib")
    90     endif (APPLE)
    89     endif (APPLE)
   120     string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   119     string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}")
   121 
   120 
   122     if(powerpc_build)
   121     if(powerpc_build)
   123         set(powerpc_build "powerpc")
   122         set(powerpc_build "powerpc")
   124     endif()
   123     endif()
       
   124 
       
   125     #on OSX we need to provide the main() function when building as executable
       
   126     if(NOT BUILD_ENGINE_LIBRARY)
       
   127         #let's look for the bundled sdlmain, if not found build our own
       
   128         find_package(SDL REQUIRED)
       
   129         #remove the ";-framework Cocoa" from the SDL_LIBRARY variable
       
   130         string(REGEX REPLACE "(.*);-.*" "\\1" sdl_dir "${SDL_LIBRARY}")
       
   131         #find libsdmain.a
       
   132         find_file(SDLMAIN_LIB libSDLMain.a PATHS ${sdl_dir}/Resources/)
       
   133 
       
   134         if(SDLMAIN_LIB MATCHES "SDLMAIN_LIB-NOTFOUND")
       
   135             set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
       
   136             include_directories(${SDL_INCLUDE_DIR})
       
   137             add_library (SDLmain STATIC SDLMain.m)
       
   138             #add a dependency to the hwengine target
       
   139             set(engine_sources ${engine_sources} SDLmain)
       
   140             set(SDLMAIN_LIB "${CMAKE_BINARY_DIR}/bin/libSDLmain.a")
       
   141         endif()
       
   142 
       
   143         set(pascal_flags "-k${SDLMAIN_LIB}" ${pascal_flags})
       
   144     endif()
   125 endif(APPLE)
   145 endif(APPLE)
   126 
   146 
   127 
   147 
   128 #PASCAL DETECTION SECTION
   148 #PASCAL DETECTION SECTION
   129 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
   149 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
   131 if(fpc_version)
   151 if(fpc_version)
   132     string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
   152     string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
   133     string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
   153     string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
   134     string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
   154     string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
   135     message(STATUS "Freepascal version installed: ${fpc_vers_major}.${fpc_vers_minor}")
   155     message(STATUS "Freepascal version installed: ${fpc_vers_major}.${fpc_vers_minor}")
   136     math(EXPR fpc_ver "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
   156     math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
   137 
   157 
   138     if(fpc_ver LESS "020200")
   158     if(fpc_version LESS "020200")
   139         message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
   159         message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
   140     elseif(APPLE AND (fpc_ver LESS "020600"))
   160     elseif(APPLE AND (fpc_version LESS "020600"))
   141         message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X")
   161         message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X")
   142     endif()
   162     endif()
   143 else()
   163 else()
   144     message(FATAL_ERROR "No FreePascal compiler found!")
   164     message(FATAL_ERROR "No FreePascal compiler found!")
   145 endif()
   165 endif()
   146 
   166 
   147 
   167 
   148 #DEPENDECIES AND EXECUTABLES SECTION
   168 #DEPENDECIES AND EXECUTABLES SECTION
   149 find_package(PNG)
   169 if(NOT NOPNG)
   150 if(${PNG_FOUND})
   170     find_package(PNG)
   151     message(STATUS "PNG screenshots enabled (library found at ${PNG_LIBRARY})")
   171     if(${PNG_FOUND})
   152     set(pascal_compiler_flags_cmn "-dPNG_SCREENSHOTS" ${pascal_compiler_flags_cmn})
   172         message(STATUS "PNG screenshots enabled (library found at ${PNG_LIBRARY})")
   153     if(APPLE)  # need to explictly link with the static lib
   173         set(pascal_flags "-dPNG_SCREENSHOTS" ${pascal_flags})
   154         string(REGEX REPLACE "(.*)libpng.*" "\\1" PNG_LIBDIR "${PNG_LIBRARY}")
   174         if(APPLE)  # need to explictly link with the static lib
   155         set(pascal_compiler_flags_cmn "-k${PNG_LIBDIR}/libpng.a" ${pascal_compiler_flags_cmn})
   175             string(REGEX REPLACE "(.*)libpng.*" "\\1" PNG_LIBDIR "${PNG_LIBRARY}")
   156     endif()
   176             set(pascal_flags "-k${PNG_LIBDIR}/libpng.a" ${pascal_flags})
   157 else()
   177         endif()
   158     message(STATUS "PNG library not found, switching to screenshots in BMP format")
   178     else()
   159 endif()
   179         message(STATUS "PNG library not found, switching to screenshots in BMP format")
   160 
   180     endif()
   161 set(pascal_compiler ${fpc_executable})
   181 endif()
   162 set(pascal_compiler_flags ${noexecstack_flags} ${pascal_compiler_flags_cmn} ${hwengine_project})
   182 
       
   183 set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project})
   163 
   184 
   164 
   185 
   165 IF(NOT APPLE)
   186 IF(NOT APPLE)
   166     #here is the command for standard executables or for shared library
   187     #here is the command for standard executables or for shared library
   167     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}"
   188     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}"
   168         COMMAND "${pascal_compiler}"
   189         COMMAND "${fpc_executable}"
   169         ARGS ${pascal_compiler_flags}
   190         ARGS ${fpc_flags}
   170         MAIN_DEPENDENCY ${hwengine_project}
   191         MAIN_DEPENDENCY ${hwengine_project}
   171         DEPENDS ${engine_sources}
   192         DEPENDS ${engine_sources}
   172         )
   193         )
   173 ELSE()
   194 ELSE()
   174     #let's build sdlmain, which is absent from the framework
       
   175     find_package(SDL REQUIRED)
       
   176 
       
   177     set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
       
   178     include_directories(${SDL_INCLUDE_DIR})
       
   179 
       
   180     add_library (SDLmain STATIC SDLMain.m)
       
   181 
       
   182 
       
   183     #these are the dependencies for building a universal binary on Mac OS X
   195     #these are the dependencies for building a universal binary on Mac OS X
   184     foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   196     foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
   185         set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list})
   197         set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list})
   186         add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   198         add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
   187             COMMAND "${pascal_compiler}"
   199             COMMAND "${fpc_executable}"
   188             ARGS ${pascal_compiler_flags} -ohwengine.${build_arch} -P${build_arch}
   200             ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch}
   189             MAIN_DEPENDENCY ${hwengine_project}
   201             MAIN_DEPENDENCY ${hwengine_project}
   190             DEPENDS ${engine_sources} SDLmain
   202             DEPENDS ${engine_sources}
   191             )
   203             )
   192         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   204         add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
   193     endforeach()
   205     endforeach()
   194 
   206 
   195     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
   207     add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"