CMakeLists.txt
branchwebgl
changeset 8833 c13ebed437cb
parent 8450 404ddce27b23
parent 8734 ecb0a97100cf
child 9127 e350500c4edb
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
     1 project(hedgewars)
     1 project(hedgewars)
     2 
     2 
     3 #initialise cmake environment
     3 #initialise cmake environment
     4 cmake_minimum_required(VERSION 2.6.0)
     4 cmake_minimum_required(VERSION 2.6.0)
       
     5 if(CMAKE_VERSION VERSION_LESS "2.8")
       
     6     set(WARNING "WARNING: ")
       
     7     set(allow_parse_args FALSE)
       
     8 else()
       
     9     set(WARNING WARNING)
       
    10     set(allow_parse_args TRUE)
       
    11 endif()
     5 foreach(hwpolicy CMP0003 CMP0012 CMP0017)
    12 foreach(hwpolicy CMP0003 CMP0012 CMP0017)
     6     if(POLICY ${hwpolicy})
    13     if(POLICY ${hwpolicy})
     7         cmake_policy(SET ${hwpolicy} NEW)
    14         cmake_policy(SET ${hwpolicy} NEW)
     8     endif()
    15     endif()
     9 endforeach()
    16 endforeach()
    10 #use available modules, fallback to ours if not present (CMP0017 helps)
    17 
    11 set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
    18 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
    12 
    19 
    13 
    20 
    14 #usually this is set at release time
    21 #possible cmake configuration
    15 option(NOREVISION "Build Hedgewars without revision information [default: off]" OFF)
    22 option(NOSERVER "Disable gameServer build (off)]" OFF)
    16 
    23 option(NOPNG "Disable screenshoot compression (off)" OFF)
    17 #set other default values
    24 option(NOVIDEOREC "Disable video recording (off)" OFF)
    18 option(NOSERVER "Disable gameServer build [default: auto]" OFF)
    25 
    19 option(NOPNG "Disable screenshoot compression [default: auto]" OFF)
    26 #set this to ON when 2.1.0 becomes more widespread (and only for linux)
    20 option(NOVIDEOREC "Disable video recording [default: auto]" OFF)
    27 option(SYSTEM_PHYSFS "Use system physfs (off)" OFF)
    21 
    28 
       
    29 option(LIBENGINE "Enable hwengine library (off)" OFF)
       
    30 option(ANDROID "Enable Android build (off)" OFF)
       
    31 
       
    32 if(UNIX AND NOT APPLE)
       
    33     option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF)
       
    34 else()
       
    35     option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
       
    36 endif()
    22 
    37 
    23 option(WEBGL "Enable WebGL build (implies NOPASCAL) [default: off]" OFF)
    38 option(WEBGL "Enable WebGL build (implies NOPASCAL) [default: off]" OFF)
    24 option(NOPASCAL "Compile hwengine as native C [default: off]" ${WEBGL})
    39 option(NOPASCAL "Compile hwengine as native C [default: off]" ${WEBGL})
    25 option(LIBENGINE "Enable hwengine library [default: off]" OFF)
       
    26 
       
    27 option(ANDROID "Enable Android build [default: off]" OFF)
       
    28 option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
       
    29 option(MINIMAL_FLAGS "Respect system flags as much as possible [default: off]" OFF)
       
    30 option(GL2 "Enable OpenGL 2 rendering [default: off]" OFF)
    40 option(GL2 "Enable OpenGL 2 rendering [default: off]" OFF)
       
    41 
    31 set(FPFLAGS "" CACHE STRING "Additional Freepascal flags")
    42 set(FPFLAGS "" CACHE STRING "Additional Freepascal flags")
    32 set(GHFLAGS "" CACHE STRING "Additional Haskell flags")
    43 set(GHFLAGS "" CACHE STRING "Additional Haskell flags")
    33 if(UNIX AND NOT APPLE)
    44 if(UNIX AND NOT APPLE)
    34     set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
    45     set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
    35 endif()
    46 endif()
    36 
    47 
    37 #detect Mercurial revision (if present)
    48 
    38 if(NOT ${NOREVISION})
    49 #detect Mercurial revision and init rev/hash information
       
    50 find_program(HGCOMMAND hg)
       
    51 if(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg))
       
    52     execute_process(COMMAND ${HGCOMMAND} identify -in
       
    53                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
       
    54                     OUTPUT_VARIABLE internal_version
       
    55                     ERROR_QUIET
       
    56                 )
       
    57     #check local repo status
       
    58     string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
       
    59     string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version})
       
    60     string(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" HEDGEWARS_HASH ${internal_version})
       
    61 
       
    62     if(HGCHANGED)
       
    63         message(${WARNING} "You have uncommitted changes in your repository!")
       
    64     endif()
       
    65     #let's assume that if you have hg you might be interested in debugging
    39     set(default_build_type "DEBUG")
    66     set(default_build_type "DEBUG")
    40     set(version_suffix "-development_version")
    67     #write down hash and rev for easy picking should hg be missing
    41     set(HW_DEV true)
    68     file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
    42     find_program(HGCOMMAND hg)
    69 else()
    43     if(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg))
       
    44         execute_process(COMMAND ${HGCOMMAND} identify -in
       
    45                         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
       
    46                         OUTPUT_VARIABLE internal_version
       
    47                         ERROR_QUIET
       
    48                     )
       
    49         #check local repo status
       
    50         string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
       
    51 
       
    52         string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" revision_number ${internal_version})
       
    53         string(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" revision_hash ${internal_version})
       
    54 
       
    55         message(STATUS "Building revision ${revision_number} from hash ${revision_hash} ${HGCHANGED}")
       
    56         if(HGCHANGED)
       
    57             MESSAGE(WARNING "Notice: you have uncommitted changes in your repository")
       
    58         endif()
       
    59         set(version_suffix "-${revision_number}${HGCHANGED}")
       
    60     endif()
       
    61 else(NOT ${NOREVISION})
       
    62     set(default_build_type "RELEASE")
    70     set(default_build_type "RELEASE")
    63     set(HWDEV false)
    71     # when compiling outside rev control, fetch revision and hash information from version_info.txt
    64     message(STATUS "Building distributable version")
    72     find_file(version_info version_info.txt PATH ${CMAKE_SOURCE_DIR}/share)
    65 endif(NOT ${NOREVISION})
    73     if(version_info)
       
    74         file(STRINGS ${version_info} internal_version REGEX "rev")
       
    75         string(REGEX REPLACE "rev ([0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
       
    76         file(STRINGS ${version_info} internal_version REGEX "hash")
       
    77         string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version})
       
    78     else()
       
    79         message(${WARNING} "${CMAKE_SOURCE_DIR}/share/version_info.txt not found, revision information "
       
    80                            "will be incorrect!!! Contact your source provider to fix this!")
       
    81         set(HEDGEWARS_REVISION "0000")
       
    82         set(HEDGEWARS_HASH "unknown")
       
    83     endif()
       
    84 endif()
    66 
    85 
    67 
    86 
    68 #versioning
    87 #versioning
    69 set(CPACK_PACKAGE_VERSION_MAJOR 0)
    88 set(CPACK_PACKAGE_VERSION_MAJOR 0)
    70 set(CPACK_PACKAGE_VERSION_MINOR 9)
    89 set(CPACK_PACKAGE_VERSION_MINOR 9)
    71 set(CPACK_PACKAGE_VERSION_PATCH 19${version_suffix})
    90 set(CPACK_PACKAGE_VERSION_PATCH 19)
    72 set(HEDGEWARS_PROTO_VER 44)
    91 set(HEDGEWARS_PROTO_VER 44)
    73 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
    92 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
    74 set(required_clang_version 3.0)
    93 set(required_clang_version 3.0)
    75 
    94 
       
    95 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
    76 
    96 
    77 if (${NOPASCAL})
    97 if (${NOPASCAL})
    78     find_package(Clang)
    98     find_package(Clang)
    79     # Check LLVM/Clang version
    99     # Check LLVM/Clang version
    80 	if (CLANG_VERSION VERSION_LESS required_clang_version)
   100 	if (CLANG_VERSION VERSION_LESS required_clang_version)
    83 		message(STATUS "Found CLANG: ${CLANG_EXECUTABLE} (version ${CLANG_VERSION})")
   103 		message(STATUS "Found CLANG: ${CLANG_EXECUTABLE} (version ${CLANG_VERSION})")
    84 	endif()
   104 	endif()
    85 endif(${NOPASCAL})
   105 endif(${NOPASCAL})
    86 
   106 
    87 
   107 
       
   108 
       
   109 #where to build libs and bins
    88 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
   110 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
    89 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
   111 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
    90 
   112 
       
   113 #resource paths
    91 if(UNIX AND NOT APPLE)
   114 if(UNIX AND NOT APPLE)
    92     set(target_binary_install_dir "bin")
   115     set(target_binary_install_dir "bin")
    93     set(target_library_install_dir "lib")
   116     set(target_library_install_dir "lib")
    94     set(SHAREPATH "${DATA_INSTALL_DIR}/")
   117 
       
   118     string(SUBSTRING "${DATA_INSTALL_DIR}" 0 1 sharepath_start)
       
   119     if (NOT (${sharepath_start} MATCHES "/"))
       
   120         set(HEDGEWARS_DATADIR "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/")
       
   121     else()
       
   122         set(HEDGEWARS_DATADIR "${DATA_INSTALL_DIR}/")
       
   123     endif()
       
   124     set(HEDGEWARS_FULL_DATADIR "${HEDGEWARS_DATADIR}")
    95 else()
   125 else()
    96     set(target_binary_install_dir "./")
   126     set(target_binary_install_dir "./")
    97 
   127 
    98     if(APPLE)
   128     if(APPLE)
       
   129         set(target_library_install_dir "../Frameworks/")
    99         set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/")
   130         set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/")
   100         set(SHAREPATH "../Resources/")
   131         set(HEDGEWARS_DATADIR "../Resources/")
   101         set(target_library_install_dir "../Frameworks/")
   132         set(HEDGEWARS_FULL_DATADIR "/Applications/${CMAKE_INSTALL_PREFIX}/${HEDGEWARS_DATADIR}")
   102     else()
   133     elseif(WIN32)
   103         if(WIN32)
   134         set(target_library_install_dir "./")
   104             set(target_library_install_dir "./")
   135         set(HEDGEWARS_DATADIR "./")
   105             set(SHAREPATH "./")
   136         set(HEDGEWARS_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/")
   106             set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/misc/winutils/")
   137         link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin")
   107             link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin")
       
   108         endif(WIN32)
       
   109     endif()
   138     endif()
   110 endif()
   139 endif()
   111 
   140 
   112 
   141 
   113 if(APPLE)
   142 if(APPLE)
   125         string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version})
   154         string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version})
   126     else()
   155     else()
   127         if(NOT minimum_macosx_version)
   156         if(NOT minimum_macosx_version)
   128             message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set")
   157             message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set")
   129         else()
   158         else()
   130             message(WARNING "sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable")
   159             message(${WARNING} "sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable")
   131             set(current_macosx_version ${minimum_macosx_version})
   160             set(current_macosx_version ${minimum_macosx_version})
   132         endif()
   161         endif()
   133     endif()
   162     endif()
   134 
   163 
   135     #if nothing is set, we deploy only for the current system
   164     #if nothing is set, we deploy only for the current system
   179 
   208 
   180     #add user framework directory, other paths can be passed via FPFLAGS
   209     #add user framework directory, other paths can be passed via FPFLAGS
   181     list(APPEND pascal_flags "-Ff~/Library/Frameworks")
   210     list(APPEND pascal_flags "-Ff~/Library/Frameworks")
   182     #set deployment target
   211     #set deployment target
   183     list(APPEND pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}")
   212     list(APPEND pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}")
   184 
       
   185     #silly libav that always brings in VideoDecoderAcceleration, avaible only from 10.6.3
       
   186     if(NOT NOVIDEOREC AND ${minimum_macosx_version} VERSION_LESS "10.6")
       
   187         set(WARNING "Video recording support before OS X 10.6 is experimental")
       
   188     endif()
       
   189 endif(APPLE)
   213 endif(APPLE)
   190 
   214 
   191 
   215 
   192 #when build type is not specified, assume Debug/Release according to build version information
   216 #when build type is not specified, assume Debug/Release according to build version information
   193 if (CMAKE_BUILD_TYPE)
   217 if (CMAKE_BUILD_TYPE)
   194     string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
   218     string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
   195     if ( NOT( (CMAKE_BUILD_TYPE MATCHES "RELEASE") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") ) )
   219     if ( NOT( (CMAKE_BUILD_TYPE MATCHES "RELEASE") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") ) )
   196         set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Choose the build type, options are: Debug Release." FORCE)
   220         set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE)
   197         message (STATUS "Unknown build type, using default (${default_build_type})")
   221         message (STATUS "Unknown build type, using default (${default_build_type})")
   198     endif ()
   222     endif ()
   199 else (CMAKE_BUILD_TYPE)
   223 else (CMAKE_BUILD_TYPE)
   200     set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Choose the build type, options are: Debug Release." FORCE)
   224     set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE)
   201 endif (CMAKE_BUILD_TYPE)
   225 endif (CMAKE_BUILD_TYPE)
       
   226 
   202 
   227 
   203 #set default flags values for all projects (unless MINIMAL_FLAGS is true)
   228 #set default flags values for all projects (unless MINIMAL_FLAGS is true)
   204 if(NOT ${MINIMAL_FLAGS})
   229 if(NOT ${MINIMAL_FLAGS})
   205     set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}")
   230     set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}")
   206     set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}")
   231     set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}")
   214     set(CMAKE_C_FLAGS_DEBUG "-Wall -DDEBUG")
   239     set(CMAKE_C_FLAGS_DEBUG "-Wall -DDEBUG")
   215     set(CMAKE_CXX_FLAGS_RELEASE "")
   240     set(CMAKE_CXX_FLAGS_RELEASE "")
   216     set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG")
   241     set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG")
   217 endif()
   242 endif()
   218 
   243 
       
   244 #TODO: find out why we need this...
       
   245 include(CheckCCompilerFlag)
       
   246 set(CMAKE_REQUIRED_FLAGS "-Wl,-z -Wl,noexecstack")
       
   247 check_c_compiler_flag("" HAVE_NOEXECSTACK) #empty because we are testing a linker flag
       
   248 if(HAVE_NOEXECSTACK)
       
   249     list(APPEND pascal_flags "-k-z" "-knoexecstack")
       
   250     if(NOT ${MINIMAL_FLAGS})
       
   251         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
   252     endif()
       
   253 endif()
       
   254 unset(CMAKE_REQUIRED_FLAGS)
       
   255 
   219 #parse additional parameters
   256 #parse additional parameters
   220 if(FPFLAGS OR GHFLAGS)
   257 if(FPFLAGS OR GHFLAGS)
   221     set(cmake_version "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
   258     if(${allow_parse_args})
   222     if(cmake_version VERSION_LESS "2.8")
   259         message(${WARNING} "FPFLAGS and GHFLAGS are available only when using CMake >= 2.8")
   223         message(WARNING "FPFLAGS and GHFLAGS are available only when using CMake >= 2.8")
       
   224     else()
   260     else()
   225         separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS})
   261         separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS})
   226         separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS})
   262         separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS})
   227     endif()
   263     endif()
   228 endif()
   264 endif()
   229 
   265 
   230 list(APPEND pascal_flags ${fpflags_parsed}              # user flags
   266 list(APPEND pascal_flags ${fpflags_parsed}            # user flags
   231                  "-vm4079,4080,4081"            # fpc output format
   267                  "-B"                                 # compile all units
   232                  "-B"                           # compile all units
   268                  "-vm4079,4080,4081"                  # fpc verbosity output format
   233                  "-FE${PROJECT_BINARY_DIR}/bin" # fpc output directory
   269                  "-FE${PROJECT_BINARY_DIR}/bin"       # fpc binaries output directory
   234                  "-Fl${PROJECT_BINARY_DIR}/bin" # fpc linking directory
   270                  "-FU${PROJECT_BINARY_DIR}/hedgewars" # fpc units output directory
   235                  "-Cs2000000"                   # stack size
   271                  "-Fl${PROJECT_BINARY_DIR}/bin"       # fpc linking directory (win/unix)
   236                  "-vewnq"                       # fpc output verbosity
   272                  "-Fi${PROJECT_BINARY_DIR}/hedgewars" # fpc .inc path (for out of source builds)
   237                  "-dDEBUGFILE"                  # macro for engine output
   273                  "-k-L${PROJECT_BINARY_DIR}/bin"      # ld linking directory (unix/osx)
       
   274                  "-Cs2000000"                         # stack size
       
   275                  "-vewnq"                             # fpc output verbosity
       
   276                  "-dDEBUGFILE"                        # macro for engine output
   238                  )
   277                  )
   239 list(APPEND haskell_flags "-O2" ${ghflags_parsed})
   278 list(APPEND haskell_flags ${ghflags_parsed} # user flags
       
   279                  "-O2"                      # optimise for faster code
       
   280                  )
       
   281 
   240 
   282 
   241 #get BUILD_TYPE and enable/disable optimisation
   283 #get BUILD_TYPE and enable/disable optimisation
   242 message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration")
   284 message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration")
   243 if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
   285 if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
   244     list(APPEND pascal_flags "-O-" "-g" "-gl" "-gv")
   286     list(APPEND pascal_flags "-O-" # disable all optimisations
   245     list(APPEND haskell_flags "-Wall" "-debug" "-dcore-lint" "-fno-warn-unused-do-bind")
   287                              "-g"  # enable debug symbols
   246 else()
   288                              "-gl" # add line info to bt
   247 #    set(pascal_flags "-O3" "-OpPENTIUM4" "-CfSSE3" "-Xs" "-Si" ${pascal_flags})
   289                              "-gv" # allow valgrind
   248     list(APPEND pascal_flags "-Os" "-Xs" "-Si")
   290                              )
   249     list(APPEND haskell_flags "-w" "-fno-warn-unused-do-bind")
   291     list(APPEND haskell_flags "-Wall"       # all warnings
   250 endif()
   292                               "-debug"      # debug mode
   251 
   293                               "-dcore-lint" # internal sanity check
       
   294                               )
       
   295 else()
       
   296     list(APPEND pascal_flags "-Os" # optimise for size
       
   297                              "-Xs" # strip binary
       
   298                              "-Si" # turn on inlining
       
   299                              )
       
   300     list(APPEND haskell_flags "-w" # no warnings
       
   301                               )
       
   302 endif()
       
   303 
       
   304 include(${CMAKE_MODULE_PATH}/utils.cmake)
   252 
   305 
   253 #Haskell compiler discovery (for server and engine in c)
   306 #Haskell compiler discovery (for server and engine in c)
   254 if((NOT NOSERVER) OR NOPASCAL)
   307 if((NOT NOSERVER) OR NOPASCAL)
   255     if(GHC)
   308     if(GHC)
   256         set(ghc_executable ${GHC})
   309         set(ghc_executable ${GHC})
   288     #linking with liblua.a requires system readline
   341     #linking with liblua.a requires system readline
   289     list(APPEND pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline")
   342     list(APPEND pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline")
   290 endif()
   343 endif()
   291 
   344 
   292 
   345 
   293 #physfs library (static on unix, dll on win32)
   346 #physfs discovery
   294 add_subdirectory(misc/physfs)
   347 if (${SYSTEM_PHYSFS})
   295 if(NOT WIN32)
   348     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   296     list(APPEND pascal_flags "-k${LIBRARY_OUTPUT_PATH}/libphysfs.a")
   349         find_package(PhysFS)
   297 endif()
   350     endif()
   298 
   351 
   299 
   352     find_file(physfs_h physfs.h ${PHYSFS_INCLUDE_DIR})
   300 #frontend library
   353     if(physfs_h)
   301 add_subdirectory(project_files/frontlib)
   354         file(STRINGS ${physfs_h} physfs_majorversion REGEX "PHYSFS_VER_MAJOR[\t' ']+[0-9]+")
   302 
   355         file(STRINGS ${physfs_h} physfs_minorversion REGEX "PHYSFS_VER_MINOR[\t' ']+[0-9]+")
       
   356         file(STRINGS ${physfs_h} physfs_patchversion REGEX "PHYSFS_VER_PATCH[\t' ']+[0-9]+")
       
   357         string(REGEX MATCH "([0-9]+)" physfs_majorversion "${physfs_majorversion}")
       
   358         string(REGEX MATCH "([0-9]+)" physfs_minorversion "${physfs_minorversion}")
       
   359         string(REGEX MATCH "([0-9]+)" physfs_patchversion "${physfs_patchversion}")
       
   360         set(physfs_detected_ver "${physfs_majorversion}.${physfs_minorversion}.${physfs_patchversion}")
       
   361 
       
   362         if (physfs_detected_ver VERSION_LESS "2.1.0")
       
   363             message(FATAL_ERROR "PhysFS version is too old (dected ${physfs_detected_ver}, required 2.1.0)")
       
   364             set(physfs_too_old true)
       
   365         endif()
       
   366     endif()
       
   367 
       
   368     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
       
   369         message(FATAL_ERROR "Missing PhysFS! Rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
       
   370     endif()
       
   371 else()
       
   372     message(STATUS "PhysFS will be provided by the bundled sources")
       
   373     set(physfs_output_name "hw_physfs")
       
   374     add_subdirectory(misc/libphysfs)
       
   375     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
       
   376     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
       
   377     #(should be harmless on other platforms)
       
   378     list(APPEND pascal_flags "-XLAphysfs=${physfs_output_name}" "-dPHYSFS_INTERNAL")
       
   379 endif()
       
   380 
       
   381 find_package_or_disable_msg(FFMPEG NOVIDEOREC "Video recording will not be built")
       
   382 
       
   383 #physfs helper library
       
   384 add_subdirectory(misc/libphyslayer)
   303 
   385 
   304 if(NOPASCAL)
   386 if(NOPASCAL)
   305     if (NOT ghc_executable)
   387     if (NOT ghc_executable)
   306         message(FATAL_ERROR "A Haskell compiler is required to build engine in C")
   388         message(FATAL_ERROR "A Haskell compiler is required to build engine in C")
   307     endif()
   389     endif()
   315 
   397 
   316 if(WEBGL)
   398 if(WEBGL)
   317     #WEBGL deps
   399     #WEBGL deps
   318 else(WEBGL)
   400 else(WEBGL)
   319     #Android related build scripts
   401     #Android related build scripts
       
   402     #TODO: when ANDROID, LIBENGINE should be set
   320     if(ANDROID)
   403     if(ANDROID)
   321         add_subdirectory(project_files/Android-build)
   404         add_subdirectory(project_files/Android-build)
   322     endif()
   405     else(ANDROID)
   323 
       
   324     #TODO: when ANDROID, LIBENGINE should be set
       
   325     if(NOT ANDROID)
       
   326         add_subdirectory(bin)
   406         add_subdirectory(bin)
   327         add_subdirectory(QTfrontend)
   407         add_subdirectory(QTfrontend)
   328         add_subdirectory(share)
   408         add_subdirectory(share)
   329         add_subdirectory(tools)
   409         add_subdirectory(tools)
   330     endif()
   410     endif(ANDROID)
   331 endif(WEBGL)
   411 endif(WEBGL)
   332 
   412 
   333 
   413 include(${CMAKE_MODULE_PATH}/CPackConfig.cmake)
   334 
   414 
   335 # CPack variables
       
   336 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hedgewars, a free turn-based strategy")
       
   337 set(CPACK_PACKAGE_VENDOR "Hedgewars Project")
       
   338 set(CPACK_PACKAGE_FILE_NAME "hedgewars-${HEDGEWARS_VERSION}")
       
   339 set(CPACK_SOURCE_PACKAGE_FILE_NAME "hedgewars-src-${HEDGEWARS_VERSION}")
       
   340 set(CPACK_SOURCE_GENERATOR "TBZ2")
       
   341 set(CPACK_PACKAGE_EXECUTABLES "hedgewars" "hedgewars")
       
   342 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
       
   343 set(CPACK_PACKAGE_INSTALL_DIRECTORY "Hedgewars ${HEDGEWARS_VERSION}")
       
   344 
       
   345 if(WIN32 AND NOT UNIX)
       
   346     set(CPACK_NSIS_DISPLAY_NAME "Hedgewars")
       
   347     set(CPACK_NSIS_HELP_LINK "http://www.hedgewars.org/")
       
   348     set(CPACK_NSIS_URL_INFO_ABOUT "http://www.hedgewars.org/")
       
   349     set(CPACK_NSIS_CONTACT "unC0Rr@gmail.com")
       
   350     set(CPACK_NSIS_MODIFY_PATH OFF)
       
   351     set(CPACK_NSIS_EXECUTABLES_DIRECTORY "${target_binary_install_dir}")
       
   352     set(CPACK_GENERATOR "ZIP;NSIS")
       
   353     set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "hedgewars")
       
   354 else(WIN32 AND NOT UNIX)
       
   355     set(CPACK_STRIP_FILES "bin/hedgewars;bin/hwengine")
       
   356 endif(WIN32 AND NOT UNIX)
       
   357 
       
   358 set(CPACK_SOURCE_IGNORE_FILES
       
   359     "~"
       
   360     "\\\\.hg"
       
   361     "\\\\.svn"
       
   362     "\\\\.exe$"
       
   363     "\\\\.a$"
       
   364     "\\\\.dll$"
       
   365     "\\\\.xcf$"
       
   366     "\\\\.cxx$"
       
   367     "\\\\.db$"
       
   368     "\\\\.dof$"
       
   369     "\\\\.layout$"
       
   370     "\\\\.zip$"
       
   371     "\\\\.gz$"
       
   372     "\\\\.bz2$"
       
   373     "\\\\.tmp$"
       
   374     "\\\\.core$"
       
   375     "\\\\.sh$"
       
   376     "\\\\.sifz$"
       
   377     "\\\\.svg$"
       
   378     "\\\\.svgz$"
       
   379     "\\\\.ppu$"
       
   380     "\\\\.psd$"
       
   381     "\\\\.o$"
       
   382     "Makefile"
       
   383     "Doxyfile"
       
   384     "CMakeFiles"
       
   385     "debug"
       
   386     "release$"
       
   387     "Debug$"
       
   388     "Release$"
       
   389     "proto\\\\.inc$"
       
   390     "hwconsts\\\\.cpp$"
       
   391     "playlist\\\\.inc$"
       
   392     "CPack"
       
   393     "cmake_install\\\\.cmake$"
       
   394     "config\\\\.inc$"
       
   395     "hwengine\\\\.desktop$"
       
   396     "CMakeCache\\\\.txt$"
       
   397 #    "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge"
       
   398 #    "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libfreetype"
       
   399     "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua"
       
   400 #    "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libtremor"
       
   401     "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/HedgewarsMobile/"
       
   402     "^${CMAKE_CURRENT_SOURCE_DIR}/bin/[a-z]"
       
   403     "^${CMAKE_CURRENT_SOURCE_DIR}/tools/templates"
       
   404     "^${CMAKE_CURRENT_SOURCE_DIR}/doc"
       
   405     "^${CMAKE_CURRENT_SOURCE_DIR}/templates"
       
   406     "^${CMAKE_CURRENT_SOURCE_DIR}/Graphics"
       
   407     "^${CMAKE_CURRENT_SOURCE_DIR}/realtest"
       
   408     "^${CMAKE_CURRENT_SOURCE_DIR}/tmp"
       
   409     "^${CMAKE_CURRENT_SOURCE_DIR}/utils"
       
   410     "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Maps/test"
       
   411     "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Themes/ethereal"
       
   412     "^${CMAKE_CURRENT_SOURCE_DIR}/install_manifest.txt"
       
   413     "^${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt"
       
   414     "^${CMAKE_CURRENT_SOURCE_DIR}/hedgewars\\\\."
       
   415 )
       
   416 
       
   417 include(CPack)
       
   418