hedgewars/CMakeLists.txt
branchsdl2transition
changeset 11342 ed5a6478e710
parent 11338 7a7611adf715
parent 11275 d49a1a295d81
child 11382 ee86941e2ade
equal deleted inserted replaced
11340:31570b766315 11342:ed5a6478e710
     4 find_package(SDL2_image REQUIRED)
     4 find_package(SDL2_image REQUIRED)
     5 find_package(SDL2_net REQUIRED)
     5 find_package(SDL2_net REQUIRED)
     6 find_package(SDL2_ttf REQUIRED)
     6 find_package(SDL2_ttf REQUIRED)
     7 find_package(SDL2_mixer REQUIRED)
     7 find_package(SDL2_mixer REQUIRED)
     8 
     8 
     9 include (CheckLibraryExists)
     9 include(CheckLibraryExists)
       
    10 include(${CMAKE_MODULE_PATH}/utils.cmake)
       
    11 
       
    12 
       
    13 enable_language(Pascal)
       
    14 add_flag_append(CMAKE_Pascal_FLAGS "-Cs2000000")
       
    15 add_flag_append(CMAKE_Pascal_FLAGS_DEBUG "-gv")
       
    16 add_flag_append(CMAKE_Pascal_FLAGS_RELEASE "-Xs")
       
    17 if(UNIX)
       
    18     include(TargetArch)
       
    19     target_architecture(CMAKE_TARGET_ARCHITECTURES)
       
    20     if(${CMAKE_Pascal_COMPILER_VERSION} VERSION_GREATER 2.7 OR ${CMAKE_TARGET_ARCHITECTURES} MATCHES "x86_64" OR ${CMAKE_TARGET_ARCHITECTURES} MATCHES "i386")
       
    21         add_flag_append(CMAKE_Pascal_FLAGS "-fPIC")
       
    22     endif()
       
    23 endif(UNIX)
       
    24 
       
    25 # convert list into pascal array
       
    26 if(FONTS_DIRS)
       
    27   list(LENGTH FONTS_DIRS ndirs)
       
    28   set(FONTS_DIRS_ARRAY "array [0..${ndirs}] of PChar = (")
       
    29   foreach(fontdir ${FONTS_DIRS})
       
    30       set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\n_P'${fontdir}',")
       
    31   endforeach(fontdir)
       
    32   set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\nnil);\n")
       
    33 else(FONTS_DIRS)
       
    34   set(FONTS_DIRS_ARRAY "array [0..1] of PChar = (nil, nil);")
       
    35 endif(FONTS_DIRS)
    10 
    36 
    11 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    37 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    12 include_directories(${CMAKE_CURRENT_BINARY_DIR})
    38 include_directories(${CMAKE_CURRENT_BINARY_DIR})
    13 
    39 
    14 
    40 
    47     uLandTexture.pas
    73     uLandTexture.pas
    48     uLandGraphics.pas
    74     uLandGraphics.pas
    49     uLandPainted.pas
    75     uLandPainted.pas
    50     uLandOutline.pas
    76     uLandOutline.pas
    51     uLandGenMaze.pas
    77     uLandGenMaze.pas
       
    78     uLandGenPerlin.pas
       
    79     uLandGenTemplateBased.pas
       
    80     uLandUtils.pas
    52 
    81 
    53     #this is where dependency tracking becomes hard
    82     #this is where dependency tracking becomes hard
    54     uStore.pas
    83     uStore.pas
    55     uAmmos.pas
    84     uAmmos.pas
    56     uLandObjects.pas
    85     uLandObjects.pas
    77     uGearsUtils.pas
   106     uGearsUtils.pas
    78     uTeams.pas
   107     uTeams.pas
    79 
   108 
    80     #these interact with everything, so compile last
   109     #these interact with everything, so compile last
    81     uScript.pas
   110     uScript.pas
    82     hwengine.pas
       
    83 
       
    84     #we also have uTouch.pas
       
    85     options.inc
       
    86     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
       
    87     )
   111     )
    88 
   112 
    89 
   113 
    90 include(${CMAKE_MODULE_PATH}/utils.cmake)
   114 if(${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.2 OR # older versions are just ancient
    91 
   115    (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.6 AND APPLE)) # because of 64bit and opengl bindings
    92 if (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.2 OR # older versions are just ancient
       
    93     (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.6 AND APPLE)) # because of 64bit and opengl bindings
       
    94     message(FATAL_ERROR "Your FreePascal installation is too old (fpc ${CMAKE_Pascal_COMPILER_VERSION})!")
   116     message(FATAL_ERROR "Your FreePascal installation is too old (fpc ${CMAKE_Pascal_COMPILER_VERSION})!")
    95 elseif(CMAKE_Pascal_COMPILER_VERSION VERSION_GREATER 2.4)
   117 elseif(${CMAKE_Pascal_COMPILER_VERSION} VERSION_GREATER 2.4)
    96     #enable INLINE only with a recent version of fpc
   118     #enable INLINE only with a recent version of fpc
    97     add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si)
   119     add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si)
    98 endif()
   120 endif()
    99 
   121 
   100 
   122 #generic folder where our libraries reside
   101 if(FFMPEG_FOUND)
   123 add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH}")
       
   124 
       
   125 #DEPENDECIES AND EXECUTABLES SECTION
       
   126 if(APPLE AND (NOT BUILD_ENGINE_LIBRARY))
       
   127     #on OSX we need to provide the SDL_main() function when building as
       
   128     #executable and the entry point too
       
   129     add_subdirectory(sdlmain)
       
   130     list(APPEND HW_LINK_LIBS SDLmain)
       
   131     add_flag_append(CMAKE_Pascal_FLAGS "-k-lsdlmain")
       
   132     add_flag_append(CMAKE_Pascal_FLAGS "-XMSDL_main")
       
   133     #OpenGL deps
       
   134     add_flag_append(CMAKE_Pascal_FLAGS "-k-framework -kCocoa")
       
   135     add_flag_append(CMAKE_Pascal_FLAGS "-k-framework -kOpenGL")
       
   136 
       
   137     #set the correct library or framework style depending on the main SDL
       
   138     string(FIND "${SDL_LIBRARY}" "dylib" sdl_framework)
       
   139     if(${sdl_framework} GREATER -1)
       
   140         add_flag_append(CMAKE_Pascal_FLAGS "-k-lsdl -k-lsdl_image -k-lsdl_mixer -k-lsdl_ttf -k-lsdl_net")
       
   141     else()
       
   142         add_flag_append(CMAKE_Pascal_FLAGS "-k-framework -kSDL -k-framework -kSDL_image -k-framework -kSDL_mixer -k-framework -kSDL_net -k-framework -kSDL_net -k-framework -kSDL_ttf")
       
   143     endif()
       
   144 endif()
       
   145 
       
   146 if(LIBAV_FOUND)
   102     add_subdirectory(avwrapper)
   147     add_subdirectory(avwrapper)
   103     list(APPEND HW_LINK_LIBS avwrapper)
   148     list(APPEND HW_LINK_LIBS avwrapper)
   104     add_definitions(-dUSE_VIDEO_RECORDING)
   149     add_definitions(-dUSE_VIDEO_RECORDING)
   105     add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
       
   106     
       
   107 endif()
   150 endif()
   108 
   151 
   109 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   152 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   110 if(PNG_FOUND)
   153 if(PNG_FOUND)
   111     list(INSERT engine_sources 0 PNGh.pas)
   154     list(INSERT engine_sources 0 PNGh.pas)
   112     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
   155     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
   113     get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
   156     get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
   114     add_flag_append(CMAKE_Pascal_FLAGS -Fl${PNG_LIBRARY_DIR})
   157     add_flag_append(CMAKE_Pascal_FLAGS "-k-L${PNG_LIBRARY_DIR} -Fl${PNG_LIBRARY_DIR}")
   115     add_definitions(-dPNG_SCREENSHOTS)
   158     add_definitions(-dPNG_SCREENSHOTS)
   116 endif()
   159 endif()
   117 
   160 
   118 if(LUA_FOUND AND LUA_SYSTEM)
   161 if(LUA_SYSTEM)
   119     get_filename_component(LUA_LIBRARY_DIR ${LUA_LIBRARY} PATH)
   162     get_filename_component(LUA_LIBRARY_DIR ${LUA_LIBRARY} PATH)
   120     get_filename_component(LUA_LIBRARY_NAME ${LUA_LIBRARY} NAME)
   163     get_filename_component(LUA_LIBRARY_NAME ${LUA_LIBRARY} NAME)
   121     #NAME_WE would strip the .1 (or .2) next to the ".so"
   164     #NAME_WE would strip the .1 (or .2) next to the ".so"
   122     string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}(.*)${CMAKE_SHARED_LIBRARY_SUFFIX}" "\\1" LUA_LIBRARY_NAME "${LUA_LIBRARY_NAME}")
   165     string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}(.*)${CMAKE_SHARED_LIBRARY_SUFFIX}" "\\1" LUA_LIBRARY_NAME "${LUA_LIBRARY_NAME}")
   123     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LUA_LIBRARY_DIR} -XLAlua=${LUA_LIBRARY_NAME}")
   166     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LUA_LIBRARY_DIR} -XLAlua=${LUA_LIBRARY_NAME}")
   125     add_definitions(-dLUA_INTERNAL)
   168     add_definitions(-dLUA_INTERNAL)
   126     list(APPEND HW_LINK_LIBS lua)
   169     list(APPEND HW_LINK_LIBS lua)
   127     add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}")
   170     add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}")
   128 endif()
   171 endif()
   129 
   172 
   130 
   173 if(PHYSFS_SYSTEM)
   131 if(NOT PHYSFS_FOUND)
   174     get_filename_component(PHYSFS_LIBRARY_DIR ${PHYSFS_LIBRARY} PATH)
       
   175     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${PHYSFS_LIBRARY}")
       
   176 else()
   132     add_definitions(-dPHYSFS_INTERNAL)
   177     add_definitions(-dPHYSFS_INTERNAL)
   133     list(APPEND HW_LINK_LIBS physfs)
   178     list(APPEND HW_LINK_LIBS physfs)
   134     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
   179     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
   135     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
   180     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
   136     #(should be harmless on other platforms)
   181     #(should be harmless on other platforms)
   137     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH} -XLAphysfs=${physfs_output_name}")
   182     add_flag_append(CMAKE_Pascal_FLAGS "-XLAphysfs=${physfs_output_name}")
   138 endif()
   183 endif()
   139 list(APPEND HW_LINK_LIBS physlayer)
   184 list(APPEND HW_LINK_LIBS physlayer)
   140 
   185 
       
   186 
   141 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
   187 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
       
   188 check_library_exists(${SDL2MIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
       
   189 if(HAVE_MIXINIT)
       
   190     add_definitions(-dSDL_MIXER_NEWER)
       
   191 endif(HAVE_MIXINIT)
       
   192 
       
   193 #IMG_Init/IMG_Quit from SDL_image 1.2.8
       
   194 check_library_exists(${SDL2IMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
       
   195 if(HAVE_IMGINIT)
       
   196     add_definitions(-dSDL_IMAGE_NEWER)
       
   197 endif(HAVE_IMGINIT)
       
   198 
       
   199 #opengl 2
       
   200 IF(GL2)
       
   201     add_definitions(-dGL2)
       
   202 ENDIF(GL2)
   142 
   203 
   143 #needs to be last
   204 #needs to be last
   144 add_definitions(-dDEBUGFILE)
   205 add_definitions(-dDEBUGFILE)
   145 
   206 
   146 
   207 
   147 # make source files objects depend on their predecessors in list
   208 # source files are with full path after this
   148 set(sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/options.inc" "${CMAKE_CURRENT_BINARY_DIR}/config.inc")
   209 set(sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/options.inc" "${CMAKE_CURRENT_BINARY_DIR}/config.inc")
   149 foreach(loop_var ${engine_sources})
   210 foreach(loop_var ${engine_sources})
   150     SET_SOURCE_FILES_PROPERTIES(${loop_var} PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar}")
       
   151     list(APPEND sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/${loop_var}")
   211     list(APPEND sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/${loop_var}")
   152 endforeach(loop_var)
   212 endforeach(loop_var)
   153 
   213 
   154 
   214 
   155 #SOURCE AND PROGRAMS SECTION
   215 #SOURCE AND PROGRAMS SECTION
   156 if(BUILD_ENGINE_LIBRARY)
   216 if(BUILD_ENGINE_LIBRARY)
   157     message("***Engine will be built as library (experimental)***")
   217     message("***Engine will be built as library (experimental)***")
   158     if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
   218     if(APPLE)
   159         # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
   219         if (${current_macosx_version} VERSION_GREATER "10.5")
   160         add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits")
   220             # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
       
   221             add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits")
       
   222         endif()
   161     endif()
   223     endif()
   162 
   224 
   163     #workaround for missing <TARGET> support during object generation
   225     #workaround for missing <TARGET> support during object generation
   164     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
   226     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
   165     set(destination_dir ${target_library_install_dir})
   227     set(destination_dir ${target_library_install_dir})
   166     add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}")
   228     add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}")
   167 
   229 
   168     add_definitions(-dHWLIBRARY)
   230     add_definitions(-dHWLIBRARY)
   169     add_library(hwengine SHARED ${engine_sources} hwLibrary.pas)
   231     set_source_files_properties(hwLibrary.pas PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar};${CMAKE_CURRENT_SOURCE_DIR}/hwengine.pas")
       
   232     add_library(hwengine SHARED hwLibrary.pas)
   170 else()
   233 else()
   171     # no need to change name here because target has same name
   234     # no need to change name here because target has same name
   172     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   235     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   173     set(destination_dir ${target_binary_install_dir})
   236     set(destination_dir ${target_binary_install_dir})
   174     add_executable(hwengine ${engine_sources})
   237     set_source_files_properties(hwengine.pas PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar}")
       
   238     add_executable(hwengine hwengine.pas)
   175 endif()
   239 endif()
   176 
   240 
   177 #even though not actually used, this will trigger relink if any lib changes
   241 #even though not actually used, this will trigger relink if any lib changes
   178 target_link_libraries(hwengine ${HW_LINK_LIBS})
   242 target_link_libraries(hwengine ${HW_LINK_LIBS})
   179 
   243