Remove <gtk/gtk.h> from gtkutil/entry.h
[xonotic/netradiant.git] / CMakeLists.txt
index 742fd05..3cbb897 100644 (file)
@@ -1,13 +1,13 @@
 cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
-# Enable Debug by default, can be changed with -DCMAKE_BUILD_TYPE=Release
-if (NOT CMAKE_BUILD_TYPE)
-    set(CMAKE_BUILD_TYPE Debug)
-endif ()
 
 project(NetRadiant C CXX)
 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)
+endif ()
+
 #-----------------------------------------------------------------------
 # Version
 #-----------------------------------------------------------------------
@@ -20,6 +20,7 @@ set(NetRadiant_VERSION "${NetRadiant_VERSION_MAJOR}.${NetRadiant_VERSION_MINOR}.
 
 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_MAJOR" ${NetRadiant_VERSION_MAJOR})
 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_MINOR" ${NetRadiant_VERSION_MINOR})
+file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_PATCH" ${NetRadiant_VERSION_PATCH})
 
 set(RADIANT_ABOUTMSG "Custom build" CACHE STRING "About message")
 
@@ -48,7 +49,7 @@ 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)
-        list(APPEND CMAKE_CXX_FLAGS --std=c++${CMAKE_CXX_STANDARD})
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
     else ()
         message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
     endif ()
@@ -60,9 +61,18 @@ endif ()
 # Flags
 #-----------------------------------------------------------------------
 
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}   -fno-strict-aliasing")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fno-exceptions -fno-rtti")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
+macro(addflags args)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
+endmacro()
+addflags("-fno-strict-aliasing")
+if (NOT WIN32)
+    addflags("-fvisibility=hidden")
+endif ()
+
 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
+set(GTK_NS "GTK2" CACHE STRING "GTK variable prefix")
 
 #-----------------------------------------------------------------------
 # Defs
@@ -71,13 +81,22 @@ set(CMAKE_POSITION_INDEPENDENT_CODE 1)
 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
+add_definitions(-DRADIANT_PATCH_VERSION="${NetRadiant_VERSION_PATCH}")
 
 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
 
-if (CMAKE_BUILD_TYPE MATCHES Debug)
+if (NOT CMAKE_BUILD_TYPE MATCHES Release)
     add_definitions(-D_DEBUG=1)
 endif ()
 
+add_definitions(
+    -DGTK_DISABLE_SINGLE_INCLUDES
+    -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES
+    -DGSEAL_ENABLE
+    -DGTK_DISABLE_DEPRECATED
+    -DGDK_DISABLE_DEPRECATED
+)
+
 if (APPLE)
     option(XWINDOWS "Build against X11" ON)
     add_definitions(
@@ -104,6 +123,23 @@ 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 (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"
+                VERBATIM
+                )
+    endif ()
+endmacro()
+
 #-----------------------------------------------------------------------
 # Libraries
 #-----------------------------------------------------------------------
@@ -131,12 +167,8 @@ endif ()
 # Radiant
 #-----------------------------------------------------------------------
 
-if (BUILD_RADIANT)
-    add_subdirectory(radiant build)
-endif ()
-
 if (CMAKE_EXECUTABLE_SUFFIX)
-    set(RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
+    string(REGEX REPLACE "^[.]" "" RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
 else ()
     execute_process(
             COMMAND uname -m
@@ -145,7 +177,26 @@ else ()
     )
 endif ()
 
+macro(radiant_tool name)
+    add_executable(${name} ${ARGN})
+    install(
+            TARGETS ${name}
+            RUNTIME DESTINATION .
+    )
+    if (NOT (CMAKE_EXECUTABLE_SUFFIX STREQUAL ".${RADIANT_EXECUTABLE}"))
+        add_custom_command(TARGET ${name} POST_BUILD
+                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} \
+        )")
+    endif ()
+endmacro()
+
 if (BUILD_RADIANT)
+    add_subdirectory(radiant build)
     set_target_properties(radiant PROPERTIES
             COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
             )
@@ -157,13 +208,12 @@ endif ()
 
 add_subdirectory(tools)
 
+file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
+
 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
     # Copy data files from sources to the build directory
     message(STATUS "Copying data files")
-    file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
-    file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/docs/*")
-    file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}/docs")
 endif ()
 
 #-----------------------------------------------------------------------
@@ -179,3 +229,53 @@ add_custom_target(game_packs
 if (DOWNLOAD_GAMEPACKS)
     add_custom_target(game_packs_all ALL DEPENDS game_packs)
 endif ()
+
+#-----------------------------------------------------------------------
+# Install
+#-----------------------------------------------------------------------
+
+install(
+        FILES
+        "${PROJECT_BINARY_DIR}/RADIANT_MAJOR"
+        "${PROJECT_BINARY_DIR}/RADIANT_MINOR"
+        "${PROJECT_BINARY_DIR}/RADIANT_PATCH"
+        DESTINATION ${CMAKE_INSTALL_PREFIX}
+)
+
+install(
+        DIRECTORY
+        ${PROJECT_SOURCE_DIR}/setup/data/tools/
+        ${PROJECT_SOURCE_DIR}/docs
+        DESTINATION ${CMAKE_INSTALL_PREFIX}
+)
+
+set(GAME_FILES
+        DarkPlaces
+        Nexuiz
+        OpenArena
+        Osirion
+        Q3
+        Quake2
+        Quake
+        Quetoo
+        Tremulous
+        UFOAI
+        Unvanquished
+        Warsow
+        Xonotic
+        )
+unset(_tmp)
+foreach (it ${GAME_FILES})
+    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}
+        OPTIONAL
+)