| 1 |
# Required cmake version |
| 2 |
cmake_minimum_required(VERSION 3.1.0) |
| 3 |
|
| 4 |
# Put the include dirs which are in the source or build tree |
| 5 |
# before all other include dirs, so the headers in the sources |
| 6 |
# are prefered over the already installed ones |
| 7 |
# since cmake 2.4.1 |
| 8 |
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) |
| 9 |
|
| 10 |
project(pvpgn CXX) |
| 11 |
|
| 12 |
option(WITH_BNETD "compile the bnetd target" ON) |
| 13 |
option(WITH_D2CS "compile the d2cs target" ON) |
| 14 |
option(WITH_D2DBS "compile the d2dbs target" ON) |
| 15 |
option(WITH_LUA "enable Lua support" OFF) |
| 16 |
if(WIN32) |
| 17 |
option(WITH_WIN32_GUI "enable GUI building (default on)" ON) |
| 18 |
endif(WIN32) |
| 19 |
|
| 20 |
#storage backends flags |
| 21 |
option(WITH_MYSQL "include MySQL user accounts support" OFF) |
| 22 |
option(WITH_SQLITE3 "include SQLite3 user accounts support" OFF) |
| 23 |
option(WITH_PGSQL "include PostgreSQL user accounts support" OFF) |
| 24 |
option(WITH_ODBC "include ODBC user accounts support" OFF) |
| 25 |
include(ConfigureChecks.cmake) |
| 26 |
|
| 27 |
|
| 28 |
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 29 |
# using Clang |
| 30 |
|
| 31 |
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -march=native -mtune=native -pedantic -stdlib=libc++") |
| 32 |
|
| 33 |
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 34 |
# using G++ |
| 35 |
|
| 36 |
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) |
| 37 |
message(FATAL_ERROR "G++ 5.1 or higher required") |
| 38 |
endif() |
| 39 |
|
| 40 |
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -march=native -mtune=native -pedantic -Wno-variadic-macros" ) |
| 41 |
|
| 42 |
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 43 |
# using Visual Studio |
| 44 |
|
| 45 |
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) |
| 46 |
message(FATAL_ERROR "Visual Studio 2015 or higher required") |
| 47 |
endif() |
| 48 |
|
| 49 |
|
| 50 |
# DEBUG compiler flags: |
| 51 |
# /Zi create debugging information PDB file |
| 52 |
# /Od disable optimizations |
| 53 |
# /Oy- do not suppress frame pointers (recommended for debugging) |
| 54 |
# /MTd use statically linked, thread-safe, debug CRT libs (Magic Builder set this flag when build) |
| 55 |
# |
| 56 |
# RELEASE compiler flags: |
| 57 |
# /MT use statically linked, thread-safe CRT libs (Magic Builder set this flag when build) |
| 58 |
# /GS- no Buffer Security Check |
| 59 |
# |
| 60 |
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi /Od /Oy-") |
| 61 |
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") |
| 62 |
|
| 63 |
# Explaining of linker flags and why enable pdb with debug info for Release build is on: |
| 64 |
# https://www.wintellect.com/correctly-creating-native-c-release-build-pdbs |
| 65 |
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") |
| 66 |
endif() |
| 67 |
|
| 68 |
subdirs(src conf man files) |
| 69 |
if(WITH_LUA) |
| 70 |
add_subdirectory(lua) |
| 71 |
endif(WITH_LUA) |
| 72 |
|
| 73 |
ENABLE_TESTING() |
| 74 |
|
| 75 |
# uninstall target |
| 76 |
configure_file( |
| 77 |
"${CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in" |
| 78 |
"${CMAKE_MODULE_PATH}/cmake_uninstall.cmake" |
| 79 |
IMMEDIATE @ONLY) |
| 80 |
|
| 81 |
add_custom_target(uninstall |
| 82 |
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_MODULE_PATH}/cmake_uninstall.cmake) |
| 83 |
|
| 84 |
# purge target |
| 85 |
configure_file( |
| 86 |
"${CMAKE_MODULE_PATH}/cmake_purge.cmake.in" |
| 87 |
"${CMAKE_MODULE_PATH}/cmake_purge.cmake" |
| 88 |
IMMEDIATE @ONLY) |
| 89 |
|
| 90 |
add_custom_target(purge |
| 91 |
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_MODULE_PATH}/cmake_purge.cmake) |