CMakeLists.txt
branchwebgl
changeset 8096 453917e94e55
parent 8044 796f2653f21d
parent 8093 2286a39140da
child 8102 20ef5bf0dc7f
equal deleted inserted replaced
8053:2e836bebb518 8096:453917e94e55
     1 project(hedgewars)
     1 project(hedgewars)
     2 
       
     3 
     2 
     4 #initialise cmake environment
     3 #initialise cmake environment
     5 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
     4 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
     6 FOREACH(policy CMP0003 CMP0012)
     5 cmake_policy(VERSION 2.6)
     7     IF(POLICY ${policy})
     6 FOREACH(hwpolicy CMP0003 CMP0012 CMP0017)
     8         CMAKE_POLICY(SET ${policy} NEW)
     7     IF(POLICY ${hwpolicy})
       
     8         CMAKE_POLICY(SET ${hwpolicy} NEW)
     9     ENDIF()
     9     ENDIF()
    10 ENDFOREACH()
    10 ENDFOREACH()
    11 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
    11 #use available modules, fallback to ours if not present (CMP0017 helps)
       
    12 set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
       
    13 
       
    14 #set some default values
       
    15 option(NOREVISION "Build Hedgewars without revision information" OFF)
       
    16 
       
    17 option(NOSERVER "Disable gameServer build [default: auto]" OFF)
       
    18 option(NOPNG "Disable screenshoot compression [default: auto]" OFF)
       
    19 option(NOVIDEOREC "Disable video recording [default: auto]" OFF)
       
    20 
       
    21 
       
    22 option(WEBGL "Enable WebGL build (implies NOPASCAL) [default: off]" OFF)
       
    23 option(NOPASCAL "Compile hwengine as native C [default: off]" ${WEBGL})
       
    24 option(LIBENGINE "Enable hwengine library [default: off]" OFF)
       
    25 
       
    26 option(ANDROID "Enable Android build [default: off]" OFF)
       
    27 option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
       
    28 option(CROSSAPPLE "Enable OSX when not on OSX [default: off]" OFF)
       
    29 option(MINIMAL_FLAGS "Respect system flags as much as possible [default: off]" OFF)
       
    30 
    12 
    31 
    13 #detect Mercurial revision (if present)
    32 #detect Mercurial revision (if present)
    14 set(version_suffix "-dev") #UNSET THIS VARIABLE AT RELEASE TIME
    33 IF(NOT NOREVISION)
    15 set(HGCHANGED "")
    34     set(default_build_type "DEBUG")
    16 IF(version_suffix MATCHES "-dev")
    35     set(version_suffix "-development_version")
    17     set(HW_DEV true)
    36     set(HW_DEV true)
    18     set(default_build_type "DEBUG")
    37     FIND_PROGRAM(HGCOMMAND hg)
    19     IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.hg)
    38     IF(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg))
    20         FIND_PROGRAM(HGCOMMAND hg)
    39         execute_process(COMMAND ${HGCOMMAND} identify -in
    21         IF(HGCOMMAND)
    40                         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    22             exec_program(${HGCOMMAND}
    41                         OUTPUT_VARIABLE internal_version
    23                      ARGS identify -in ${CMAKE_CURRENT_SOURCE_DIR}
    42                         ERROR_QUIET
    24                      OUTPUT_VARIABLE version_suffix
    43                     )
    25                      )
    44         #check local repo status
    26             STRING(REGEX REPLACE "[^+]" "" HGCHANGED ${version_suffix})
    45         STRING(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
    27             STRING(REGEX REPLACE "([0-9a-zA-Z]+)(.*) ([0-9]+)(.*)" "\\3-\\1" version_suffix ${version_suffix})
    46 
    28             IF (HGCHANGED)
    47         STRING(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" revision_number ${internal_version})
    29                 MESSAGE(STATUS "Building revision ${version_suffix} (SOURCE CODE MODIFIED)")
    48         STRING(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" revision_hash ${internal_version})
    30             ELSE()
    49 
    31                 MESSAGE(STATUS "Building revision ${version_suffix}")
    50         MESSAGE(STATUS "Building revision ${revision_number} from hash ${revision_hash} ${HGCHANGED}")
    32             ENDIF()
    51         IF(HGCHANGED)
    33             set(version_suffix "-${version_suffix}")
    52             MESSAGE(WARNING "Notice: you have uncommitted changes in your repository")
    34         ENDIF()
    53         ENDIF()
       
    54         set(version_suffix "-${revision_number}${HGCHANGED}")
    35     ENDIF()
    55     ENDIF()
    36 ELSE()
    56 ELSE(NOT NOREVISION)
    37     set(HW_DEV false)
       
    38     set(default_build_type "RELEASE")
    57     set(default_build_type "RELEASE")
    39 ENDIF()
    58     set(HWDEV false)
       
    59     MESSAGE(STATUS "Building distributable version")
       
    60 ENDIF(NOT NOREVISION)
    40 
    61 
    41 
    62 
    42 #versioning
    63 #versioning
    43 set(CPACK_PACKAGE_VERSION_MAJOR 0)
    64 set(CPACK_PACKAGE_VERSION_MAJOR 0)
    44 set(CPACK_PACKAGE_VERSION_MINOR 9)
    65 set(CPACK_PACKAGE_VERSION_MINOR 9)
    45 set(CPACK_PACKAGE_VERSION_PATCH 19${version_suffix})
    66 set(CPACK_PACKAGE_VERSION_PATCH 19${version_suffix})
    46 set(HEDGEWARS_PROTO_VER 44)
    67 set(HEDGEWARS_PROTO_VER 44)
    47 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
    68 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
    48 
    69 
    49 
       
    50 #set some default values
       
    51 option(NOSERVER "Disable gameServer build [default: auto]" OFF)
       
    52 option(NOPNG "Disable screenshoot compression [default: auto]" OFF)
       
    53 option(NOVIDEOREC "Disable video recording [default: auto]" OFF)
       
    54 
       
    55 option(ANDROID "Enable Android build [default: off]" OFF)
       
    56 option(WEBGL "Enable WebGL build (implies NOPASCAL) [default: off]" OFF)
       
    57 option(LIBENGINE "Enable hwengine library [default: off]" OFF)
       
    58 
       
    59 option(NOPASCAL "Compile hwengine as native C [default: off]" ${WEBGL})
       
    60 option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
       
    61 option(CROSSAPPLE "Enable OSX when not on OSX [default: off]" OFF)
       
    62 option(MINIMAL_FLAGS "Respect system flags as much as possible [default: off]" OFF)
       
    63 
    70 
    64 #bundle .app setup
    71 #bundle .app setup
    65 if(APPLE OR CROSSAPPLE)
    72 if(APPLE OR CROSSAPPLE)
    66     #paths for creating the bundle
    73     #paths for creating the bundle
    67     set(bundle_name Hedgewars.app)
    74     set(bundle_name Hedgewars.app)
    81     set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET})
    88     set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET})
    82 
    89 
    83     #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version
    90     #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version
    84     find_program(sw_vers sw_vers)
    91     find_program(sw_vers sw_vers)
    85     if(sw_vers)
    92     if(sw_vers)
    86         exec_program(${sw_vers} ARGS "-productVersion" OUTPUT_VARIABLE current_macosx_version)
    93         execute_process(COMMAND ${sw_vers} "-productVersion"
       
    94                         OUTPUT_VARIABLE current_macosx_version
       
    95                         OUTPUT_STRIP_TRAILING_WHITESPACE)
    87         string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version})
    96         string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version})
    88         else()
    97     else()
    89         if(NOT minimum_macosx_version)
    98         if(NOT minimum_macosx_version)
    90             message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set")
    99             message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set")
    91         else()
   100         else()
       
   101             message(WARNING "sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable")
    92             set(current_macosx_version ${minimum_macosx_version})
   102             set(current_macosx_version ${minimum_macosx_version})
    93         endif()
   103         endif()
    94     endif()
   104     endif()
    95 
   105 
    96     #if nothing is set, we deploy only for the current system
   106     #if nothing is set, we deploy only for the current system
    97     if(NOT minimum_macosx_version)
   107     if(NOT minimum_macosx_version)
    98         set(minimum_macosx_version ${current_macosx_version})
   108         set(minimum_macosx_version ${current_macosx_version})
    99     endif()
   109     endif()
   100 
   110 
   101     #lower systems don't have enough processing power anyways
   111     #lower systems don't have enough processing power anyway
   102     if (minimum_macosx_version LESS "10.4")
   112     if (minimum_macosx_version LESS "10.4")
   103         message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4")
   113         message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4")
   104     endif()
   114     endif()
   105 
   115 
   106     #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2)
   116     #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2)
   141     #add user framework directory, other paths can be passed via FPFLAGS
   151     #add user framework directory, other paths can be passed via FPFLAGS
   142     set(pascal_flags "-Ff~/Library/Frameworks" ${pascal_flags})
   152     set(pascal_flags "-Ff~/Library/Frameworks" ${pascal_flags})
   143     #set deployment target
   153     #set deployment target
   144     set(pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}" ${pascal_flags})
   154     set(pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}" ${pascal_flags})
   145 
   155 
   146     message(STATUS "Build system: Mac OS X ${current_macosx_version} with GCC:${CMAKE_C_COMPILER}")
   156     message(STATUS "Build system: Mac OS X ${current_macosx_version} with C compiler: ${CMAKE_C_COMPILER}")
   147     message(STATUS "Target system: Mac OS X ${minimum_macosx_version} for architecture(s):${CMAKE_OSX_ARCHITECTURES}")
   157     message(STATUS "Target system: Mac OS X ${minimum_macosx_version} for architecture(s): ${CMAKE_OSX_ARCHITECTURES}")
   148 endif(APPLE)
   158 endif(APPLE)
   149 
   159 
   150 
   160 
   151 #when build type is not specified, assume Debug/Release according to build version information
   161 #when build type is not specified, assume Debug/Release according to build version information
   152 if (CMAKE_BUILD_TYPE)
   162 if (CMAKE_BUILD_TYPE)
   208 else()
   218 else()
   209     set(SHAREPATH share/hedgewars/)
   219     set(SHAREPATH share/hedgewars/)
   210 endif()
   220 endif()
   211 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
   221 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
   212 set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
   222 set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
       
   223 if(WIN32)
       
   224     set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/misc/winutils/")
       
   225     link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin")
       
   226 endif(WIN32)
   213 
   227 
   214 
   228 
   215 #Haskell compiler discovery (for server and engine in c)
   229 #Haskell compiler discovery (for server and engine in c)
   216 if((NOT NOSERVER) OR NOPASCAL)
   230 if((NOT NOSERVER) OR NOPASCAL)
   217     if(GHC)
   231     if(GHC)
   245 if(LUA_FOUND AND (NOT WEBGL))
   259 if(LUA_FOUND AND (NOT WEBGL))
   246     message(STATUS "Found LUA: ${LUA_DEFAULT}")
   260     message(STATUS "Found LUA: ${LUA_DEFAULT}")
   247 else()
   261 else()
   248     message(STATUS "Using internal LUA library")
   262     message(STATUS "Using internal LUA library")
   249     add_subdirectory(misc/liblua)
   263     add_subdirectory(misc/liblua)
   250     #linking with liblua.a requires system readline -- this works everywhere, right?
   264     #linking with liblua.a requires system readline
   251     set(pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline" ${pascal_flags})
   265     set(pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline" ${pascal_flags})
   252 endif()
   266 endif()
       
   267 
       
   268 
       
   269 #physfs library
       
   270 add_subdirectory(misc/physfs)
       
   271 
       
   272 #frontend library
       
   273 add_subdirectory(project_files/frontlib)
   253 
   274 
   254 
   275 
   255 if(NOPASCAL)
   276 if(NOPASCAL)
   256     if (NOT ghc_executable)
   277     if (NOT ghc_executable)
   257         message(FATAL_ERROR "A Haskell compiler is required to build engine in C")
   278         message(FATAL_ERROR "A Haskell compiler is required to build engine in C")
   264     add_subdirectory(hedgewars)
   285     add_subdirectory(hedgewars)
   265 endif()
   286 endif()
   266 
   287 
   267 if(WEBGL)
   288 if(WEBGL)
   268     #WEBGL deps
   289     #WEBGL deps
   269 else()
   290 else(WEBGL)
   270     #Android related build scripts
   291     #Android related build scripts
   271     if(ANDROID)
   292     if(ANDROID)
   272         add_subdirectory(project_files/Android-build)
   293         add_subdirectory(project_files/Android-build)
   273     endif()
   294     endif()
   274 
   295 
   275     #TODO: when ANDROID, LIBENGINE should be set
   296     #TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
   276     if(NOT (LIBENGINE OR ANDROID))
   297     if(NOT ANDROID)
   277         add_subdirectory(bin)
   298         add_subdirectory(bin)
   278         add_subdirectory(misc/quazip)
       
   279         add_subdirectory(QTfrontend)
   299         add_subdirectory(QTfrontend)
   280         add_subdirectory(share)
   300         add_subdirectory(share)
   281         add_subdirectory(tools)
   301         add_subdirectory(tools)
   282     endif()
   302     endif()
   283 endif()
   303 endif(WEBGL)
   284 
   304 
   285 
   305 
   286 
   306 
   287 # CPack variables
   307 # CPack variables
   288 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hedgewars, a free turn-based strategy")
   308 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hedgewars, a free turn-based strategy")