aboutsummaryrefslogtreecommitdiff
path: root/cmake/macros
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/macros')
-rw-r--r--cmake/macros/AutoCollect.cmake71
-rw-r--r--cmake/macros/ConfigureBoost.cmake53
-rw-r--r--cmake/macros/ConfigureScripts.cmake104
-rw-r--r--cmake/macros/FindPCHSupport.cmake42
-rw-r--r--cmake/macros/FindReadline.cmake18
-rw-r--r--cmake/macros/GroupSources.cmake9
6 files changed, 219 insertions, 78 deletions
diff --git a/cmake/macros/AutoCollect.cmake b/cmake/macros/AutoCollect.cmake
new file mode 100644
index 00000000000..cddd3a20290
--- /dev/null
+++ b/cmake/macros/AutoCollect.cmake
@@ -0,0 +1,71 @@
+# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# Collects all source files into the given variable,
+# which is useful to include all sources in subdirectories.
+# Ignores full qualified directories listed in the variadic arguments.
+#
+# Use it like:
+# CollectSourceFiles(
+# ${CMAKE_CURRENT_SOURCE_DIR}
+# COMMON_PRIVATE_SOURCES
+# # Exclude
+# ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders
+# ${CMAKE_CURRENT_SOURCE_DIR}/Platform)
+#
+function(CollectSourceFiles current_dir variable)
+ list(FIND ARGN "${current_dir}" IS_EXCLUDED)
+ if(IS_EXCLUDED EQUAL -1)
+ file(GLOB COLLECTED_SOURCES
+ ${current_dir}/*.c
+ ${current_dir}/*.cc
+ ${current_dir}/*.cpp
+ ${current_dir}/*.inl
+ ${current_dir}/*.def
+ ${current_dir}/*.h
+ ${current_dir}/*.hh
+ ${current_dir}/*.hpp)
+ list(APPEND ${variable} ${COLLECTED_SOURCES})
+
+ file(GLOB SUB_DIRECTORIES ${current_dir}/*)
+ foreach(SUB_DIRECTORY ${SUB_DIRECTORIES})
+ if (IS_DIRECTORY ${SUB_DIRECTORY})
+ CollectSourceFiles("${SUB_DIRECTORY}" "${variable}" "${ARGN}")
+ endif()
+ endforeach()
+ set(${variable} ${${variable}} PARENT_SCOPE)
+ endif()
+endfunction()
+
+# Collects all subdirectoroies into the given variable,
+# which is useful to include all subdirectories.
+# Ignores full qualified directories listed in the variadic arguments.
+#
+# Use it like:
+# CollectIncludeDirectories(
+# ${CMAKE_CURRENT_SOURCE_DIR}
+# COMMON_PUBLIC_INCLUDES
+# # Exclude
+# ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders
+# ${CMAKE_CURRENT_SOURCE_DIR}/Platform)
+#
+function(CollectIncludeDirectories current_dir variable)
+ list(FIND ARGN "${current_dir}" IS_EXCLUDED)
+ if(IS_EXCLUDED EQUAL -1)
+ list(APPEND ${variable} ${current_dir})
+ file(GLOB SUB_DIRECTORIES ${current_dir}/*)
+ foreach(SUB_DIRECTORY ${SUB_DIRECTORIES})
+ if (IS_DIRECTORY ${SUB_DIRECTORY})
+ CollectIncludeDirectories("${SUB_DIRECTORY}" "${variable}" "${ARGN}")
+ endif()
+ endforeach()
+ set(${variable} ${${variable}} PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/cmake/macros/ConfigureBoost.cmake b/cmake/macros/ConfigureBoost.cmake
deleted file mode 100644
index b3a71b8a682..00000000000
--- a/cmake/macros/ConfigureBoost.cmake
+++ /dev/null
@@ -1,53 +0,0 @@
-if(WIN32)
- set(BOOST_DEBUG ON)
- if(DEFINED ENV{BOOST_ROOT})
- set(BOOST_ROOT $ENV{BOOST_ROOT})
- if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0)
- set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib${PLATFORM}-msvc-12.0)
- else()
- set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib${PLATFORM}-msvc-14.0)
- endif()
- else()
- message(FATAL_ERROR "No BOOST_ROOT environment variable could be found! Please make sure it is set and the points to your Boost installation.")
- endif()
-
- set(Boost_USE_STATIC_LIBS ON)
- set(Boost_USE_MULTITHREADED ON)
- set(Boost_USE_STATIC_RUNTIME OFF)
-
- add_definitions(-D_WIN32_WINNT=0x0601)
-endif()
-
-find_package(Boost 1.49 REQUIRED system filesystem thread program_options iostreams regex)
-add_definitions(-DBOOST_DATE_TIME_NO_LIB)
-add_definitions(-DBOOST_REGEX_NO_LIB)
-add_definitions(-DBOOST_CHRONO_NO_LIB)
-
-# Find if Boost was compiled in C++03 mode because it requires -DBOOST_NO_CXX11_SCOPED_ENUMS
-
-include (CheckCXXSourceCompiles)
-
-set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR})
-set(CMAKE_REQUIRED_LIBRARIES ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_IOSTREAMS_LIBRARY})
-set(CMAKE_REQUIRED_FLAGS "-std=c++11")
-unset(boost_filesystem_copy_links_without_NO_SCOPED_ENUM CACHE)
-check_cxx_source_compiles("
- #include <boost/filesystem/path.hpp>
- #include <boost/filesystem/operations.hpp>
- int main() { boost::filesystem::copy_file(boost::filesystem::path(), boost::filesystem::path()); }"
-boost_filesystem_copy_links_without_NO_SCOPED_ENUM)
-unset(CMAKE_REQUIRED_INCLUDES CACHE)
-unset(CMAKE_REQUIRED_LIBRARIES CACHE)
-unset(CMAKE_REQUIRED_FLAGS CACHE)
-
-if (NOT boost_filesystem_copy_links_without_NO_SCOPED_ENUM)
- if (Boost_VERSION LESS 105100) # 1.51
- add_definitions(-DBOOST_NO_SCOPED_ENUMS)
- else()
- add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)
- endif()
-endif()
-
-if(Boost_FOUND)
- include_directories(${Boost_INCLUDE_DIRS})
-endif()
diff --git a/cmake/macros/ConfigureScripts.cmake b/cmake/macros/ConfigureScripts.cmake
new file mode 100644
index 00000000000..5260d3a1afe
--- /dev/null
+++ b/cmake/macros/ConfigureScripts.cmake
@@ -0,0 +1,104 @@
+# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# Returns the base path to the script directory in the source directory
+function(WarnAboutSpacesInBuildPath)
+ # Only check win32 since unix doesn't allow spaces in paths
+ if (WIN32)
+ string(FIND "${CMAKE_BINARY_DIR}" " " SPACE_INDEX_POS)
+
+ if (SPACE_INDEX_POS GREATER -1)
+ message("")
+ message(WARNING " *** WARNING!\n"
+ " *** Your selected build directory contains spaces!\n"
+ " *** Please note that this will cause issues!")
+ endif()
+ endif()
+endfunction()
+
+# Returns the base path to the script directory in the source directory
+function(GetScriptsBasePath variable)
+ set(${variable} "${CMAKE_SOURCE_DIR}/src/server/scripts" PARENT_SCOPE)
+endfunction()
+
+# Stores the absolut path of the given module in the variable
+function(GetPathToScriptModule module variable)
+ GetScriptsBasePath(SCRIPTS_BASE_PATH)
+ set(${variable} "${SCRIPTS_BASE_PATH}/${module}" PARENT_SCOPE)
+endfunction()
+
+# Stores the project name of the given module in the variable
+function(GetProjectNameOfScriptModule module variable)
+ string(TOLOWER "scripts_${SCRIPT_MODULE}" GENERATED_NAME)
+ set(${variable} "${GENERATED_NAME}" PARENT_SCOPE)
+endfunction()
+
+# Creates a list of all script modules
+# and stores it in the given variable.
+function(GetScriptModuleList variable)
+ GetScriptsBasePath(BASE_PATH)
+ file(GLOB LOCALE_SCRIPT_MODULE_LIST RELATIVE
+ ${BASE_PATH}
+ ${BASE_PATH}/*)
+
+ set(${variable})
+ foreach(SCRIPT_MODULE ${LOCALE_SCRIPT_MODULE_LIST})
+ GetPathToScriptModule(${SCRIPT_MODULE} SCRIPT_MODULE_PATH)
+ if (IS_DIRECTORY ${SCRIPT_MODULE_PATH})
+ list(APPEND ${variable} ${SCRIPT_MODULE})
+ endif()
+ endforeach()
+ set(${variable} ${${variable}} PARENT_SCOPE)
+endfunction()
+
+# Converts the given script module name into it's
+# variable name which holds the linkage type.
+function(ScriptModuleNameToVariable module variable)
+ string(TOUPPER ${module} ${variable})
+ set(${variable} "SCRIPTS_${${variable}}")
+ set(${variable} ${${variable}} PARENT_SCOPE)
+endfunction()
+
+# Stores in the given variable whether dynamic linking is required
+function(IsDynamicLinkingRequired variable)
+ if(SCRIPTS MATCHES "dynamic")
+ set(IS_DEFAULT_VALUE_DYNAMIC ON)
+ endif()
+
+ GetScriptModuleList(SCRIPT_MODULE_LIST)
+ set(IS_REQUIRED OFF)
+ foreach(SCRIPT_MODULE ${SCRIPT_MODULE_LIST})
+ ScriptModuleNameToVariable(${SCRIPT_MODULE} SCRIPT_MODULE_VARIABLE)
+ if ((${SCRIPT_MODULE_VARIABLE} STREQUAL "dynamic") OR
+ (${SCRIPT_MODULE_VARIABLE} STREQUAL "default" AND IS_DEFAULT_VALUE_DYNAMIC))
+ set(IS_REQUIRED ON)
+ break()
+ endif()
+ endforeach()
+ set(${variable} ${IS_REQUIRED} PARENT_SCOPE)
+endfunction()
+
+# Stores the native variable name
+function(GetNativeSharedLibraryName module variable)
+ if(WIN32)
+ set(${variable} "${module}.dll" PARENT_SCOPE)
+ else()
+ set(${variable} "lib${module}.so" PARENT_SCOPE)
+ endif()
+endfunction()
+
+# Stores the native install path in the variable
+function(GetInstallOffset variable)
+ if(WIN32)
+ set(${variable} "${CMAKE_INSTALL_PREFIX}/scripts" PARENT_SCOPE)
+ else()
+ set(${variable} "${CMAKE_INSTALL_PREFIX}/bin/scripts" PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/cmake/macros/FindPCHSupport.cmake b/cmake/macros/FindPCHSupport.cmake
index 49d4be904d1..9cc39a13b04 100644
--- a/cmake/macros/FindPCHSupport.cmake
+++ b/cmake/macros/FindPCHSupport.cmake
@@ -1,17 +1,49 @@
-FUNCTION(GET_COMMON_PCH_PARAMS PCH_HEADER PCH_FE INCLUDE_PREFIX)
+FUNCTION(GET_COMMON_PCH_PARAMS TARGET_NAME_LIST PCH_HEADER PCH_FE INCLUDE_PREFIX)
GET_FILENAME_COMPONENT(PCH_HEADER_N ${PCH_HEADER} NAME)
GET_DIRECTORY_PROPERTY(TARGET_INCLUDES INCLUDE_DIRECTORIES)
+ # Stores the inherited dependency definitions and include directories
+ # from the given target into the given variables
+ MACRO(CollectIncludes target inherited_includes inherited_definitions)
+ # Append the includes and definitions of the current target to the list
+ get_property(included TARGET ${target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
+ LIST(APPEND "${inherited_includes}" ${included})
+ get_property(definitions TARGET ${target} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
+ FOREACH(def ${definitions})
+ LIST(APPEND "${inherited_definitions}" "-D${def}")
+ ENDFOREACH()
+ # Add all inherited link targets which weren't included already
+ get_property(links TARGET ${target} PROPERTY INTERFACE_LINK_LIBRARIES)
+ # TODO Maybe catch circular dependencies?
+ FOREACH(target_link ${links})
+ IF(TARGET ${target_link})
+ CollectIncludes(${target_link} "${inherited_includes}" "${inherited_definitions}")
+ ENDIF()
+ ENDFOREACH()
+ ENDMACRO()
+
+ FOREACH(TARGET_NAME ${TARGET_NAME_LIST})
+ CollectIncludes(${TARGET_NAME} TARGET_INCLUDES TARGET_DEFINITIONS)
+ ENDFOREACH()
+
+ LIST(REMOVE_DUPLICATES TARGET_INCLUDES)
+ LIST(REMOVE_DUPLICATES TARGET_DEFINITIONS)
+
FOREACH(ITEM ${TARGET_INCLUDES})
LIST(APPEND INCLUDE_FLAGS_LIST "${INCLUDE_PREFIX}\"${ITEM}\" ")
ENDFOREACH(ITEM)
+ SET(PCH_INCLUDES ${TARGET_INCLUDES} PARENT_SCOPE)
+ SET(PCH_DEFINITIONS ${TARGET_DEFINITIONS} PARENT_SCOPE)
SET(PCH_HEADER_NAME ${PCH_HEADER_N} PARENT_SCOPE)
SET(PCH_HEADER_OUT ${CMAKE_CURRENT_BINARY_DIR}/${PCH_HEADER_N}.${PCH_FE} PARENT_SCOPE)
SET(INCLUDE_FLAGS ${INCLUDE_FLAGS_LIST} PARENT_SCOPE)
ENDFUNCTION(GET_COMMON_PCH_PARAMS)
FUNCTION(GENERATE_CXX_PCH_COMMAND TARGET_NAME_LIST INCLUDE_FLAGS IN PCH_SRC OUT)
+ include_directories(${PCH_INCLUDES})
+ add_definitions(${PCH_DEFINITIONS})
+
IF (CMAKE_BUILD_TYPE)
STRING(TOUPPER _${CMAKE_BUILD_TYPE} CURRENT_BUILD_TYPE)
ENDIF ()
@@ -62,7 +94,7 @@ FUNCTION(GENERATE_CXX_PCH_COMMAND TARGET_NAME_LIST INCLUDE_FLAGS IN PCH_SRC OUT)
ENDFUNCTION(GENERATE_CXX_PCH_COMMAND)
FUNCTION(ADD_CXX_PCH_GCC TARGET_NAME_LIST PCH_HEADER PCH_SOURCE)
- GET_COMMON_PCH_PARAMS(${PCH_HEADER} "gch" "-I")
+ GET_COMMON_PCH_PARAMS("${TARGET_NAME_LIST}" ${PCH_HEADER} "gch" "-I")
GENERATE_CXX_PCH_COMMAND("${TARGET_NAME_LIST}" "${INCLUDE_FLAGS}" ${PCH_HEADER} ${PCH_SOURCE} ${PCH_HEADER_OUT})
FOREACH(TARGET_NAME ${TARGET_NAME_LIST})
@@ -74,7 +106,7 @@ FUNCTION(ADD_CXX_PCH_GCC TARGET_NAME_LIST PCH_HEADER PCH_SOURCE)
ENDFUNCTION(ADD_CXX_PCH_GCC)
FUNCTION(ADD_CXX_PCH_CLANG TARGET_NAME_LIST PCH_HEADER PCH_SOURCE)
- GET_COMMON_PCH_PARAMS(${PCH_HEADER} "pch" "-I")
+ GET_COMMON_PCH_PARAMS("${TARGET_NAME_LIST}" ${PCH_HEADER} "pch" "-I")
GENERATE_CXX_PCH_COMMAND("${TARGET_NAME_LIST}" "${INCLUDE_FLAGS}" ${PCH_HEADER} ${PCH_SOURCE} ${PCH_HEADER_OUT})
FOREACH(TARGET_NAME ${TARGET_NAME_LIST})
@@ -86,7 +118,7 @@ FUNCTION(ADD_CXX_PCH_CLANG TARGET_NAME_LIST PCH_HEADER PCH_SOURCE)
ENDFUNCTION(ADD_CXX_PCH_CLANG)
FUNCTION(ADD_CXX_PCH_MSVC TARGET_NAME_LIST PCH_HEADER PCH_SOURCE)
- GET_COMMON_PCH_PARAMS(${PCH_HEADER} "pch" "/I")
+ GET_COMMON_PCH_PARAMS("${TARGET_NAME_LIST}" ${PCH_HEADER} "pch" "/I")
FOREACH(TARGET_NAME ${TARGET_NAME_LIST})
SET_TARGET_PROPERTIES(
@@ -111,7 +143,7 @@ FUNCTION(ADD_CXX_PCH_XCODE TARGET_NAME_LIST PCH_HEADER PCH_SOURCE)
ENDFUNCTION(ADD_CXX_PCH_XCODE)
FUNCTION(ADD_CXX_PCH TARGET_NAME_LIST PCH_HEADER PCH_SOURCE)
- IF (MSVC)
+ IF (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
ADD_CXX_PCH_MSVC("${TARGET_NAME_LIST}" ${PCH_HEADER} ${PCH_SOURCE})
ELSEIF ("${CMAKE_GENERATOR}" MATCHES "Xcode")
ADD_CXX_PCH_XCODE("${TARGET_NAME_LIST}" ${PCH_HEADER} ${PCH_SOURCE})
diff --git a/cmake/macros/FindReadline.cmake b/cmake/macros/FindReadline.cmake
deleted file mode 100644
index 34af35204b5..00000000000
--- a/cmake/macros/FindReadline.cmake
+++ /dev/null
@@ -1,18 +0,0 @@
-# find Readline (terminal input library) includes and library
-#
-# READLINE_INCLUDE_DIR - where the directory containing the READLINE headers can be found
-# READLINE_LIBRARY - full path to the READLINE library
-# READLINE_FOUND - TRUE if READLINE was found
-
-FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h)
-FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
-
-IF (READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
- SET(READLINE_FOUND TRUE)
- MESSAGE(STATUS "Found Readline library: ${READLINE_LIBRARY}")
- MESSAGE(STATUS "Include dir is: ${READLINE_INCLUDE_DIR}")
- INCLUDE_DIRECTORIES(${READLINE_INCLUDE_DIR})
-ELSE (READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
- SET(READLINE_FOUND FALSE)
- MESSAGE(FATAL_ERROR "** Readline library not found!\n** Your distro may provide a binary for Readline e.g. for ubuntu try apt-get install libreadline5-dev")
-ENDIF (READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
diff --git a/cmake/macros/GroupSources.cmake b/cmake/macros/GroupSources.cmake
index 198d8c3e187..f8e252fe41a 100644
--- a/cmake/macros/GroupSources.cmake
+++ b/cmake/macros/GroupSources.cmake
@@ -10,7 +10,7 @@
macro(GroupSources dir)
# Skip this if WITH_SOURCE_TREE is not set (empty string).
- if (NOT ${_WITH_SOURCE_TREE} STREQUAL "")
+ if (NOT ${WITH_SOURCE_TREE} STREQUAL "")
# Include all header and c files
file(GLOB_RECURSE elements RELATIVE ${dir} *.h *.hpp *.c *.cpp *.cc)
@@ -21,7 +21,7 @@ macro(GroupSources dir)
if (NOT ${element_dir} STREQUAL "")
# If the file is in a subdirectory use it as source group.
- if (${_WITH_SOURCE_TREE} STREQUAL "flat")
+ if (${WITH_SOURCE_TREE} STREQUAL "flat")
# Build flat structure by using only the first subdirectory.
string(FIND ${element_dir} "/" delemiter_pos)
if (NOT ${delemiter_pos} EQUAL -1)
@@ -44,3 +44,8 @@ macro(GroupSources dir)
endforeach()
endif()
endmacro()
+
+if (WITH_SOURCE_TREE STREQUAL "hierarchical-folders")
+ # Use folders
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+endif()