CMakeLists.txt
branchwebgl
changeset 9236 ddd675825672
parent 9197 e4e366013e9a
parent 9233 a6ae0286787c
child 9238 84e591af6c29
equal deleted inserted replaced
9201:bcf2f7798ebb 9236:ddd675825672
     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.4)
     5 foreach(hwpolicy CMP0003 CMP0012 CMP0017 CMP0018)
     5 foreach(hwpolicy CMP0003 CMP0012 CMP0017 CMP0018)
     6     if(POLICY ${hwpolicy})
     6     if(POLICY ${hwpolicy})
     7         cmake_policy(SET ${hwpolicy} NEW)
     7         cmake_policy(SET ${hwpolicy} NEW)
     8     endif()
     8     endif()
     9 endforeach()
     9 endforeach()
    10 
    10 
    11 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
    11 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
    12 
    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
       
    20 option(BUILD_SHARED_LIBS "Build libraries as shared modules (on)" ON)
    19 #set this to ON when 2.1.0 becomes more widespread (and only for linux)
    21 #set this to ON when 2.1.0 becomes more widespread (and only for linux)
    20 option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
    22 option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
    21 
    23 
    22 option(LIBENGINE "Enable hwengine library (off)" OFF)
    24 if(WIN32 OR APPLE)
       
    25     option(LUA_SYSTEM "Use system lua (off)" OFF)
       
    26 else()
       
    27     option(LUA_SYSTEM "Use system lua (on)" ON)
       
    28 endif()
       
    29 
       
    30 option(BUILD_ENGINE_LIBRARY "Enable hwengine library (off)" OFF)
    23 option(ANDROID "Enable Android build (off)" OFF)
    31 option(ANDROID "Enable Android build (off)" OFF)
    24 
    32 
    25 if(UNIX AND NOT APPLE)
    33 if(UNIX AND NOT APPLE)
    26     option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF)
    34     option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF)
    27 else()
    35 else()
    48 include(${CMAKE_MODULE_PATH}/revinfo.cmake)
    56 include(${CMAKE_MODULE_PATH}/revinfo.cmake)
    49 set(required_clang_version 3.0)
    57 set(required_clang_version 3.0)
    50 
    58 
    51 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
    59 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
    52 
    60 
    53 if (${NOPASCAL})
    61 #general utilities
    54     find_package(Clang)
    62 include(${CMAKE_MODULE_PATH}/utils.cmake)
    55     # Check LLVM/Clang version
       
    56 	if (CLANG_VERSION VERSION_LESS required_clang_version)
       
    57 		message(FATAL_ERROR "LLVM/Clang compiler required version is ${required_clang_version} but version ${CLANG_VERSION} was found!")
       
    58 	else()
       
    59 		message(STATUS "Found CLANG: ${CLANG_EXECUTABLE} (version ${CLANG_VERSION})")
       
    60 	endif()
       
    61 endif(${NOPASCAL})
       
    62 
       
    63 
       
    64 
       
    65 #where to build libs and bins
       
    66 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
       
    67 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
       
    68 
       
    69 #resource paths
       
    70 if(UNIX AND NOT APPLE)
       
    71     set(target_binary_install_dir "bin")
       
    72     set(target_library_install_dir "lib")
       
    73 
       
    74     string(SUBSTRING "${DATA_INSTALL_DIR}" 0 1 sharepath_start)
       
    75     if (NOT (${sharepath_start} MATCHES "/"))
       
    76         set(HEDGEWARS_DATADIR "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/")
       
    77     else()
       
    78         set(HEDGEWARS_DATADIR "${DATA_INSTALL_DIR}/")
       
    79     endif()
       
    80     set(HEDGEWARS_FULL_DATADIR "${HEDGEWARS_DATADIR}")
       
    81 else()
       
    82     set(target_binary_install_dir "./")
       
    83 
       
    84     if(APPLE)
       
    85         set(target_library_install_dir "../Frameworks/")
       
    86         set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/")
       
    87         set(HEDGEWARS_DATADIR "../Resources/")
       
    88         set(HEDGEWARS_FULL_DATADIR "/Applications/${CMAKE_INSTALL_PREFIX}/${HEDGEWARS_DATADIR}")
       
    89     elseif(WIN32)
       
    90         set(target_library_install_dir "./")
       
    91         set(HEDGEWARS_DATADIR "./")
       
    92         set(HEDGEWARS_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/")
       
    93         link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin")
       
    94     endif()
       
    95 endif()
       
    96 
       
    97 #platform specific init code
    63 #platform specific init code
    98 include(${CMAKE_MODULE_PATH}/platform.cmake)
    64 include(${CMAKE_MODULE_PATH}/platform.cmake)
       
    65 include(${CMAKE_MODULE_PATH}/paths.cmake)
    99 
    66 
   100 
    67 
   101 #when build type is not specified, assume Debug/Release according to build version information
    68 #when build type is not specified, assume Debug/Release according to build version information
   102 if (CMAKE_BUILD_TYPE)
    69 if (CMAKE_BUILD_TYPE)
   103     string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
    70     string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
   115 
    82 
   116 #set default flags values for all projects (unless MINIMAL_FLAGS is true)
    83 #set default flags values for all projects (unless MINIMAL_FLAGS is true)
   117 if(NOT ${MINIMAL_FLAGS})
    84 if(NOT ${MINIMAL_FLAGS})
   118     set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}")
    85     set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}")
   119     set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}")
    86     set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}")
   120     set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g -DDEBUG ${CMAKE_C_FLAGS_DEBUG}")
    87     set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g ${CMAKE_C_FLAGS_DEBUG}")
   121     set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
    88     set(CMAKE_CXX_FLAGS "-pipe ${CMAKE_CXX_FLAGS}")
   122     set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
    89     set(CMAKE_CXX_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_CXX_FLAGS_RELEASE}")
   123     set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
    90     set(CMAKE_CXX_FLAGS_DEBUG "-Wall -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}")
   124 else()
    91 else()
   125     #CMake adds a lot of additional configuration flags, so let's clear them up
    92     #CMake adds a lot of additional configuration flags, so let's clear them up
   126     set(CMAKE_C_FLAGS_RELEASE "")
    93     set(CMAKE_C_FLAGS_RELEASE "")
   127     set(CMAKE_C_FLAGS_DEBUG "-Wall -DDEBUG")
    94     set(CMAKE_C_FLAGS_DEBUG "-Wall")
   128     set(CMAKE_CXX_FLAGS_RELEASE "")
    95     set(CMAKE_CXX_FLAGS_RELEASE "")
   129     set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG")
    96     set(CMAKE_CXX_FLAGS_DEBUG "-Wall")
   130 endif()
    97 endif()
   131 
    98 
   132 #parse additional parameters
    99 #parse additional parameters
   133 if(FPFLAGS OR GHFLAGS)
   100 if(FPFLAGS)
   134     if(CMAKE_VERSION VERSION_GREATER "2.6")
   101     add_flag_prepend(CMAKE_Pascal_FLAGS ${FPFLAGS})
   135         separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS})
   102 endif()
       
   103 if(GHFLAGS)
       
   104     if(${allow_parse_args})
   136         separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS})
   105         separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS})
   137     else()
   106     else()
   138         message("*** FPFLAGS and GHFLAGS are available only when using CMake >= 2.8 ***")
   107         message(${WARNING} "FPFLAGS and GHFLAGS are available only when using CMake >= 2.8")
   139     endif()
   108     endif()
   140 endif()
   109 endif()
   141 
   110 
   142 list(APPEND pascal_flags ${fpflags_parsed}            # user flags
   111 
   143                  "-B"                                 # compile all units
       
   144                  "-vm4079,4080,4081"                  # fpc verbosity output format
       
   145                  "-FE${PROJECT_BINARY_DIR}/bin"       # fpc binaries output directory
       
   146                  "-FU${PROJECT_BINARY_DIR}/hedgewars" # fpc units output directory
       
   147                  "-Fl${PROJECT_BINARY_DIR}/bin"       # fpc linking directory (win/unix)
       
   148                  "-Fi${PROJECT_BINARY_DIR}/hedgewars" # fpc .inc path (for out of source builds)
       
   149                  "-k-L${PROJECT_BINARY_DIR}/bin"      # ld linking directory (unix/osx)
       
   150                  "-Cs2000000"                         # stack size
       
   151                  "-vewnq"                             # fpc output verbosity
       
   152                  "-dDEBUGFILE"                        # macro for engine output
       
   153                  )
       
   154 list(APPEND haskell_flags ${ghflags_parsed} # user flags
   112 list(APPEND haskell_flags ${ghflags_parsed} # user flags
   155                  "-O2"                      # optimise for faster code
   113                  "-O2"                      # optimise for faster code
   156                  )
   114                  )
   157 
   115 
       
   116 #-vm4079,4080,4081
       
   117 add_flag_append(CMAKE_Pascal_FLAGS "-Cs2000000")
       
   118 add_flag_append(CMAKE_Pascal_FLAGS_DEBUG "-O- -gv")
       
   119 add_flag_append(CMAKE_Pascal_FLAGS_RELEASE "-Os -Xs")
   158 
   120 
   159 #get BUILD_TYPE and enable/disable optimisation
   121 #get BUILD_TYPE and enable/disable optimisation
   160 message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration")
   122 message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration")
   161 if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
   123 if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
   162     list(APPEND pascal_flags "-O-" # disable all optimisations
       
   163                              "-g"  # enable debug symbols
       
   164                              "-gl" # add line info to bt
       
   165                              "-gv" # allow valgrind
       
   166                              )
       
   167     list(APPEND haskell_flags "-Wall"       # all warnings
   124     list(APPEND haskell_flags "-Wall"       # all warnings
   168                               "-debug"      # debug mode
   125                               "-debug"      # debug mode
   169                               "-dcore-lint" # internal sanity check
   126                               "-dcore-lint" # internal sanity check
   170                               )
   127                               )
   171 else()
   128 else()
   172     list(APPEND pascal_flags "-Os" # optimise for size
       
   173                              "-Xs" # strip binary
       
   174                              "-Si" # turn on inlining
       
   175                              )
       
   176     list(APPEND haskell_flags "-w" # no warnings
   129     list(APPEND haskell_flags "-w" # no warnings
   177                               )
   130                               )
   178 endif()
   131 endif()
   179 
   132 
   180 include(${CMAKE_MODULE_PATH}/utils.cmake)
   133 if (${NOPASCAL})
       
   134     find_package(Clang)
       
   135     # Check LLVM/Clang version
       
   136 	if (CLANG_VERSION VERSION_LESS required_clang_version)
       
   137 		message(FATAL_ERROR "LLVM/Clang compiler required version is ${required_clang_version} but version ${CLANG_VERSION} was found!")
       
   138 	else()
       
   139 		message(STATUS "Found CLANG: ${CLANG_EXECUTABLE} (version ${CLANG_VERSION})")
       
   140 	endif()
       
   141 endif(${NOPASCAL})
       
   142 
   181 
   143 
   182 #Haskell compiler discovery (for server and engine in c)
   144 #Haskell compiler discovery (for server and engine in c)
   183 if((NOT NOSERVER) OR NOPASCAL)
   145 if((NOT NOSERVER) OR NOPASCAL)
   184     if(GHC)
   146     if(GHC)
   185         set(ghc_executable ${GHC})
   147         set(ghc_executable ${GHC})
   206     set(HAVE_NETSERVER false)
   168     set(HAVE_NETSERVER false)
   207 endif()
   169 endif()
   208 
   170 
   209 
   171 
   210 #lua discovery
   172 #lua discovery
   211 find_package(Lua)
   173 if (${LUA_SYSTEM})
   212 if(LUA_FOUND AND (NOT WEBGL))
   174     if (NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
   213     message(STATUS "Found LUA: ${LUA_DEFAULT}")
   175         find_package(Lua)
   214 else()
   176     endif()
   215     message(STATUS "Using internal LUA library")
   177 
       
   178     if (LUA_LIBRARY AND LUA_INCLUDE_DIR)
       
   179         set(LUA_FOUND TRUE)
       
   180         #use an IMPORTED tharget so that we can just use 'lua' to link
       
   181         add_library(lua UNKNOWN IMPORTED)
       
   182         set_target_properties(lua PROPERTIES IMPORTED_LOCATION ${LUA_LIBRARY})
       
   183     else()
       
   184         message(FATAL_ERROR "Missing Lua! Rerun cmake with -DLUA_SYSTEM=off to build the internal version")
       
   185     endif()
       
   186 else()
       
   187     if (NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
       
   188         message(STATUS "LUA will be provided by the bundled sources")
       
   189     endif()
       
   190     set(lua_output_name "hwlua")
   216     add_subdirectory(misc/liblua)
   191     add_subdirectory(misc/liblua)
   217     #linking with liblua.a requires system readline
       
   218     list(APPEND pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline")
       
   219 endif()
   192 endif()
   220 
   193 
   221 
   194 
   222 #physfs discovery
   195 #physfs discovery
   223 if (${PHYSFS_SYSTEM})
   196 if (${PHYSFS_SYSTEM})
   241         endif()
   214         endif()
   242     endif()
   215     endif()
   243 
   216 
   244     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   217     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
   245         message(FATAL_ERROR "Missing PhysFS! Rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
   218         message(FATAL_ERROR "Missing PhysFS! Rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
   246     endif()
   219     else()
   247 else()
   220         #use an IMPORTED tharget so that we can just use 'physfs' to link
   248     message(STATUS "PhysFS will be provided by the bundled sources")
   221         add_library(physfs UNKNOWN IMPORTED)
   249     set(physfs_output_name "hw_physfs")
   222         set_target_properties(physfs PROPERTIES IMPORTED_LOCATION ${PHYSFS_LIBRARY})
       
   223     endif()
       
   224 else()
       
   225     if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
       
   226         message(STATUS "PhysFS will be provided by the bundled sources")
       
   227     endif()
       
   228     set(physfs_output_name "hwphysfs")
   250     add_subdirectory(misc/libphysfs)
   229     add_subdirectory(misc/libphysfs)
   251     #-XLA is a beta fpc flag that renames libraries before passing them to the linker
       
   252     #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
       
   253     #(should be harmless on other platforms)
       
   254     list(APPEND pascal_flags "-XLAphysfs=${physfs_output_name}" "-dPHYSFS_INTERNAL")
       
   255 endif()
   230 endif()
   256 
   231 
   257 find_package_or_disable_msg(FFMPEG NOVIDEOREC "Video recording will not be built")
   232 find_package_or_disable_msg(FFMPEG NOVIDEOREC "Video recording will not be built")
   258 
   233 
   259 #physfs helper library
   234 #physfs helper library