CMakeLists.txt
author koda
Sat, 08 Jun 2013 01:22:46 +0200
changeset 9150 79c58ff0d4b1
parent 9141 e391e9a19b1c
child 9151 1d2df388fcc6
permissions -rw-r--r--
move platform specific and revision info code into separate cmake modules
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 123
diff changeset
     1
project(hedgewars)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 123
diff changeset
     2
5407
486231e82e8d typo and spaces
koda
parents: 5405
diff changeset
     3
#initialise cmake environment
8104
09c38cdf380d show console on win when debugging to see frontend messages
koda
parents: 8093
diff changeset
     4
cmake_minimum_required(VERSION 2.6.0)
8611
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
     5
if(CMAKE_VERSION VERSION_LESS "2.8")
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
     6
    set(WARNING "WARNING: ")
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
     7
    set(allow_parse_args FALSE)
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
     8
else()
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
     9
    set(WARNING WARNING)
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
    10
    set(allow_parse_args TRUE)
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
    11
endif()
8146
1fba650c2aa4 GCI2012: Lowercase CMake functions (main files only)
m4tx
parents: 8104
diff changeset
    12
foreach(hwpolicy CMP0003 CMP0012 CMP0017)
1fba650c2aa4 GCI2012: Lowercase CMake functions (main files only)
m4tx
parents: 8104
diff changeset
    13
    if(POLICY ${hwpolicy})
1fba650c2aa4 GCI2012: Lowercase CMake functions (main files only)
m4tx
parents: 8104
diff changeset
    14
        cmake_policy(SET ${hwpolicy} NEW)
1fba650c2aa4 GCI2012: Lowercase CMake functions (main files only)
m4tx
parents: 8104
diff changeset
    15
    endif()
1fba650c2aa4 GCI2012: Lowercase CMake functions (main files only)
m4tx
parents: 8104
diff changeset
    16
endforeach()
8611
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
    17
8674
fff355ba2902 our cmake modules have become good enough, prefer them over system ones
koda
parents: 8673
diff changeset
    18
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
8673
834e2d3b43d2 Backed out changeset 4cccc0520988
koda
parents: 8672
diff changeset
    19
8090
38d9cc60b14c cleanup revision section, make hg launch tolerant to config errors, drop deprecated exec_prog for desktop configuration in favour of execute_process
koda
parents: 8089
diff changeset
    20
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
    21
#possible cmake configuration
8687
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    22
option(NOSERVER "Disable gameServer build (off)]" OFF)
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    23
option(NOPNG "Disable screenshoot compression (off)" OFF)
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    24
option(NOVIDEOREC "Disable video recording (off)" OFF)
8090
38d9cc60b14c cleanup revision section, make hg launch tolerant to config errors, drop deprecated exec_prog for desktop configuration in favour of execute_process
koda
parents: 8089
diff changeset
    25
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
    26
#set this to ON when 2.1.0 becomes more widespread (and only for linux)
9096
b3041025c271 fix the cmake flag PHYSFS_SYSTEM being called SYSTEM_PHYSFS in the code
sheepluva
parents: 9091
diff changeset
    27
option(PHYSFS_SYSTEM "Use system physfs (off)" OFF)
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
    28
8687
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    29
option(BUILD_ENGINE_LIBRARY "Enable hwengine library (off)" OFF)
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    30
option(ANDROID "Enable Android build (off)" OFF)
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    31
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    32
if(UNIX AND NOT APPLE)
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    33
    option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF)
5b6ad1bd6ace update option list
koda
parents: 8686
diff changeset
    34
else()
8659
e49056d3aba1 fail if sparkle not found consciously
koda
parents: 8650
diff changeset
    35
    option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
e49056d3aba1 fail if sparkle not found consciously
koda
parents: 8650
diff changeset
    36
endif()
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
    37
8333
416cb5e5a405 move DATA_INSTALL_DIR to the configurable options section
koda
parents: 8331
diff changeset
    38
set(FPFLAGS "" CACHE STRING "Additional Freepascal flags")
416cb5e5a405 move DATA_INSTALL_DIR to the configurable options section
koda
parents: 8331
diff changeset
    39
set(GHFLAGS "" CACHE STRING "Additional Haskell flags")
416cb5e5a405 move DATA_INSTALL_DIR to the configurable options section
koda
parents: 8331
diff changeset
    40
if(UNIX AND NOT APPLE)
416cb5e5a405 move DATA_INSTALL_DIR to the configurable options section
koda
parents: 8331
diff changeset
    41
    set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
416cb5e5a405 move DATA_INSTALL_DIR to the configurable options section
koda
parents: 8331
diff changeset
    42
endif()
8104
09c38cdf380d show console on win when debugging to see frontend messages
koda
parents: 8093
diff changeset
    43
8090
38d9cc60b14c cleanup revision section, make hg launch tolerant to config errors, drop deprecated exec_prog for desktop configuration in favour of execute_process
koda
parents: 8089
diff changeset
    44
5405
5b17e1b3e0d5 better variable grouping...
koda
parents: 5223
diff changeset
    45
#versioning
5407
486231e82e8d typo and spaces
koda
parents: 5405
diff changeset
    46
set(CPACK_PACKAGE_VERSION_MAJOR 0)
486231e82e8d typo and spaces
koda
parents: 5405
diff changeset
    47
set(CPACK_PACKAGE_VERSION_MINOR 9)
9141
e391e9a19b1c Bump protocol and version (game desync would be triggered by b70352db5675, 2ae44c4381cd - other revisions probably safe)
nemo
parents: 9106
diff changeset
    48
set(CPACK_PACKAGE_VERSION_PATCH 20)
e391e9a19b1c Bump protocol and version (game desync would be triggered by b70352db5675, 2ae44c4381cd - other revisions probably safe)
nemo
parents: 9106
diff changeset
    49
set(HEDGEWARS_PROTO_VER 46)
5407
486231e82e8d typo and spaces
koda
parents: 5405
diff changeset
    50
set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents: 9141
diff changeset
    51
include(${CMAKE_MODULE_PATH}/revinfo.cmake)
5405
5b17e1b3e0d5 better variable grouping...
koda
parents: 5223
diff changeset
    52
8650
18807b6302c8 version variables confom to naming convention
koda
parents: 8646
diff changeset
    53
message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
907
a5b0b93a39c8 Use constant generated by cmake for version string
unc0rr
parents: 904
diff changeset
    54
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
    55
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
    56
#where to build libs and bins
8316
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    57
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    58
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    59
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
    60
#resource paths
8316
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    61
if(UNIX AND NOT APPLE)
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    62
    set(target_binary_install_dir "bin")
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    63
    set(target_library_install_dir "lib")
8646
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    64
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    65
    string(SUBSTRING "${DATA_INSTALL_DIR}" 0 1 sharepath_start)
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    66
    if (NOT (${sharepath_start} MATCHES "/"))
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    67
        set(HEDGEWARS_DATADIR "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/")
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    68
    else()
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    69
        set(HEDGEWARS_DATADIR "${DATA_INSTALL_DIR}/")
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    70
    endif()
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    71
    set(HEDGEWARS_FULL_DATADIR "${HEDGEWARS_DATADIR}")
7718
97ba379164ec use cmake OPTION for arguments and further cleanup on CMakeFiles
koda
parents: 7709
diff changeset
    72
else()
8316
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    73
    set(target_binary_install_dir "./")
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    74
8317
ec9f94ab2737 remove the CROSSAPPLE option until a better solution is found
koda
parents: 8316
diff changeset
    75
    if(APPLE)
8646
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    76
        set(target_library_install_dir "../Frameworks/")
8316
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    77
        set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/")
8646
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    78
        set(HEDGEWARS_DATADIR "../Resources/")
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    79
        set(HEDGEWARS_FULL_DATADIR "/Applications/${CMAKE_INSTALL_PREFIX}/${HEDGEWARS_DATADIR}")
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    80
    elseif(WIN32)
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    81
        set(target_library_install_dir "./")
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    82
        set(HEDGEWARS_DATADIR "./")
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    83
        set(HEDGEWARS_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/")
e31044b7fbba on linux assume datapath is always relative to cmake_install_prefix, unless you provide an absolute path; on win32/osx hardcode engine path to default installation prefixes (it gets overridden at runtime so it works even if you move the data folder)
koda
parents: 8644
diff changeset
    84
        link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin")
8316
89232b2fa1d6 cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
koda
parents: 8313
diff changeset
    85
    endif()
7256
5b97b9946cde CROSSAPPLE ftw
koda
parents: 7233
diff changeset
    86
endif()
5b97b9946cde CROSSAPPLE ftw
koda
parents: 7233
diff changeset
    87
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents: 9141
diff changeset
    88
#platform specific init code
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents: 9141
diff changeset
    89
include(${CMAKE_MODULE_PATH}/platform.cmake)
2015
d2848d723690 koda's patch
unc0rr
parents: 2005
diff changeset
    90
2406
2e757b32991e cmake optimizations and simplification
koda
parents: 2401
diff changeset
    91
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
    92
#when build type is not specified, assume Debug/Release according to build version information
7709
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
    93
if (CMAKE_BUILD_TYPE)
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
    94
    string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
    95
    if ( NOT( (CMAKE_BUILD_TYPE MATCHES "RELEASE") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") ) )
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
    96
        set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE)
7709
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
    97
        message (STATUS "Unknown build type, using default (${default_build_type})")
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
    98
    endif ()
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
    99
else (CMAKE_BUILD_TYPE)
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
   100
    set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE)
7709
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
   101
endif (CMAKE_BUILD_TYPE)
2606
ed687a8d081f updated build files for macosx and optimization system
koda
parents: 2573
diff changeset
   102
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
   103
7944
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   104
#set default flags values for all projects (unless MINIMAL_FLAGS is true)
8347
716c05f19401 GCI2012: CMake List Append
Willie Zhu
parents: 8333
diff changeset
   105
if(NOT ${MINIMAL_FLAGS})
8348
c039ac6f33e0 don't discard older cmake_c_flags
koda
parents: 8347
diff changeset
   106
    set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}")
c039ac6f33e0 don't discard older cmake_c_flags
koda
parents: 8347
diff changeset
   107
    set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}")
c039ac6f33e0 don't discard older cmake_c_flags
koda
parents: 8347
diff changeset
   108
    set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g -DDEBUG ${CMAKE_C_FLAGS_DEBUG}")
7944
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   109
    set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   110
    set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   111
    set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   112
else()
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   113
    #CMake adds a lot of additional configuration flags, so let's clear them up
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   114
    set(CMAKE_C_FLAGS_RELEASE "")
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   115
    set(CMAKE_C_FLAGS_DEBUG "-Wall -DDEBUG")
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   116
    set(CMAKE_CXX_FLAGS_RELEASE "")
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   117
    set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG")
a94f4ef5ba2b play nicer with system flags
hasufell
parents: 7933
diff changeset
   118
endif()
2606
ed687a8d081f updated build files for macosx and optimization system
koda
parents: 2573
diff changeset
   119
8907
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   120
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   121
#TESTING TIME
8669
3f9853888d4f user correct variable and slimmer test, version typos, .dll.a updated
koda
parents: 8666
diff changeset
   122
include(CheckCCompilerFlag)
8907
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   123
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   124
#check for noexecstack on ELF, should be set on Gentoo and similar
8669
3f9853888d4f user correct variable and slimmer test, version typos, .dll.a updated
koda
parents: 8666
diff changeset
   125
set(CMAKE_REQUIRED_FLAGS "-Wl,-z -Wl,noexecstack")
3f9853888d4f user correct variable and slimmer test, version typos, .dll.a updated
koda
parents: 8666
diff changeset
   126
check_c_compiler_flag("" HAVE_NOEXECSTACK) #empty because we are testing a linker flag
8665
3ff8694d9e22 rewritten findfreepascal, moved checkstack code elsewhere
koda
parents: 8659
diff changeset
   127
if(HAVE_NOEXECSTACK)
3ff8694d9e22 rewritten findfreepascal, moved checkstack code elsewhere
koda
parents: 8659
diff changeset
   128
    list(APPEND pascal_flags "-k-z" "-knoexecstack")
8907
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   129
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   130
endif()
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   131
unset(CMAKE_REQUIRED_FLAGS)
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   132
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   133
#check for ASLR and DEP security features on Windows
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   134
#both supported in binutils >= 2.20, available since Vista and XP SP2 respectively
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   135
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat -Wl,--dynamicbase")
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   136
check_c_compiler_flag("" HAVE_WINASLRDEP) #empty because we are testing a linker flag
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   137
if(HAVE_WINASLRDEP)
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   138
    list(APPEND pascal_flags "-k--nxcompat" "-k--dynamicbase")
7e9c6efe90fd added two security flags to windows linking
koda
parents: 8734
diff changeset
   139
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
8665
3ff8694d9e22 rewritten findfreepascal, moved checkstack code elsewhere
koda
parents: 8659
diff changeset
   140
endif()
8669
3f9853888d4f user correct variable and slimmer test, version typos, .dll.a updated
koda
parents: 8666
diff changeset
   141
unset(CMAKE_REQUIRED_FLAGS)
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
   142
7397
833fc211ca2d allow FPFLAGS and GHFLAGS only in cmakes able to support them
koda
parents: 7264
diff changeset
   143
#parse additional parameters
833fc211ca2d allow FPFLAGS and GHFLAGS only in cmakes able to support them
koda
parents: 7264
diff changeset
   144
if(FPFLAGS OR GHFLAGS)
8611
90f445317e8a support WARNING message status on cmake 2.6 (bug 524)
koda
parents: 8597
diff changeset
   145
    if(${allow_parse_args})
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   146
        separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS})
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   147
        separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS})
9104
5cf87143b188 wow binary logic ftw
koda
parents: 9096
diff changeset
   148
    else()
5cf87143b188 wow binary logic ftw
koda
parents: 9096
diff changeset
   149
        message(${WARNING} "FPFLAGS and GHFLAGS are available only when using CMake >= 2.8")
7397
833fc211ca2d allow FPFLAGS and GHFLAGS only in cmakes able to support them
koda
parents: 7264
diff changeset
   150
    endif()
833fc211ca2d allow FPFLAGS and GHFLAGS only in cmakes able to support them
koda
parents: 7264
diff changeset
   151
endif()
833fc211ca2d allow FPFLAGS and GHFLAGS only in cmakes able to support them
koda
parents: 7264
diff changeset
   152
8707
404c18aed69f alignment
koda
parents: 8706
diff changeset
   153
list(APPEND pascal_flags ${fpflags_parsed}            # user flags
404c18aed69f alignment
koda
parents: 8706
diff changeset
   154
                 "-B"                                 # compile all units
404c18aed69f alignment
koda
parents: 8706
diff changeset
   155
                 "-vm4079,4080,4081"                  # fpc verbosity output format
404c18aed69f alignment
koda
parents: 8706
diff changeset
   156
                 "-FE${PROJECT_BINARY_DIR}/bin"       # fpc binaries output directory
8706
9f5df5dc44a0 introducing the bestest flag of all
koda
parents: 8705
diff changeset
   157
                 "-FU${PROJECT_BINARY_DIR}/hedgewars" # fpc units output directory
8707
404c18aed69f alignment
koda
parents: 8706
diff changeset
   158
                 "-Fl${PROJECT_BINARY_DIR}/bin"       # fpc linking directory (win/unix)
404c18aed69f alignment
koda
parents: 8706
diff changeset
   159
                 "-Fi${PROJECT_BINARY_DIR}/hedgewars" # fpc .inc path (for out of source builds)
404c18aed69f alignment
koda
parents: 8706
diff changeset
   160
                 "-k-L${PROJECT_BINARY_DIR}/bin"      # ld linking directory (unix/osx)
404c18aed69f alignment
koda
parents: 8706
diff changeset
   161
                 "-Cs2000000"                         # stack size
404c18aed69f alignment
koda
parents: 8706
diff changeset
   162
                 "-vewnq"                             # fpc output verbosity
404c18aed69f alignment
koda
parents: 8706
diff changeset
   163
                 "-dDEBUGFILE"                        # macro for engine output
8283
af97cdbb7713 cmake verbosity/documentation/cleanup/formatting
koda
parents: 8279
diff changeset
   164
                 )
8707
404c18aed69f alignment
koda
parents: 8706
diff changeset
   165
list(APPEND haskell_flags ${ghflags_parsed} # user flags
404c18aed69f alignment
koda
parents: 8706
diff changeset
   166
                 "-O2"                      # optimise for faster code
8644
62756eb6fe9c typo and doc
koda
parents: 8642
diff changeset
   167
                 )
2606
ed687a8d081f updated build files for macosx and optimization system
koda
parents: 2573
diff changeset
   168
8614
5f74a047cf2c drop useless option, automatically set revision and debug info
koda
parents: 8613
diff changeset
   169
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   170
#get BUILD_TYPE and enable/disable optimisation
8279
c03d64969112 less linking needed, raise minimum_osx_version when videorec is enabled
koda
parents: 8272
diff changeset
   171
message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration")
7709
631852904cee only accept RELASE and DEBUG build type configuration
koda
parents: 7705
diff changeset
   172
if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
8707
404c18aed69f alignment
koda
parents: 8706
diff changeset
   173
    list(APPEND pascal_flags "-O-" # disable all optimisations
404c18aed69f alignment
koda
parents: 8706
diff changeset
   174
                             "-g"  # enable debug symbols
404c18aed69f alignment
koda
parents: 8706
diff changeset
   175
                             "-gl" # add line info to bt
404c18aed69f alignment
koda
parents: 8706
diff changeset
   176
                             "-gv" # allow valgrind
8555
342f7af2eea5 moar docs update
koda
parents: 8549
diff changeset
   177
                             )
8707
404c18aed69f alignment
koda
parents: 8706
diff changeset
   178
    list(APPEND haskell_flags "-Wall"       # all warnings
404c18aed69f alignment
koda
parents: 8706
diff changeset
   179
                              "-debug"      # debug mode
404c18aed69f alignment
koda
parents: 8706
diff changeset
   180
                              "-dcore-lint" # internal sanity check
8644
62756eb6fe9c typo and doc
koda
parents: 8642
diff changeset
   181
                              )
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   182
else()
8707
404c18aed69f alignment
koda
parents: 8706
diff changeset
   183
    list(APPEND pascal_flags "-Os" # optimise for size
404c18aed69f alignment
koda
parents: 8706
diff changeset
   184
                             "-Xs" # strip binary
404c18aed69f alignment
koda
parents: 8706
diff changeset
   185
                             "-Si" # turn on inlining
8555
342f7af2eea5 moar docs update
koda
parents: 8549
diff changeset
   186
                             )
8707
404c18aed69f alignment
koda
parents: 8706
diff changeset
   187
    list(APPEND haskell_flags "-w" # no warnings
8644
62756eb6fe9c typo and doc
koda
parents: 8642
diff changeset
   188
                              )
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   189
endif()
2606
ed687a8d081f updated build files for macosx and optimization system
koda
parents: 2573
diff changeset
   190
8686
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents: 8683
diff changeset
   191
include(${CMAKE_MODULE_PATH}/utils.cmake)
2606
ed687a8d081f updated build files for macosx and optimization system
koda
parents: 2573
diff changeset
   192
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   193
#lua discovery
7031
d5ea24399a48 when Lua is not found, fallback to compiling the one that comes bundled in our sources
koda
parents: 7030
diff changeset
   194
find_package(Lua)
7233
225179f64fd8 LUA_FOUND should surely be set only if the system lua was found.
nemo
parents: 7226
diff changeset
   195
if(LUA_FOUND)
7817
6cc558a69b58 countless small optimisation for cmake, output messages are now coherent (mostly) and the options get fully respected (eg. skipping library search if not activated)
koda
parents: 7816
diff changeset
   196
    message(STATUS "Found LUA: ${LUA_DEFAULT}")
7223
b554726ff468 uniform NOPNG and NOSERVER cmake symbols
koda
parents: 7220
diff changeset
   197
else()
7817
6cc558a69b58 countless small optimisation for cmake, output messages are now coherent (mostly) and the options get fully respected (eg. skipping library search if not activated)
koda
parents: 7816
diff changeset
   198
    message(STATUS "LUA will be provided by the bundled sources")
7220
dfe678f129e4 sed 's/\t/ /g' CMakeLists.txt
koda
parents: 7114
diff changeset
   199
    add_subdirectory(misc/liblua)
8093
2286a39140da moar cmake cleanup, use message(WARNING ...) where appropriate
koda
parents: 8090
diff changeset
   200
    #linking with liblua.a requires system readline
8347
716c05f19401 GCI2012: CMake List Append
Willie Zhu
parents: 8333
diff changeset
   201
    list(APPEND pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline")
7031
d5ea24399a48 when Lua is not found, fallback to compiling the one that comes bundled in our sources
koda
parents: 7030
diff changeset
   202
endif()
7223
b554726ff468 uniform NOPNG and NOSERVER cmake symbols
koda
parents: 7220
diff changeset
   203
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   204
8544
d610e692e2f6 perform a version check before including physfs (maybe there is a better place for this?) and allow overriding automagic search
koda
parents: 8540
diff changeset
   205
#physfs discovery
9096
b3041025c271 fix the cmake flag PHYSFS_SYSTEM being called SYSTEM_PHYSFS in the code
sheepluva
parents: 9091
diff changeset
   206
if (${PHYSFS_SYSTEM})
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   207
    if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   208
        find_package(PhysFS)
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   209
    endif()
8544
d610e692e2f6 perform a version check before including physfs (maybe there is a better place for this?) and allow overriding automagic search
koda
parents: 8540
diff changeset
   210
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   211
    find_file(physfs_h physfs.h ${PHYSFS_INCLUDE_DIR})
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   212
    if(physfs_h)
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   213
        file(STRINGS ${physfs_h} physfs_majorversion REGEX "PHYSFS_VER_MAJOR[\t' ']+[0-9]+")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   214
        file(STRINGS ${physfs_h} physfs_minorversion REGEX "PHYSFS_VER_MINOR[\t' ']+[0-9]+")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   215
        file(STRINGS ${physfs_h} physfs_patchversion REGEX "PHYSFS_VER_PATCH[\t' ']+[0-9]+")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   216
        string(REGEX MATCH "([0-9]+)" physfs_majorversion "${physfs_majorversion}")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   217
        string(REGEX MATCH "([0-9]+)" physfs_minorversion "${physfs_minorversion}")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   218
        string(REGEX MATCH "([0-9]+)" physfs_patchversion "${physfs_patchversion}")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   219
        set(physfs_detected_ver "${physfs_majorversion}.${physfs_minorversion}.${physfs_patchversion}")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   220
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   221
        if (physfs_detected_ver VERSION_LESS "2.1.0")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   222
            message(FATAL_ERROR "PhysFS version is too old (dected ${physfs_detected_ver}, required 2.1.0)")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   223
            set(physfs_too_old true)
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   224
        endif()
8544
d610e692e2f6 perform a version check before including physfs (maybe there is a better place for this?) and allow overriding automagic search
koda
parents: 8540
diff changeset
   225
    endif()
d610e692e2f6 perform a version check before including physfs (maybe there is a better place for this?) and allow overriding automagic search
koda
parents: 8540
diff changeset
   226
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   227
    if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR)
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   228
        message(FATAL_ERROR "Missing PhysFS! Rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version")
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   229
    endif()
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   230
else()
8528
ffd71e99a4f0 and now compile and link properly
koda
parents: 8522
diff changeset
   231
    message(STATUS "PhysFS will be provided by the bundled sources")
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   232
    set(physfs_output_name "hw_physfs")
8528
ffd71e99a4f0 and now compile and link properly
koda
parents: 8522
diff changeset
   233
    add_subdirectory(misc/libphysfs)
8558
e96bf10216ef on windows fpc-linking is the funniest of all
koda
parents: 8555
diff changeset
   234
    #-XLA is a beta fpc flag that renames libraries before passing them to the linker
e96bf10216ef on windows fpc-linking is the funniest of all
koda
parents: 8555
diff changeset
   235
    #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements
e96bf10216ef on windows fpc-linking is the funniest of all
koda
parents: 8555
diff changeset
   236
    #(should be harmless on other platforms)
e96bf10216ef on windows fpc-linking is the funniest of all
koda
parents: 8555
diff changeset
   237
    list(APPEND pascal_flags "-XLAphysfs=${physfs_output_name}" "-dPHYSFS_INTERNAL")
8528
ffd71e99a4f0 and now compile and link properly
koda
parents: 8522
diff changeset
   238
endif()
8549
af104e59ea8e due to popular demand, add a compile time switch to manually select whether to build the internal physfs (default) or not
koda
parents: 8544
diff changeset
   239
8688
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8687
diff changeset
   240
find_package_or_disable_msg(FFMPEG NOVIDEOREC "Video recording will not be built")
8666
1652c1d9adc8 rework ffmpeg/libav/videorec linking and their cmake discovery
koda
parents: 8665
diff changeset
   241
8671
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents: 8669
diff changeset
   242
#physfs helper library
8528
ffd71e99a4f0 and now compile and link properly
koda
parents: 8522
diff changeset
   243
add_subdirectory(misc/libphyslayer)
8283
af97cdbb7713 cmake verbosity/documentation/cleanup/formatting
koda
parents: 8279
diff changeset
   244
8671
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents: 8669
diff changeset
   245
#server
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents: 8669
diff changeset
   246
if(NOT NOSERVER)
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents: 8669
diff changeset
   247
    add_subdirectory(gameServer)
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents: 8669
diff changeset
   248
endif()
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents: 8669
diff changeset
   249
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   250
#main engine
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 123
diff changeset
   251
add_subdirectory(hedgewars)
5053
a767954cfa03 this should help people hacking the cmake files
koda
parents: 4904
diff changeset
   252
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   253
#Android related build scripts
6812
929b467c7277 fixed some typo's. LUA_LIBRARY now points to the right name, regardless of the host machine. Running cmake after a bad attempt (ie forgot to add paths to PATH) now works rather than having to clean the cache
Xeli
parents: 6605
diff changeset
   254
if(ANDROID)
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   255
    #run cmake -DANDROID=1 to enable this
7220
dfe678f129e4 sed 's/\t/ /g' CMakeLists.txt
koda
parents: 7114
diff changeset
   256
    add_subdirectory(project_files/Android-build)
6025
cac1d5601d7c reviewed the build system and parts of the previous merge, performed some code cleanup
koda
parents: 6023
diff changeset
   257
endif()
5381
8f95038f3f75 Removed protocol check, using CMake now to setup the building scripts using Templates/* removed old scripts
Xeli
parents: 5223
diff changeset
   258
7705
15f5d3cd35c6 force a DEBUG build when HW_DEV is true, some CMakeLists.txt cleanup/commenting
koda
parents: 7704
diff changeset
   259
#TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
8082
675372256a01 lotsa hackery to get frontend somehow link libengine...
koda
parents: 8078
diff changeset
   260
if(NOT ANDROID)
7220
dfe678f129e4 sed 's/\t/ /g' CMakeLists.txt
koda
parents: 7114
diff changeset
   261
    add_subdirectory(bin)
dfe678f129e4 sed 's/\t/ /g' CMakeLists.txt
koda
parents: 7114
diff changeset
   262
    add_subdirectory(QTfrontend)
dfe678f129e4 sed 's/\t/ /g' CMakeLists.txt
koda
parents: 7114
diff changeset
   263
    add_subdirectory(share)
dfe678f129e4 sed 's/\t/ /g' CMakeLists.txt
koda
parents: 7114
diff changeset
   264
    add_subdirectory(tools)
3515
3e8635f43972 fix cmakefiles to work with mercurial
koda
parents: 3495
diff changeset
   265
endif()
2203
6bd39d75e0dd -Added support for Release and Debug for CMAKE_BUILD_TYPE
koda
parents: 2200
diff changeset
   266
584
f381705f1aeb Some stuff to get good results from make 'package_source'
unc0rr
parents: 546
diff changeset
   267
9091
bafadc6b4516 change cpack configuration file name so that it's not excluded by 'make package_source'
koda
parents: 9086
diff changeset
   268
include(${CMAKE_MODULE_PATH}/cpackvars.cmake)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 123
diff changeset
   269