From c00d5fe0ab4fed85783dca5e484954647a31a9b5 Mon Sep 17 00:00:00 2001 From: Kargatum Date: Thu, 10 Jan 2019 11:20:32 +0700 Subject: [PATCH] CMake: Use source_groups to represent the source tree (#1247) --- CMakeLists.txt | 1 + conf/config.cmake.dist | 4 ++ src/cmake/macros/GroupSources.cmake | 46 +++++++++++++++++ src/cmake/showoptions.cmake | 72 +++++++++++++++------------ src/common/CMakeLists.txt | 3 ++ src/server/authserver/CMakeLists.txt | 3 ++ src/server/game/CMakeLists.txt | 3 ++ src/server/scripts/CMakeLists.txt | 3 ++ src/server/worldserver/CMakeLists.txt | 3 ++ 9 files changed, 107 insertions(+), 31 deletions(-) create mode 100644 src/cmake/macros/GroupSources.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index eee5bb371..8cbeb4ed9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ if( NOPCH ) endif() include(CheckPlatform) +include(GroupSources) # basic packagesearching and setup (further support will be needed, this is a preliminary release!) set(OPENSSL_EXPECTED_VERSION 1.0.0) diff --git a/conf/config.cmake.dist b/conf/config.cmake.dist index 5884963ac..19e6c4c2a 100644 --- a/conf/config.cmake.dist +++ b/conf/config.cmake.dist @@ -11,3 +11,7 @@ option(WITHOUT_GIT "Disable the GIT testing routines" option(ENABLE_EXTRAS "Set to 0 to disable extra features optimizing performances" 1) option(ENABLE_VMAP_CHECKS "Enable Checks relative to DisableMgr system on vmap" 1) option(ENABLE_EXTRA_LOGS "Enable extra log functions that can be CPU intensive" 0) + +# Source tree in IDE +set(WITH_SOURCE_TREE "hierarchical" CACHE STRING "Build the source tree for IDE's.") +set_property(CACHE WITH_SOURCE_TREE PROPERTY STRINGS no flat hierarchical) diff --git a/src/cmake/macros/GroupSources.cmake b/src/cmake/macros/GroupSources.cmake new file mode 100644 index 000000000..071451f08 --- /dev/null +++ b/src/cmake/macros/GroupSources.cmake @@ -0,0 +1,46 @@ +# Copyright (C) 2008-2018 TrinityCore +# +# 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. + +macro(GroupSources dir) + # Skip this if WITH_SOURCE_TREE is not set (empty string). + if (NOT ${WITH_SOURCE_TREE} STREQUAL "") + # Include all header and c files + file(GLOB_RECURSE elements RELATIVE ${dir} *.h *.hpp *.c *.cpp *.cc) + + foreach(element ${elements}) + # Extract filename and directory + get_filename_component(element_name ${element} NAME) + get_filename_component(element_dir ${element} DIRECTORY) + + if (NOT ${element_dir} STREQUAL "") + # If the file is in a subdirectory use it as source group. + 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) + string(SUBSTRING ${element_dir} 0 ${delemiter_pos} group_name) + source_group("${group_name}" FILES ${dir}/${element}) + else() + # Build hierarchical structure. + # File is in root directory. + source_group("${element_dir}" FILES ${dir}/${element}) + endif() + else() + # Use the full hierarchical structure to build source_groups. + string(REPLACE "/" "\\" group_name ${element_dir}) + source_group("${group_name}" FILES ${dir}/${element}) + endif() + else() + # If the file is in the root directory, place it in the root source_group. + source_group("\\" FILES ${dir}/${element}) + endif() + endforeach() + endif() +endmacro() \ No newline at end of file diff --git a/src/cmake/showoptions.cmake b/src/cmake/showoptions.cmake index 1ec0e8754..1d0b4bcb6 100644 --- a/src/cmake/showoptions.cmake +++ b/src/cmake/showoptions.cmake @@ -1,19 +1,19 @@ # output generic information about the core and buildtype chosen message("") -message("* AzerothCore revision : ${rev_hash} ${rev_date} (${rev_branch} branch)") +message("* AzerothCore revision : ${rev_hash} ${rev_date} (${rev_branch} branch)") if( UNIX ) - message("* AzerothCore buildtype : ${CMAKE_BUILD_TYPE}") + message("* AzerothCore buildtype : ${CMAKE_BUILD_TYPE}") endif() message("") # output information about installation-directories and locations -message("* Install core to : ${CMAKE_INSTALL_PREFIX}") +message("* Install core to : ${CMAKE_INSTALL_PREFIX}") if( UNIX ) - message("* Install libraries to : ${LIBSDIR}") + message("* Install libraries to : ${LIBSDIR}") endif() -message("* Install configs to : ${CONF_DIR}") +message("* Install configs to : ${CONF_DIR}") add_definitions(-D_CONF_DIR="\\"${CONF_DIR}\\"") message("") @@ -21,69 +21,69 @@ message("") # Show infomation about the options selected during configuration if( SERVERS ) - message("* Build world/auth : Yes (default)") + message("* Build world/auth : Yes (default)") else() - message("* Build world/authserver : No") + message("* Build world/authserver : No") endif() if( SCRIPTS ) - message("* Build with scripts : Yes (default)") + message("* Build with scripts : Yes (default)") add_definitions(-DSCRIPTS) else() - message("* Build with scripts : No") + message("* Build with scripts : No") endif() if( TOOLS ) - message("* Build map/vmap tools : Yes") + message("* Build map/vmap tools : Yes") add_definitions(-DNO_CORE_FUNCS) else() - message("* Build map/vmap tools : No (default)") + message("* Build map/vmap tools : No (default)") endif() if( USE_COREPCH ) - message("* Build core w/PCH : Yes (default)") + message("* Build core w/PCH : Yes (default)") else() - message("* Build core w/PCH : No") + message("* Build core w/PCH : No") endif() if( USE_SCRIPTPCH ) - message("* Build scripts w/PCH : Yes (default)") + message("* Build scripts w/PCH : Yes (default)") else() - message("* Build scripts w/PCH : No") + message("* Build scripts w/PCH : No") endif() if( WITH_WARNINGS ) - message("* Show all warnings : Yes") + message("* Show all warnings : Yes") else() - message("* Show compile-warnings : No (default)") + message("* Show compile-warnings : No (default)") endif() if( WITH_COREDEBUG ) - message("* Use coreside debug : Yes") + message("* Use coreside debug : Yes") add_definitions(-DTRINITY_DEBUG) else() - message("* Use coreside debug : No (default)") + message("* Use coreside debug : No (default)") endif() if ( UNIX ) if( WITH_PERFTOOLS ) - message("* Use unix gperftools : Yes") + message("* Use unix gperftools : Yes") add_definitions(-DPERF_TOOLS) else() - message("* Use unix gperftools : No (default)") + message("* Use unix gperftools : No (default)") endif() endif( UNIX ) if( WIN32 ) if( USE_MYSQL_SOURCES ) - message("* Use MySQL sourcetree : Yes (default)") + message("* Use MySQL sourcetree : Yes (default)") else() - message("* Use MySQL sourcetree : No") + message("* Use MySQL sourcetree : No") endif() endif( WIN32 ) if ( WITHOUT_GIT ) - message("* Use GIT revision hash : No") + message("* Use GIT revision hash : No") message("") message(" *** WITHOUT_GIT - WARNING!") message(" *** By choosing the WITHOUT_GIT option you have waived all rights for support,") @@ -94,7 +94,7 @@ if ( WITHOUT_GIT ) message(" *** version of git for the revision-hash to work, and be allowede to ask for") message(" *** support if needed.") else() - message("* Use GIT revision hash : Yes") + message("* Use GIT revision hash : Yes (default)") endif() if ( NOJEM ) @@ -108,24 +108,34 @@ endif() # Performance optimization options: if( ENABLE_EXTRAS ) - message("* Enable extra features : Yes (default)") + message("* Enable extra features : Yes (default)") add_definitions(-DENABLE_EXTRAS) else() - message("* Enable extra features : No") + message("* Enable extra features : No") endif() if( ENABLE_VMAP_CHECKS ) - message("* Enable vmap DisableMgr checks : Yes (default)") + message("* Enable vmap DisableMgr checks : Yes (default)") add_definitions(-DENABLE_VMAP_CHECKS) else() - message("* Enable vmap DisableMgr checks : No") + message("* Enable vmap DisableMgr checks : No") endif() if( ENABLE_EXTRA_LOGS ) - message("* Enable extra logging functions : Yes") + message("* Enable extra logging functions : Yes") add_definitions(-DENABLE_EXTRA_LOGS) else() - message("* Enable extra logging functions : No (default)") + message("* Enable extra logging functions : No (default)") +endif() + +if(WIN32 AND NOT CMAKE_VERSION VERSION_LESS 2.8.12) + if(NOT WITH_SOURCE_TREE STREQUAL "no") + message("* Show source tree : Yes - \"${WITH_SOURCE_TREE}\"") + else() + message("* Show source tree : No") + endif() +else() + message("* Show source tree : No (For UNIX default)") endif() message("") diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 9a44d3302..8cd73a9ff 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -78,6 +78,9 @@ include_directories( ${OPENSSL_INCLUDE_DIR} ) +# Group sources +GroupSources(${CMAKE_CURRENT_SOURCE_DIR}) + add_library(shared STATIC ${shared_STAT_SRCS} ${shared_STAT_PCH_SRC} diff --git a/src/server/authserver/CMakeLists.txt b/src/server/authserver/CMakeLists.txt index 65c4ed58e..d3e18971b 100644 --- a/src/server/authserver/CMakeLists.txt +++ b/src/server/authserver/CMakeLists.txt @@ -61,6 +61,9 @@ include_directories( ${OPENSSL_INCLUDE_DIR} ) +# Group sources +GroupSources(${CMAKE_CURRENT_SOURCE_DIR}) + add_executable(authserver ${authserver_SRCS} ${authserver_PCH_SRC} diff --git a/src/server/game/CMakeLists.txt b/src/server/game/CMakeLists.txt index 2b4f7c26a..e0ed81cca 100644 --- a/src/server/game/CMakeLists.txt +++ b/src/server/game/CMakeLists.txt @@ -213,6 +213,9 @@ include_directories( ${OPENSSL_INCLUDE_DIR} ) +# Group sources +GroupSources(${CMAKE_CURRENT_SOURCE_DIR}) + add_library(game STATIC ${game_STAT_SRCS} ${game_STAT_PCH_SRC} diff --git a/src/server/scripts/CMakeLists.txt b/src/server/scripts/CMakeLists.txt index a3373a007..fec3de1ec 100644 --- a/src/server/scripts/CMakeLists.txt +++ b/src/server/scripts/CMakeLists.txt @@ -180,6 +180,9 @@ include_directories( ${MYSQL_INCLUDE_DIR} ) +# Group sources +GroupSources(${CMAKE_CURRENT_SOURCE_DIR}) + add_library(scripts STATIC ${scripts_STAT_SRCS} ${scripts_STAT_PCH_SRC} diff --git a/src/server/worldserver/CMakeLists.txt b/src/server/worldserver/CMakeLists.txt index 37777822c..7fd1ebd96 100644 --- a/src/server/worldserver/CMakeLists.txt +++ b/src/server/worldserver/CMakeLists.txt @@ -153,6 +153,9 @@ add_executable(worldserver ${worldserver_PCH_SRC} ) +# Group sources +GroupSources(${CMAKE_CURRENT_SOURCE_DIR}) + if( NOT WIN32 ) set_target_properties(worldserver PROPERTIES COMPILE_DEFINITIONS _TRINITY_CORE_CONFIG="${CONF_DIR}/worldserver.conf"