hedgewars/CMakeLists.txt
branchsdl2transition
changeset 11342 ed5a6478e710
parent 11338 7a7611adf715
parent 11275 d49a1a295d81
child 11382 ee86941e2ade
--- a/hedgewars/CMakeLists.txt	Tue Nov 10 18:16:35 2015 +0100
+++ b/hedgewars/CMakeLists.txt	Tue Nov 10 20:43:13 2015 +0100
@@ -6,7 +6,33 @@
 find_package(SDL2_ttf REQUIRED)
 find_package(SDL2_mixer REQUIRED)
 
-include (CheckLibraryExists)
+include(CheckLibraryExists)
+include(${CMAKE_MODULE_PATH}/utils.cmake)
+
+
+enable_language(Pascal)
+add_flag_append(CMAKE_Pascal_FLAGS "-Cs2000000")
+add_flag_append(CMAKE_Pascal_FLAGS_DEBUG "-gv")
+add_flag_append(CMAKE_Pascal_FLAGS_RELEASE "-Xs")
+if(UNIX)
+    include(TargetArch)
+    target_architecture(CMAKE_TARGET_ARCHITECTURES)
+    if(${CMAKE_Pascal_COMPILER_VERSION} VERSION_GREATER 2.7 OR ${CMAKE_TARGET_ARCHITECTURES} MATCHES "x86_64" OR ${CMAKE_TARGET_ARCHITECTURES} MATCHES "i386")
+        add_flag_append(CMAKE_Pascal_FLAGS "-fPIC")
+    endif()
+endif(UNIX)
+
+# convert list into pascal array
+if(FONTS_DIRS)
+  list(LENGTH FONTS_DIRS ndirs)
+  set(FONTS_DIRS_ARRAY "array [0..${ndirs}] of PChar = (")
+  foreach(fontdir ${FONTS_DIRS})
+      set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\n_P'${fontdir}',")
+  endforeach(fontdir)
+  set(FONTS_DIRS_ARRAY "${FONTS_DIRS_ARRAY}\nnil);\n")
+else(FONTS_DIRS)
+  set(FONTS_DIRS_ARRAY "array [0..1] of PChar = (nil, nil);")
+endif(FONTS_DIRS)
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
@@ -49,6 +75,9 @@
     uLandPainted.pas
     uLandOutline.pas
     uLandGenMaze.pas
+    uLandGenPerlin.pas
+    uLandGenTemplateBased.pas
+    uLandUtils.pas
 
     #this is where dependency tracking becomes hard
     uStore.pas
@@ -79,31 +108,45 @@
 
     #these interact with everything, so compile last
     uScript.pas
-    hwengine.pas
-
-    #we also have uTouch.pas
-    options.inc
-    ${CMAKE_CURRENT_BINARY_DIR}/config.inc
     )
 
 
-include(${CMAKE_MODULE_PATH}/utils.cmake)
-
-if (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.2 OR # older versions are just ancient
-    (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.6 AND APPLE)) # because of 64bit and opengl bindings
+if(${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.2 OR # older versions are just ancient
+   (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.6 AND APPLE)) # because of 64bit and opengl bindings
     message(FATAL_ERROR "Your FreePascal installation is too old (fpc ${CMAKE_Pascal_COMPILER_VERSION})!")
-elseif(CMAKE_Pascal_COMPILER_VERSION VERSION_GREATER 2.4)
+elseif(${CMAKE_Pascal_COMPILER_VERSION} VERSION_GREATER 2.4)
     #enable INLINE only with a recent version of fpc
     add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si)
 endif()
 
+#generic folder where our libraries reside
+add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH}")
 
-if(FFMPEG_FOUND)
+#DEPENDECIES AND EXECUTABLES SECTION
+if(APPLE AND (NOT BUILD_ENGINE_LIBRARY))
+    #on OSX we need to provide the SDL_main() function when building as
+    #executable and the entry point too
+    add_subdirectory(sdlmain)
+    list(APPEND HW_LINK_LIBS SDLmain)
+    add_flag_append(CMAKE_Pascal_FLAGS "-k-lsdlmain")
+    add_flag_append(CMAKE_Pascal_FLAGS "-XMSDL_main")
+    #OpenGL deps
+    add_flag_append(CMAKE_Pascal_FLAGS "-k-framework -kCocoa")
+    add_flag_append(CMAKE_Pascal_FLAGS "-k-framework -kOpenGL")
+
+    #set the correct library or framework style depending on the main SDL
+    string(FIND "${SDL_LIBRARY}" "dylib" sdl_framework)
+    if(${sdl_framework} GREATER -1)
+        add_flag_append(CMAKE_Pascal_FLAGS "-k-lsdl -k-lsdl_image -k-lsdl_mixer -k-lsdl_ttf -k-lsdl_net")
+    else()
+        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")
+    endif()
+endif()
+
+if(LIBAV_FOUND)
     add_subdirectory(avwrapper)
     list(APPEND HW_LINK_LIBS avwrapper)
     add_definitions(-dUSE_VIDEO_RECORDING)
-    add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
-    
 endif()
 
 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
@@ -111,11 +154,11 @@
     list(INSERT engine_sources 0 PNGh.pas)
     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
     get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
-    add_flag_append(CMAKE_Pascal_FLAGS -Fl${PNG_LIBRARY_DIR})
+    add_flag_append(CMAKE_Pascal_FLAGS "-k-L${PNG_LIBRARY_DIR} -Fl${PNG_LIBRARY_DIR}")
     add_definitions(-dPNG_SCREENSHOTS)
 endif()
 
-if(LUA_FOUND AND LUA_SYSTEM)
+if(LUA_SYSTEM)
     get_filename_component(LUA_LIBRARY_DIR ${LUA_LIBRARY} PATH)
     get_filename_component(LUA_LIBRARY_NAME ${LUA_LIBRARY} NAME)
     #NAME_WE would strip the .1 (or .2) next to the ".so"
@@ -127,27 +170,44 @@
     add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}")
 endif()
 
-
-if(NOT PHYSFS_FOUND)
+if(PHYSFS_SYSTEM)
+    get_filename_component(PHYSFS_LIBRARY_DIR ${PHYSFS_LIBRARY} PATH)
+    add_flag_append(CMAKE_Pascal_FLAGS "-Fl${PHYSFS_LIBRARY}")
+else()
     add_definitions(-dPHYSFS_INTERNAL)
     list(APPEND HW_LINK_LIBS physfs)
     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
     #(should be harmless on other platforms)
-    add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH} -XLAphysfs=${physfs_output_name}")
+    add_flag_append(CMAKE_Pascal_FLAGS "-XLAphysfs=${physfs_output_name}")
 endif()
 list(APPEND HW_LINK_LIBS physlayer)
 
+
 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
+check_library_exists(${SDL2MIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
+if(HAVE_MIXINIT)
+    add_definitions(-dSDL_MIXER_NEWER)
+endif(HAVE_MIXINIT)
+
+#IMG_Init/IMG_Quit from SDL_image 1.2.8
+check_library_exists(${SDL2IMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
+if(HAVE_IMGINIT)
+    add_definitions(-dSDL_IMAGE_NEWER)
+endif(HAVE_IMGINIT)
+
+#opengl 2
+IF(GL2)
+    add_definitions(-dGL2)
+ENDIF(GL2)
 
 #needs to be last
 add_definitions(-dDEBUGFILE)
 
 
-# make source files objects depend on their predecessors in list
+# source files are with full path after this
 set(sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/options.inc" "${CMAKE_CURRENT_BINARY_DIR}/config.inc")
 foreach(loop_var ${engine_sources})
-    SET_SOURCE_FILES_PROPERTIES(${loop_var} PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar}")
     list(APPEND sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/${loop_var}")
 endforeach(loop_var)
 
@@ -155,9 +215,11 @@
 #SOURCE AND PROGRAMS SECTION
 if(BUILD_ENGINE_LIBRARY)
     message("***Engine will be built as library (experimental)***")
-    if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
-        # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
-        add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits")
+    if(APPLE)
+        if (${current_macosx_version} VERSION_GREATER "10.5")
+            # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
+            add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits")
+        endif()
     endif()
 
     #workaround for missing <TARGET> support during object generation
@@ -166,12 +228,14 @@
     add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}")
 
     add_definitions(-dHWLIBRARY)
-    add_library(hwengine SHARED ${engine_sources} hwLibrary.pas)
+    set_source_files_properties(hwLibrary.pas PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar};${CMAKE_CURRENT_SOURCE_DIR}/hwengine.pas")
+    add_library(hwengine SHARED hwLibrary.pas)
 else()
     # no need to change name here because target has same name
     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
     set(destination_dir ${target_binary_install_dir})
-    add_executable(hwengine ${engine_sources})
+    set_source_files_properties(hwengine.pas PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar}")
+    add_executable(hwengine hwengine.pas)
 endif()
 
 #even though not actually used, this will trigger relink if any lib changes