CMakeLists.txt
branchsdl2transition
changeset 11342 ed5a6478e710
parent 11338 7a7611adf715
parent 11289 f8529d679a0d
child 11388 d3b603323b2b
equal deleted inserted replaced
11340:31570b766315 11342:ed5a6478e710
    10 
    10 
    11 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
    11 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
    12 include(${CMAKE_MODULE_PATH}/utils.cmake)
    12 include(${CMAKE_MODULE_PATH}/utils.cmake)
    13 
    13 
    14 #possible cmake configuration
    14 #possible cmake configuration
    15 option(NOSERVER "Disable gameServer build (off)]" OFF)
    15 option(NOSERVER "Disable gameServer build (off)" OFF)
    16 option(NOPNG "Disable screenshoot compression (off)" OFF)
    16 option(NOPNG "Disable screenshoot compression (off)" OFF)
    17 option(NOVIDEOREC "Disable video recording (off)" OFF)
    17 option(NOVIDEOREC "Disable video recording (off)" OFF)
    18 
    18 
    19 #libraries are built shared unless explicitly added as a static
    19 #libraries are built shared unless explicitly added as a static
    20 option(BUILD_SHARED_LIBS "Build libraries as shared modules (on)" ON)
    20 option(BUILD_SHARED_LIBS "Build libraries as shared modules (on)" ON)
    21 #set this to ON when 2.1.0 becomes more widespread (and only for linux)
       
    22 option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
       
    23 
    21 
    24 if(WIN32 OR APPLE)
    22 if(WIN32 OR APPLE)
       
    23     option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
    25     option(LUA_SYSTEM "Use system lua (off)" OFF)
    24     option(LUA_SYSTEM "Use system lua (off)" OFF)
    26 else()
    25 else()
       
    26     option(PHYSFS_SYSTEM "Use system physfs (on)" ON)
    27     option(LUA_SYSTEM "Use system lua (on)" ON)
    27     option(LUA_SYSTEM "Use system lua (on)" ON)
    28 endif()
    28 endif()
    29 
    29 
    30 option(BUILD_ENGINE_LIBRARY "Enable hwengine library (off)" OFF)
    30 option(BUILD_ENGINE_LIBRARY "Enable hwengine library (off)" OFF)
    31 option(ANDROID "Enable Android build (off)" OFF)
    31 option(ANDROID "Enable Android build (off)" OFF)
    32 
    32 
    33 option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF)
    33 option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF)
    34 option(NOAUTOUPDATE "Disable OS X Sparkle update checking (off)" OFF)
    34 option(NOAUTOUPDATE "Disable OS X Sparkle update checking (off)" OFF)
       
    35 option(SKIPBUNDLE "Do not create relocate bundle (off)" OFF)
       
    36 
       
    37 option(BUILD_ENGINE_C "Compile hwengine as native C (off)" OFF)
       
    38 option(GL2 "Enable OpenGL 2 rendering !!!EXPERIMENTAL - DO NOT USE!!! [default: off)" OFF)
    35 
    39 
    36 set(GHFLAGS "" CACHE STRING "Additional Haskell flags")
    40 set(GHFLAGS "" CACHE STRING "Additional Haskell flags")
    37 if(UNIX AND NOT APPLE)
    41 if(UNIX AND NOT APPLE)
    38     set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
    42     set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
    39 endif()
    43 endif()
    40 
    44 
       
    45 option(NOVERSIONINFOUPDATE "Disable update of version_info.txt. To be used if source is in a git/repo that is NOT the hedgewars repo" OFF)
       
    46 
       
    47 #system paths for finding required fonts (see share/hedgewars/Data/fonts)
       
    48 #subdirectories will NOT be searched.
       
    49 #all fonts that can't be found will be bundled with hedgewars
       
    50 set(FONTS_DIRS "" CACHE STRING "Additional paths to folders where required fonts can be found ( ; is separator)")
    41 
    51 
    42 #versioning
    52 #versioning
    43 set(CPACK_PACKAGE_VERSION_MAJOR 0)
    53 set(CPACK_PACKAGE_VERSION_MAJOR 0)
    44 set(CPACK_PACKAGE_VERSION_MINOR 9)
    54 set(CPACK_PACKAGE_VERSION_MINOR 9)
    45 set(CPACK_PACKAGE_VERSION_PATCH 20)
    55 set(CPACK_PACKAGE_VERSION_PATCH 23)
    46 set(HEDGEWARS_PROTO_VER 46)
    56 set(HEDGEWARS_PROTO_VER 52)
    47 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
    57 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
    48 include(${CMAKE_MODULE_PATH}/revinfo.cmake)
    58 include(${CMAKE_MODULE_PATH}/revinfo.cmake)
    49 
    59 
    50 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
    60 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
    51 
    61 
    52 #io library paths
    62 #io library paths
    53 include(${CMAKE_MODULE_PATH}/paths.cmake)
    63 include(${CMAKE_MODULE_PATH}/paths.cmake)
    54 #general utilities
    64 #general utilities
    55 include(${CMAKE_MODULE_PATH}/utils.cmake)
    65 include(${CMAKE_MODULE_PATH}/utils.cmake)
       
    66 #paths initialization
       
    67 include(${CMAKE_MODULE_PATH}/paths.cmake)
    56 #platform specific init code
    68 #platform specific init code
    57 include(${CMAKE_MODULE_PATH}/platform.cmake)
    69 include(${CMAKE_MODULE_PATH}/platform.cmake)
    58 
    70 
    59 
    71 
    60 #when build type is not specified, assume Debug/Release according to build version information
    72 #when build type is not specified, assume Debug/Release according to build version information
    61 if (CMAKE_BUILD_TYPE)
    73 if(CMAKE_BUILD_TYPE)
    62     string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
    74     string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
    63     if ( NOT( (CMAKE_BUILD_TYPE MATCHES "RELEASE") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") ) )
    75     if(NOT((CMAKE_BUILD_TYPE MATCHES "RELEASE") OR
    64         set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE)
    76            (CMAKE_BUILD_TYPE MATCHES "DEBUG") OR
    65         message (STATUS "Unknown build type, using default (${default_build_type})")
    77            (CMAKE_BUILD_TYPE MATCHES "RELWITHDEBINFO")))
    66     endif ()
    78         set(CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release/RelWithDebInfo)" FORCE)
    67 else (CMAKE_BUILD_TYPE)
    79         message(STATUS "Unknown build type ${CMAKE_BUILD_TYPE}, using default (${default_build_type})")
    68     set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE)
    80     endif()
    69 endif (CMAKE_BUILD_TYPE)
    81 else(CMAKE_BUILD_TYPE)
       
    82     set(CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release/RelWithDebInfo)" FORCE)
       
    83 endif(CMAKE_BUILD_TYPE)
    70 
    84 
    71 
    85 
    72 #perform safe check that enable/disable compilation features
    86 #perform safe check that enable/disable compilation features
    73 include(${CMAKE_MODULE_PATH}/compilerchecks.cmake)
    87 include(${CMAKE_MODULE_PATH}/compilerchecks.cmake)
    74 
    88 
    75 #set default compiler flags
    89 #set default compiler flags
    76 add_flag_append(CMAKE_C_FLAGS "-Wall -pipe")
    90 add_flag_append(CMAKE_C_FLAGS "-Wall -pipe")
    77 add_flag_append(CMAKE_C_FLAGS_RELEASE "-Os")
    91 add_flag_append(CMAKE_C_FLAGS_RELEASE "-O2")
    78 add_flag_append(CMAKE_C_FLAGS_DEBUG "-Wextra -O0")
    92 add_flag_append(CMAKE_C_FLAGS_DEBUG "-Wextra -O0")
    79 add_flag_append(CMAKE_CXX_FLAGS "-Wall -pipe")
    93 add_flag_append(CMAKE_CXX_FLAGS "-Wall -pipe")
    80 add_flag_append(CMAKE_CXX_FLAGS_RELEASE "-Os")
    94 add_flag_append(CMAKE_CXX_FLAGS_RELEASE "-O2")
    81 add_flag_append(CMAKE_CXX_FLAGS_DEBUG "-Wextra -O0")
    95 add_flag_append(CMAKE_CXX_FLAGS_DEBUG "-Wextra -O0")
    82 add_flag_append(CMAKE_Pascal_FLAGS "-Cs2000000")
       
    83 add_flag_append(CMAKE_Pascal_FLAGS_DEBUG "-O- -gv")
       
    84 add_flag_append(CMAKE_Pascal_FLAGS_RELEASE "-Os -Xs")
       
    85 
    96 
    86 #CMake adds a lot of additional configuration flags, so let's clear them up
    97 #CMake adds a lot of additional configuration flags, so let's clear them up
    87 if(${MINIMAL_FLAGS})
    98 if(MINIMAL_FLAGS)
    88     unset(CMAKE_C_FLAGS_RELEASE)
    99     unset(CMAKE_C_FLAGS_RELEASE)
    89     unset(CMAKE_C_FLAGS_DEBUG)
   100     unset(CMAKE_C_FLAGS_DEBUG)
    90     unset(CMAKE_CXX_FLAGS_RELEASE)
   101     unset(CMAKE_CXX_FLAGS_RELEASE)
    91     unset(CMAKE_CXX_FLAGS_DEBUG)
   102     unset(CMAKE_CXX_FLAGS_DEBUG)
    92 endif()
   103 endif()
    95 #parse additional parameters
   106 #parse additional parameters
    96 if(GHFLAGS)
   107 if(GHFLAGS)
    97     if(${CMAKE_VERSION} VERSION_GREATER 2.6)
   108     if(${CMAKE_VERSION} VERSION_GREATER 2.6)
    98         separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS})
   109         separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS})
    99     else()
   110     else()
   100         message(${WARNING} "GHFLAGS are available only when using CMake >= 2.8")
   111         message("*** GHFLAGS are available only when using CMake >= 2.8 ***")
   101     endif()
   112     endif()
   102 endif()
   113 endif()
   103 
   114 
   104 list(APPEND haskell_flags ${ghflags_parsed} "-O2")
   115 list(APPEND haskell_flags ${ghflags_parsed} "-O2")
   105 
   116 
   107 message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration")
   118 message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration")
   108 if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
   119 if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
   109     list(APPEND haskell_flags "-Wall"       # all warnings
   120     list(APPEND haskell_flags "-Wall"       # all warnings
   110                               "-debug"      # debug mode
   121                               "-debug"      # debug mode
   111                               "-dcore-lint" # internal sanity check
   122                               "-dcore-lint" # internal sanity check
       
   123                               "-fno-warn-unused-do-bind"
   112                               )
   124                               )
   113 else()
   125 else()
   114     list(APPEND haskell_flags "-w" # no warnings
   126     list(APPEND haskell_flags "-w" # no warnings
   115                               )
   127                               )
   116 endif()
   128 endif()
   117 
   129 
   118 
   130 
       
   131 #build engine without freepascal
       
   132 if(BUILD_ENGINE_C)
       
   133     find_package(Clang REQUIRED)
       
   134 
       
   135     if(${CLANG_VERSION} VERSION_LESS "3.0")
       
   136         message(FATAL_ERROR "LLVM/Clang compiler required version is 3.0 but version ${CLANG_VERSION} was found!")
       
   137     endif()
       
   138 
       
   139     set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE})
       
   140     set(CMAKE_CXX_COMPILER ${CLANG_EXECUTABLE})
       
   141 endif()
       
   142 
       
   143 
       
   144 #server
       
   145 if(NOT NOSERVER)
       
   146     add_subdirectory(gameServer)
       
   147 endif()
       
   148 
       
   149 
   119 #lua discovery
   150 #lua discovery
   120 if (${LUA_SYSTEM})
   151 if(LUA_SYSTEM)
   121     if (NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
   152     if(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
   122         find_package(Lua)
   153         find_package(Lua)
   123     endif()
   154     endif()
   124 
   155 
   125     if (LUA_LIBRARY AND LUA_INCLUDE_DIR)
   156     if(LUA_LIBRARY AND LUA_INCLUDE_DIR)
   126         set(LUA_FOUND TRUE)
       
   127         #use an IMPORTED tharget so that we can just use 'lua' to link
   157         #use an IMPORTED tharget so that we can just use 'lua' to link
   128         add_library(lua UNKNOWN IMPORTED)
   158         add_library(lua UNKNOWN IMPORTED)
   129         set_target_properties(lua PROPERTIES IMPORTED_LOCATION ${LUA_LIBRARY})
   159         set_target_properties(lua PROPERTIES IMPORTED_LOCATION ${LUA_LIBRARY})
   130     else()
   160     else()
   131         message(FATAL_ERROR "Missing Lua! Rerun cmake with -DLUA_SYSTEM=off to build the internal version")
   161         message(FATAL_ERROR "Missing Lua! Rerun cmake with -DLUA_SYSTEM=off to build the internal version")
   132     endif()
   162     endif()
   133 else()
   163 else()
   134     if (NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
   164     if(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
   135         message(STATUS "LUA will be provided by the bundled sources")
   165         message(STATUS "LUA will be provided by the bundled sources")
   136     endif()
   166     endif()
   137     set(lua_output_name "hwlua")
   167     set(lua_output_name "hwlua")
   138     add_subdirectory(misc/liblua)
   168     add_subdirectory(misc/liblua)
   139 endif()
   169 endif()
   140 
   170 
   141 
   171 
   142 #physfs discovery
   172 #physfs discovery
   143 if (${PHYSFS_SYSTEM})
   173 if(PHYSFS_SYSTEM)
   144     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   174     if(NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   145         find_package(PhysFS)
   175         find_package(PhysFS)
   146     endif()
   176     endif()
   147 
   177 
   148     find_file(physfs_h physfs.h ${PHYSFS_INCLUDE_DIR})
   178     find_file(physfs_h physfs.h ${PHYSFS_INCLUDE_DIR})
   149     if(physfs_h)
   179     if(physfs_h)
   153         string(REGEX MATCH "([0-9]+)" physfs_majorversion "${physfs_majorversion}")
   183         string(REGEX MATCH "([0-9]+)" physfs_majorversion "${physfs_majorversion}")
   154         string(REGEX MATCH "([0-9]+)" physfs_minorversion "${physfs_minorversion}")
   184         string(REGEX MATCH "([0-9]+)" physfs_minorversion "${physfs_minorversion}")
   155         string(REGEX MATCH "([0-9]+)" physfs_patchversion "${physfs_patchversion}")
   185         string(REGEX MATCH "([0-9]+)" physfs_patchversion "${physfs_patchversion}")
   156         set(physfs_detected_ver "${physfs_majorversion}.${physfs_minorversion}.${physfs_patchversion}")
   186         set(physfs_detected_ver "${physfs_majorversion}.${physfs_minorversion}.${physfs_patchversion}")
   157 
   187 
   158         if (physfs_detected_ver VERSION_LESS "2.1.0")
   188         if(${physfs_detected_ver} VERSION_LESS 2.0.0)
   159             message(FATAL_ERROR "PhysFS version is too old (dected ${physfs_detected_ver}, required 2.1.0)")
   189             message(FATAL_ERROR "PhysFS version is too old (detected ${physfs_detected_ver}, required 2.0.0)\n"
   160             set(physfs_too_old true)
   190                                 "Perform an update or rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
   161         endif()
   191         endif()
   162     endif()
   192     endif()
   163 
   193 
   164     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   194     if(PHYSFS_LIBRARY AND PHYSFS_INCLUDE_DIR)
   165         message(FATAL_ERROR "Missing PhysFS! Rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
       
   166     else()
       
   167         #use an IMPORTED tharget so that we can just use 'physfs' to link
   195         #use an IMPORTED tharget so that we can just use 'physfs' to link
   168         add_library(physfs UNKNOWN IMPORTED)
   196         add_library(physfs UNKNOWN IMPORTED)
   169         set_target_properties(physfs PROPERTIES IMPORTED_LOCATION ${PHYSFS_LIBRARY})
   197         set_target_properties(physfs PROPERTIES IMPORTED_LOCATION ${PHYSFS_LIBRARY})
   170     endif()
   198     else()
   171 else()
   199         message(FATAL_ERROR "Missing PhysFS! Rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
   172     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   200     endif()
       
   201 else()
       
   202     if(NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   173         message(STATUS "PhysFS will be provided by the bundled sources")
   203         message(STATUS "PhysFS will be provided by the bundled sources")
   174     endif()
   204     endif()
   175     set(physfs_output_name "hwphysfs")
   205     set(physfs_output_name "hwphysfs")
   176     add_subdirectory(misc/libphysfs)
   206     add_subdirectory(misc/libphysfs)
   177 endif()
   207 endif()
   178 
   208 
   179 find_package_or_disable_msg(FFMPEG NOVIDEOREC "Video recording will not be built")
   209 find_package_or_disable_msg(LIBAV NOVIDEOREC "Video recording will not be built")
   180 
   210 
   181 #physfs helper library
   211 #physfs helper library
   182 add_subdirectory(misc/libphyslayer)
   212 add_subdirectory(misc/libphyslayer)
   183 
   213 
   184 #server
   214 #maybe this could be merged inside hedgewars/CMakeLists.txt
   185 if(NOT NOSERVER)
   215 if(BUILD_ENGINE_C)
   186     add_subdirectory(gameServer)
   216     #pascal to c converter
   187 endif()
   217     add_subdirectory(tools/pas2c)
   188 
   218     add_subdirectory(project_files/hwc)
   189 #main engine
   219 else()
   190 add_subdirectory(hedgewars)
   220     #main pascal engine
       
   221     add_subdirectory(hedgewars)
       
   222 endif()
   191 
   223 
   192 #Android related build scripts
   224 #Android related build scripts
       
   225 #TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
   193 if(ANDROID)
   226 if(ANDROID)
   194     #run cmake -DANDROID=1 to enable this
       
   195     add_subdirectory(project_files/Android-build)
   227     add_subdirectory(project_files/Android-build)
   196 endif()
   228 else(ANDROID)
   197 
       
   198 #TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
       
   199 if(NOT ANDROID)
       
   200     add_subdirectory(bin)
   229     add_subdirectory(bin)
   201     add_subdirectory(QTfrontend)
   230     add_subdirectory(QTfrontend)
   202     add_subdirectory(share)
   231     add_subdirectory(share)
   203     add_subdirectory(tools)
   232     add_subdirectory(tools)
   204 endif()
   233 endif(ANDROID)
   205 
       
   206 
   234 
   207 include(${CMAKE_MODULE_PATH}/cpackvars.cmake)
   235 include(${CMAKE_MODULE_PATH}/cpackvars.cmake)
   208 
   236 
       
   237 enable_testing()
       
   238 
       
   239 add_custom_target(test_normal  COMMAND ${CMAKE_CTEST_COMMAND} -E '^todo/' --timeout 300 --schedule-random)
       
   240 add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} -E '^todo/' --timeout 300 --schedule-random -V)
       
   241 
       
   242 set(LUATESTS_DIR "${CMAKE_SOURCE_DIR}/tests/lua")
       
   243 set(TESTSDATA_DIR "${CMAKE_SOURCE_DIR}/share/hedgewars/Data")
       
   244 
       
   245 # set set this to "" if you want to see what's going on
       
   246 # TODO: engine should do this implicitly when running tests,
       
   247 # unless some env var like HWENGINE_SHOWTESTS is set or something
       
   248 set(STATSONLYFLAG "--stats-only")
       
   249 
       
   250 # add all lua tests
       
   251 file(GLOB_RECURSE luatests RELATIVE "${LUATESTS_DIR}" "${LUATESTS_DIR}/*.lua")
       
   252 foreach(luatest ${luatests})
       
   253     add_test("${luatest}" "bin/hwengine" "--prefix" "${TESTSDATA_DIR}" "--nosound" "--nomusic" "${STATSONLYFLAG}" "--lua-test" "${LUATESTS_DIR}/${luatest}")
       
   254 endforeach(luatest)
       
   255