CMake: Use source_groups to represent the source tree (#1247)

This commit is contained in:
Kargatum
2019-01-10 11:20:32 +07:00
committed by Viste(Кирилл)
parent 82baf637f6
commit c00d5fe0ab
9 changed files with 107 additions and 31 deletions

View File

@@ -81,6 +81,7 @@ if( NOPCH )
endif() endif()
include(CheckPlatform) include(CheckPlatform)
include(GroupSources)
# basic packagesearching and setup (further support will be needed, this is a preliminary release!) # basic packagesearching and setup (further support will be needed, this is a preliminary release!)
set(OPENSSL_EXPECTED_VERSION 1.0.0) set(OPENSSL_EXPECTED_VERSION 1.0.0)

View File

@@ -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_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_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) 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)

View File

@@ -0,0 +1,46 @@
# Copyright (C) 2008-2018 TrinityCore <https://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.
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()

View File

@@ -94,7 +94,7 @@ if ( WITHOUT_GIT )
message(" *** version of git for the revision-hash to work, and be allowede to ask for") message(" *** version of git for the revision-hash to work, and be allowede to ask for")
message(" *** support if needed.") message(" *** support if needed.")
else() else()
message("* Use GIT revision hash : Yes") message("* Use GIT revision hash : Yes (default)")
endif() endif()
if ( NOJEM ) if ( NOJEM )
@@ -128,5 +128,15 @@ else()
message("* Enable extra logging functions : No (default)") message("* Enable extra logging functions : No (default)")
endif() 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("") message("")

View File

@@ -78,6 +78,9 @@ include_directories(
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}
) )
# Group sources
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_library(shared STATIC add_library(shared STATIC
${shared_STAT_SRCS} ${shared_STAT_SRCS}
${shared_STAT_PCH_SRC} ${shared_STAT_PCH_SRC}

View File

@@ -61,6 +61,9 @@ include_directories(
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}
) )
# Group sources
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(authserver add_executable(authserver
${authserver_SRCS} ${authserver_SRCS}
${authserver_PCH_SRC} ${authserver_PCH_SRC}

View File

@@ -213,6 +213,9 @@ include_directories(
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}
) )
# Group sources
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_library(game STATIC add_library(game STATIC
${game_STAT_SRCS} ${game_STAT_SRCS}
${game_STAT_PCH_SRC} ${game_STAT_PCH_SRC}

View File

@@ -180,6 +180,9 @@ include_directories(
${MYSQL_INCLUDE_DIR} ${MYSQL_INCLUDE_DIR}
) )
# Group sources
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_library(scripts STATIC add_library(scripts STATIC
${scripts_STAT_SRCS} ${scripts_STAT_SRCS}
${scripts_STAT_PCH_SRC} ${scripts_STAT_PCH_SRC}

View File

@@ -153,6 +153,9 @@ add_executable(worldserver
${worldserver_PCH_SRC} ${worldserver_PCH_SRC}
) )
# Group sources
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
if( NOT WIN32 ) if( NOT WIN32 )
set_target_properties(worldserver PROPERTIES set_target_properties(worldserver PROPERTIES
COMPILE_DEFINITIONS _TRINITY_CORE_CONFIG="${CONF_DIR}/worldserver.conf" COMPILE_DEFINITIONS _TRINITY_CORE_CONFIG="${CONF_DIR}/worldserver.conf"