hedgewars/CMakeLists.txt
branchcmake_pascal
changeset 8775 3cad01db0bae
parent 8770 53481d654691
child 8787 f9dc079f2aa6
equal deleted inserted replaced
8772:c9583cf8e10d 8775:3cad01db0bae
     6 
     6 
     7 include (CheckLibraryExists)
     7 include (CheckLibraryExists)
     8 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
     8 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
     9 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
     9 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
    10 if(HAVE_MIXINIT)
    10 if(HAVE_MIXINIT)
    11     list(APPEND pascal_flags "-dSDL_MIXER_NEWER")
    11     add_definitions(-dSDL_MIXER_NEWER)
    12 endif()
    12 endif()
    13 #IMG_Init/IMG_Quit from SDL_image 1.2.8
    13 #IMG_Init/IMG_Quit from SDL_image 1.2.8
    14 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
    14 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
    15 if(HAVE_IMGINIT)
    15 if(HAVE_IMGINIT)
    16     list(APPEND pascal_flags "-dSDL_IMAGE_NEWER")
    16     add_definitions(-dSDL_IMAGE_NEWER)
    17 endif()
    17 endif()
    18 
    18 
    19 
    19 
    20 enable_language(Pascal)
    20 enable_language(Pascal)
    21 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    21 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
   104     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
   104     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
   105     )
   105     )
   106 
   106 
   107 if(${BUILD_ENGINE_LIBRARY})
   107 if(${BUILD_ENGINE_LIBRARY})
   108     message(${WARNING} "Engine will be built as library (experimental)")
   108     message(${WARNING} "Engine will be built as library (experimental)")
   109     list(APPEND pascal_flags "-dHWLIBRARY")
   109     add_definitions(-dHWLIBRARY)
   110 
       
   111     # create position independent code, only required for x68_64 builds, similar to -fPIC
       
   112     if(CMAKE_SIZEOF_VOID_P MATCHES "8")
       
   113         list(APPEND pascal_flags "-Cg")
       
   114     endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
       
   115 
   110 
   116     # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
   111     # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
   117     if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
   112     if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
   118         list(APPEND pascal_flags "-k-no_order_inits")
   113         add_flag_append(CMAKE_Pascal_FLAGS "-k-no_order_inits")
   119     endif()
   114     endif()
   120     set(destination_dir ${target_library_install_dir})
   115     set(destination_dir ${target_library_install_dir})
   121 else(${BUILD_ENGINE_LIBRARY})
   116 else(${BUILD_ENGINE_LIBRARY})
   122     set(destination_dir ${target_binary_install_dir})
   117     set(destination_dir ${target_binary_install_dir})
   123 endif(${BUILD_ENGINE_LIBRARY})
   118 endif(${BUILD_ENGINE_LIBRARY})
   145 
   140 
   146     #on OSX we need to provide the SDL_main() function when building as executable
   141     #on OSX we need to provide the SDL_main() function when building as executable
   147     if(NOT ${BUILD_ENGINE_LIBRARY})
   142     if(NOT ${BUILD_ENGINE_LIBRARY})
   148         #let's look for the installed sdlmain file; if it is not found, let's build our own
   143         #let's look for the installed sdlmain file; if it is not found, let's build our own
   149         find_package(SDL REQUIRED)
   144         find_package(SDL REQUIRED)
   150         #remove the ";-framework Cocoa" from the SDL_LIBRARY variable
   145         include_directories(${SDL_INCLUDE_DIR})
   151         string(REGEX REPLACE "(.*);-.*" "\\1" sdl_library_only "${SDL_LIBRARY}")
   146         add_library (SDLmain STATIC SDLMain.m)
   152         #find libsdmain.a
   147         add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
   153         find_file(SDLMAIN_LIB libSDLMain.a PATHS ${sdl_library_only}/Resources/)
   148     endif()
   154 
       
   155         if(SDLMAIN_LIB MATCHES "SDLMAIN_LIB-NOTFOUND")
       
   156             include_directories(${SDL_INCLUDE_DIR})
       
   157             add_library (SDLmain STATIC SDLMain.m)
       
   158             #add a dependency to the hwengine target
       
   159             list(APPEND engine_sources SDLmain)
       
   160             set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a")
       
   161         endif()
       
   162 
       
   163         list(APPEND pascal_flags "-k${SDLMAIN_LIB}")
       
   164     endif()
       
   165 
       
   166     #when you have multiple ld installation make sure you get the one bundled with the compiler
       
   167     get_filename_component(compiler_dir ${CMAKE_C_COMPILER} PATH)
       
   168     list(APPEND pascal_flags "-FD${compiler_dir}")
       
   169 endif(APPLE)
   149 endif(APPLE)
   170 
       
   171 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
       
   172 if(FREEPASCAL_VERSION VERSION_LESS "2.6")
       
   173     #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation
       
   174     if(UNIX)
       
   175         set(SAFE_BUILD_TOOL $(MAKE))
       
   176     else()
       
   177         set(SAFE_BUILD_TOOL ${CMAKE_BUILD_TOOL})
       
   178     endif()
       
   179     add_custom_target(ENGINECLEAN COMMAND ${SAFE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
       
   180 endif()
       
   181 
   150 
   182 
   151 
   183 if(${FFMPEG_FOUND})
   152 if(${FFMPEG_FOUND})
   184     # TODO: this check is only for SDL < 2
   153     # TODO: this check is only for SDL < 2
   185     # fpc will take care of linking but we need to have this library installed
   154     # fpc will take care of linking but we need to have this library installed
   186     find_package(GLUT REQUIRED)
   155     find_package(GLUT REQUIRED)
   187 
   156 
   188     #TODO: convert avwrapper to .pas unit so we can skip this step
   157     #TODO: convert avwrapper to .pas unit so we can skip this step
   189     include_directories(${FFMPEG_INCLUDE_DIR})
   158     include_directories(${FFMPEG_INCLUDE_DIR})
   190     list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING")
       
   191     if(WIN32)
   159     if(WIN32)
   192         # there are some problems with linking our avwrapper as static lib, so link it as shared
   160         # there are some problems with linking our avwrapper as static lib, so link it as shared
   193         add_library(avwrapper SHARED avwrapper.c)
   161         add_library(avwrapper SHARED avwrapper.c)
   194         target_link_libraries(avwrapper ${FFMPEG_LIBRARIES})
   162         target_link_libraries(avwrapper ${FFMPEG_LIBRARIES})
   195         install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}avwrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${target_library_install_dir})
   163         install(PROGRAMS "${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}avwrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${target_library_install_dir})
   196     else()
   164     else()
   197         add_library(avwrapper STATIC avwrapper.c)
   165         add_library(avwrapper STATIC avwrapper.c)
   198     endif()
   166     endif()
       
   167     add_definitions(-dUSE_VIDEO_RECORDING)
       
   168     add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
   199 endif()
   169 endif()
   200 
   170 
   201 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   171 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   202 if(PNG_FOUND)
   172 if(PNG_FOUND)
   203     get_filename_component(PNG_LIB_DIR ${PNG_LIBRARY} PATH)
   173     get_filename_component(PNG_LIB_DIR ${PNG_LIBRARY} PATH)
   204     add_definitions(-dPNG_SCREENSHOTS -Fl${PNG_LIB_DIR})
   174     add_definitions(-dPNG_SCREENSHOTS)
   205 endif()
   175     add_flag_append(CMAKE_Pascal_FLAGS -Fl${PNG_LIB_DIR})
   206 
   176 endif()
   207 
   177 
   208 set(CMAKE_Pascal_FLAGS "-vm4079,4080,4081 -Fl${PROJECT_BINARY_DIR}/bin -Cs2000000 -vewnq -dDEBUGFILE ${CMAKE_Pascal_FLAGS}")
   178 if(NOT PHYSFS_FOUND)
       
   179     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
       
   180     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
       
   181     #(should be harmless on other platforms)
       
   182     add_flag_append(CMAKE_Pascal_FLAGS "-XLAphysfs=${physfs_output_name}")
       
   183     add_definitions(-dPHYSFS_INTERNAL)
       
   184 endif()
       
   185 
       
   186 if(APPLE)
       
   187     add_flag_append(CMAKE_Pascal_FLAGS -Px86_64)
       
   188 else()
       
   189     add_flag_append(CMAKE_Pascal_FLAGS -Pi386)
       
   190 endif()
       
   191 
       
   192 add_definitions(-dDEBUGFILE)
   209 add_executable(hwengine ${engine_sources})
   193 add_executable(hwengine ${engine_sources})
   210 
       
   211 if(APPLE)
       
   212     set(CMAKE_Pascal_FLAGS "-Px86_64  -k-llua -k${SDLMAIN_LIB} ${CMAKE_Pascal_FLAGS}")
       
   213 else()
       
   214     set(CMAKE_Pascal_FLAGS "-Pi386 ${CMAKE_Pascal_FLAGS}")
       
   215 endif()
       
   216 set(fpc_flags ${pascal_flags} ${hwengine_project})
       
   217 
       
   218 #add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}")
       
   219 
   194 
   220 #when system Lua is not found we need to compile it before engine
   195 #when system Lua is not found we need to compile it before engine
   221 if(NOT LUA_FOUND)
   196 if(NOT LUA_FOUND)
   222     add_dependencies(hwengine lua)
   197     add_dependencies(hwengine lua)
   223 endif()
   198 endif()