hedgewars/CMakeLists.txt
branchwebgl
changeset 9950 2759212a27de
parent 9521 8054d9d775fd
parent 9945 c4ae96531f8c
child 10015 4feced261c68
equal deleted inserted replaced
9521:8054d9d775fd 9950:2759212a27de
     1 find_package(SDL)
     1 find_package(SDL1or2)
     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 (CheckLibraryExists)
     7 include(CheckLibraryExists)
       
     8 include(${CMAKE_MODULE_PATH}/utils.cmake)
     8 
     9 
     9 
    10 
    10 enable_language(Pascal)
    11 enable_language(Pascal)
       
    12 add_flag_append(CMAKE_Pascal_FLAGS "-Cs2000000")
       
    13 add_flag_append(CMAKE_Pascal_FLAGS_DEBUG "-gv")
       
    14 add_flag_append(CMAKE_Pascal_FLAGS_RELEASE "-Xs")
       
    15 if(UNIX)
       
    16     include(TargetArch)
       
    17     target_architecture(CMAKE_TARGET_ARCHITECTURES)
       
    18     if(${CMAKE_Pascal_COMPILER_VERSION} VERSION_GREATER 2.7 OR ${CMAKE_TARGET_ARCHITECTURES} MATCHES "x86_64" OR ${CMAKE_TARGET_ARCHITECTURES} MATCHES "i386")
       
    19         add_flag_append(CMAKE_Pascal_FLAGS "-fPIC")
       
    20     endif()
       
    21 endif(UNIX)
       
    22 
    11 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    23 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
    12 include_directories(${CMAKE_CURRENT_BINARY_DIR})
    24 include_directories(${CMAKE_CURRENT_BINARY_DIR})
    13 
    25 
    14 
    26 
    15 #set the sources with the correct order of dependencies so that cmake won't be confused
    27 #set the sources with the correct order of dependencies so that cmake won't be confused
    77     uGearsUtils.pas
    89     uGearsUtils.pas
    78     uTeams.pas
    90     uTeams.pas
    79 
    91 
    80     #these interact with everything, so compile last
    92     #these interact with everything, so compile last
    81     uScript.pas
    93     uScript.pas
    82     hwengine.pas
       
    83 
       
    84     #we also have uTouch.pas
       
    85     options.inc
       
    86     ${CMAKE_CURRENT_BINARY_DIR}/config.inc
       
    87     )
    94     )
    88 
    95 
    89 
    96 
    90 include(${CMAKE_MODULE_PATH}/utils.cmake)
    97 include(${CMAKE_MODULE_PATH}/utils.cmake)
    91 #opengl 2
    98 #opengl 2
   100 elseif(CMAKE_Pascal_COMPILER_VERSION VERSION_GREATER 2.4)
   107 elseif(CMAKE_Pascal_COMPILER_VERSION VERSION_GREATER 2.4)
   101     #enable INLINE only with a recent version of fpc
   108     #enable INLINE only with a recent version of fpc
   102     add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si)
   109     add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si)
   103 endif()
   110 endif()
   104 
   111 
       
   112 #generic folder where our libraries reside
       
   113 add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH}")
   105 
   114 
   106 #DEPENDECIES AND EXECUTABLES SECTION
   115 #DEPENDECIES AND EXECUTABLES SECTION
   107 if(NOT ${BUILD_ENGINE_LIBRARY} AND APPLE)
   116 if(NOT ${BUILD_ENGINE_LIBRARY} AND APPLE)
   108     #on OSX we need to provide the SDL_main() function when building as executable
   117     #on OSX we need to provide the SDL_main() function when building as executable
   109     add_subdirectory(sdlmain)
   118     add_subdirectory(sdlmain)
   110     list(APPEND HW_LINK_LIBS SDLmain)
   119     list(APPEND HW_LINK_LIBS SDLmain)
   111     add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
       
   112 endif()
   120 endif()
   113 
   121 
   114 if(FFMPEG_FOUND)
   122 if(FFMPEG_FOUND)
   115     add_subdirectory(avwrapper)
   123     add_subdirectory(avwrapper)
   116     list(APPEND HW_LINK_LIBS avwrapper)
   124     list(APPEND HW_LINK_LIBS avwrapper)
   117     add_definitions(-dUSE_VIDEO_RECORDING)
   125     add_definitions(-dUSE_VIDEO_RECORDING)
   118     add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH})
       
   119     #only for SDL < 2, linking carried out by fpc
   126     #only for SDL < 2, linking carried out by fpc
   120     find_package_or_disable_msg(GLUT NOVIDEOREC "Video recording will not be built")
   127     find_package_or_disable_msg(GLUT NOVIDEOREC "Video recording will not be built")
   121 endif()
   128 endif()
   122 
   129 
   123 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   130 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
   124 if(PNG_FOUND)
   131 if(PNG_FOUND)
   125     list(INSERT engine_sources 0 PNGh.pas)
   132     list(INSERT engine_sources 0 PNGh.pas)
   126     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
   133     list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
   127     get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
   134     get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
   128     add_flag_append(CMAKE_Pascal_FLAGS -Fl${PNG_LIBRARY_DIR})
   135     add_flag_append(CMAKE_Pascal_FLAGS "-k-L${PNG_LIBRARY_DIR} -Fl${PNG_LIBRARY_DIR}")
       
   136     add_definitions(-dPNG_SCREENSHOTS)
   129 endif()
   137 endif()
   130 
   138 
   131 if(LUA_FOUND AND LUA_SYSTEM)
   139 if(LUA_FOUND AND LUA_SYSTEM)
   132     get_filename_component(LUA_LIBRARY_DIR ${LUA_LIBRARY} PATH)
   140     get_filename_component(LUA_LIBRARY_DIR ${LUA_LIBRARY} PATH)
   133     get_filename_component(LUA_LIBRARY_NAME ${LUA_LIBRARY} NAME)
   141     get_filename_component(LUA_LIBRARY_NAME ${LUA_LIBRARY} NAME)
   138     add_definitions(-dLUA_INTERNAL)
   146     add_definitions(-dLUA_INTERNAL)
   139     list(APPEND HW_LINK_LIBS lua)
   147     list(APPEND HW_LINK_LIBS lua)
   140     add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}")
   148     add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}")
   141 endif()
   149 endif()
   142 
   150 
   143 
   151 if(PHYSFS_FOUND)
   144 if(NOT PHYSFS_FOUND)
   152     get_filename_component(PHYSFS_LIBRARY_DIR ${PHYSFS_LIBRARY} PATH)
       
   153     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${PHYSFS_LIBRARY}")
       
   154 else()
   145     add_definitions(-dPHYSFS_INTERNAL)
   155     add_definitions(-dPHYSFS_INTERNAL)
   146     list(APPEND HW_LINK_LIBS physfs)
   156     list(APPEND HW_LINK_LIBS physfs)
   147     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
   157     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
   148     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
   158     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
   149     #(should be harmless on other platforms)
   159     #(should be harmless on other platforms)
   150     add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH} -XLAphysfs=${physfs_output_name}")
   160     add_flag_append(CMAKE_Pascal_FLAGS "-XLAphysfs=${physfs_output_name}")
   151 endif()
   161 endif()
   152 list(APPEND HW_LINK_LIBS physlayer)
   162 list(APPEND HW_LINK_LIBS physlayer)
       
   163 
   153 
   164 
   154 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
   165 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10
   155 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
   166 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT)
   156 if(HAVE_MIXINIT)
   167 if(HAVE_MIXINIT)
   157     add_definitions(-dSDL_MIXER_NEWER)
   168     add_definitions(-dSDL_MIXER_NEWER)
   161 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
   172 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT)
   162 if(HAVE_IMGINIT)
   173 if(HAVE_IMGINIT)
   163     add_definitions(-dSDL_IMAGE_NEWER)
   174     add_definitions(-dSDL_IMAGE_NEWER)
   164 endif(HAVE_IMGINIT)
   175 endif(HAVE_IMGINIT)
   165 
   176 
       
   177 if(NOT (SDL_VERSION VERSION_LESS 2.0))
       
   178     add_definitions(-dSDL2)
       
   179 endif()
       
   180 
   166 #needs to be last
   181 #needs to be last
   167 add_definitions(-dDEBUGFILE)
   182 add_definitions(-dDEBUGFILE)
       
   183 
       
   184 
       
   185 # source files are with full path after this
       
   186 set(sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/options.inc" "${CMAKE_CURRENT_BINARY_DIR}/config.inc")
       
   187 foreach(loop_var ${engine_sources})
       
   188     list(APPEND sourcefiles_sofar "${CMAKE_CURRENT_SOURCE_DIR}/${loop_var}")
       
   189 endforeach(loop_var)
       
   190 
   168 
   191 
   169 #SOURCE AND PROGRAMS SECTION
   192 #SOURCE AND PROGRAMS SECTION
   170 if(BUILD_ENGINE_LIBRARY)
   193 if(BUILD_ENGINE_LIBRARY)
   171     message("***Engine will be built as library (experimental)***")
   194     message("***Engine will be built as library (experimental)***")
   172     if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
   195     if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
   178     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
   201     set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
   179     set(destination_dir ${target_library_install_dir})
   202     set(destination_dir ${target_library_install_dir})
   180     add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}")
   203     add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}")
   181 
   204 
   182     add_definitions(-dHWLIBRARY)
   205     add_definitions(-dHWLIBRARY)
   183     add_library(hwengine SHARED ${engine_sources} hwLibrary.pas)
   206     set_source_files_properties(hwLibrary.pas PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar}")
       
   207     set_source_files_properties(hwLibrary.pas PROPERTIES OBJECT_DEPENDS hwengine.pas)
       
   208     add_library(hwengine SHARED hwLibrary.pas)
   184 else()
   209 else()
   185     # no need to change name here because target has same name
   210     # no need to change name here because target has same name
   186     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   211     set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
   187     set(destination_dir ${target_binary_install_dir})
   212     set(destination_dir ${target_binary_install_dir})
   188     add_executable(hwengine ${engine_sources})
   213     set_source_files_properties(hwengine.pas PROPERTIES OBJECT_DEPENDS "${sourcefiles_sofar}")
       
   214     add_executable(hwengine hwengine.pas)
   189 endif()
   215 endif()
   190 
   216 
   191 #even though not actually used, this will trigger relink if any lib changes
   217 #even though not actually used, this will trigger relink if any lib changes
   192 target_link_libraries(hwengine ${HW_LINK_LIBS})
   218 target_link_libraries(hwengine ${HW_LINK_LIBS})
   193 
   219