Callback: work at any arity
[xonotic/netradiant.git] / CMakeLists.txt
index 335c108..d2e87cd 100644 (file)
@@ -1,8 +1,8 @@
-cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
-
 project(NetRadiant C CXX)
-option(BUILD_RADIANT "Build the gui" ON)
+
+option(BUILD_RADIANT "Build the GUI" ON)
 
 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
     set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
@@ -44,17 +44,18 @@ message(STATUS "Building ${PROJECT_NAME} ${RADIANT_VERSION_STRING} ${RADIANT_ABO
 
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
-# For some reason the above flags don't really work...
-if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
-    include(CheckCXXCompilerFlag)
-    check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
-    if (STD_CXX)
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
+if (CMAKE_VERSION VERSION_LESS "3.1")
+    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
+        include(CheckCXXCompilerFlag)
+        check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
+        if (STD_CXX)
+            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
+        else ()
+            message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
+        endif ()
     else ()
-        message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
+        message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
     endif ()
-else ()
-    message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
 endif ()
 
 #-----------------------------------------------------------------------
@@ -62,17 +63,39 @@ endif ()
 #-----------------------------------------------------------------------
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
-macro(addflags args)
+macro(addflags_c args)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
+endmacro()
+macro(addflags_cxx args)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
 endmacro()
+macro(addflags args)
+    addflags_c("${args}")
+    addflags_cxx("${args}")
+endmacro()
 addflags("-fno-strict-aliasing")
 if (NOT WIN32)
     addflags("-fvisibility=hidden")
 endif ()
 
+if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
+    addflags("-Werror")
+    addflags("-pedantic-errors")
+endif ()
+
+addflags("-Wall")
+addflags("-Wextra")
+addflags("-pedantic")
+
+addflags_c("-Wno-deprecated-declarations") # vfs.c: g_strdown
+
+addflags("-Wno-unused-function")
+addflags("-Wno-unused-variable")
+addflags("-Wno-unused-parameter")
+
 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
-set(GTK_NS "GTK2" CACHE STRING "GTK variable prefix")
+set(GTK_TARGET 2 CACHE STRING "GTK target")
+add_definitions(-DGTK_TARGET=${GTK_TARGET})
 
 #-----------------------------------------------------------------------
 # Defs
@@ -89,6 +112,20 @@ if (NOT CMAKE_BUILD_TYPE MATCHES Release)
     add_definitions(-D_DEBUG=1)
 endif ()
 
+macro(disable_deprecated name gtk2only)
+    add_definitions(-D${name}_DISABLE_SINGLE_INCLUDES)
+    if ((${gtk2only} EQUAL 0) OR (GTK_TARGET EQUAL 2))
+        add_definitions(-D${name}_DISABLE_DEPRECATED)
+    endif ()
+endmacro()
+
+disable_deprecated(ATK 0)
+disable_deprecated(G 0)
+disable_deprecated(GDK 0)
+disable_deprecated(GDK_PIXBUF 0)
+disable_deprecated(GTK 1)
+disable_deprecated(PANGO 0)
+
 if (APPLE)
     option(XWINDOWS "Build against X11" ON)
     add_definitions(
@@ -115,8 +152,15 @@ endif ()
 include_directories("${PROJECT_SOURCE_DIR}/include")
 include_directories("${PROJECT_SOURCE_DIR}/libs")
 
+if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
+    set(BUNDLE_LIBRARIES_DEFAULT ON)
+else ()
+    set(BUNDLE_LIBRARIES_DEFAULT OFF)
+endif ()
+option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
+
 macro(copy_dlls target)
-    if (WIN32)
+    if (BUNDLE_LIBRARIES)
         add_custom_command(TARGET ${target} POST_BUILD
                 COMMAND bash
                 ARGS -c "ldd '$<TARGET_FILE:${target}>' | grep -v /c/Windows | awk '{ print $1 }' | while read dll; do cp \"$(which $dll)\" '${PROJECT_BINARY_DIR}'; done"
@@ -173,15 +217,14 @@ macro(radiant_tool name)
                 COMMAND ln -f -s "$<TARGET_FILE_NAME:${name}>" "${PROJECT_BINARY_DIR}/${name}.${RADIANT_EXECUTABLE}"
                 VERBATIM
                 )
-        install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \
-            ${name}${CMAKE_EXECUTABLE_SUFFIX} \
-            ${CMAKE_INSTALL_PREFIX}/${name}.${RADIANT_EXECUTABLE} \
-        )")
+        install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
+                ${name}${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${name}.${RADIANT_EXECUTABLE})
+                ")
     endif ()
 endmacro()
 
 if (BUILD_RADIANT)
-    add_subdirectory(radiant build)
+    add_subdirectory(radiant _radiant)
     set_target_properties(radiant PROPERTIES
             COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
             )
@@ -206,13 +249,24 @@ endif ()
 #-----------------------------------------------------------------------
 
 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
-add_custom_target(game_packs
+add_custom_target(game_packs_free
         COMMAND ${CMAKE_COMMAND} -E make_directory games
         COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}"
-        COMMENT "Downloading game packs"
+        COMMENT "Downloading free game packs"
+        )
+add_custom_target(game_packs_all
+        COMMAND ${CMAKE_COMMAND} -E make_directory games
+        COMMAND DOWNLOAD_GAMEPACKS=all SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}"
+        COMMENT "Downloading all game packs"
         )
+
 if (DOWNLOAD_GAMEPACKS)
-    add_custom_target(game_packs_all ALL DEPENDS game_packs)
+    set(DOWNLOAD_GAMEPACKS "all")
+endif()
+if ("${DOWNLOAD_GAMEPACKS}" STREQUAL "free")
+    add_custom_target(game_packs_go ALL DEPENDS game_packs_free)
+elseif ("${DOWNLOAD_GAMEPACKS}" STREQUAL "all")
+    add_custom_target(game_packs_go ALL DEPENDS game_packs_all)
 endif ()
 
 #-----------------------------------------------------------------------
@@ -224,43 +278,45 @@ install(
         "${PROJECT_BINARY_DIR}/RADIANT_MAJOR"
         "${PROJECT_BINARY_DIR}/RADIANT_MINOR"
         "${PROJECT_BINARY_DIR}/RADIANT_PATCH"
-        DESTINATION ${CMAKE_INSTALL_PREFIX}
+        DESTINATION .
 )
 
 install(
         DIRECTORY
-        ${PROJECT_SOURCE_DIR}/setup/data/tools/
-        ${PROJECT_SOURCE_DIR}/docs
-        DESTINATION ${CMAKE_INSTALL_PREFIX}
+        setup/data/tools/
+        docs
+        DESTINATION .
 )
 
 set(GAME_FILES
-        DarkPlacesPack
-        NexuizPack
-        OpenArenaPack
-        OsirionPack
-        Q3Pack
-        Quake2Pack
-        QuakePack
-        QuetooPack
-        TremulousPack
-        UFOAIPack
-        UnvanquishedPack
-        WarsowPack
-        XonoticPack
+        DarkPlaces
+        Nexuiz
+        OpenArena
+        Osirion
+        Q3
+        Quake2
+        Quake
+        Quetoo
+        Tremulous
+        UFOAI
+        Unvanquished
+        Warsow
+        Xonotic
         )
 unset(_tmp)
 foreach (it ${GAME_FILES})
-    set(it "${PROJECT_BINARY_DIR}/games/${it}")
-    list(APPEND _tmp "${it}/games")
-    file(GLOB GAME_DIR "${it}/*.game")
-    list(APPEND _tmp "${GAME_DIR}")
+    set(dir "${PROJECT_BINARY_DIR}/games/${it}Pack")
+    string(TOLOWER "${it}" it)
+    list(APPEND _tmp "${dir}/games")
+    list(APPEND _tmp "${dir}/${it}.game")
 endforeach ()
 set(GAME_FILES ${_tmp})
 
 install(
         DIRECTORY
         ${GAME_FILES}
-        DESTINATION ${CMAKE_INSTALL_PREFIX}
+        DESTINATION .
         OPTIONAL
 )
+
+include(cmake/scripts/package.cmake)