summaryrefslogtreecommitdiff
path: root/src/cmake
diff options
context:
space:
mode:
authorKargatum <dowlandtop@yandex.com>2022-05-31 17:05:39 +0700
committerGitHub <noreply@github.com>2022-05-31 17:05:39 +0700
commit4fbec972a8fe55d73744205322298791ded0c204 (patch)
tree9b183311815b3a25c46ea11e99c73c548460a0fb /src/cmake
parent40a5eef152addba3949016938519fa61d9776f82 (diff)
refactor(Cmake): add support build selected applications and tools (#11836)
Diffstat (limited to 'src/cmake')
-rw-r--r--src/cmake/macros/ConfigInstall.cmake44
-rw-r--r--src/cmake/macros/ConfigureApplications.cmake108
-rw-r--r--src/cmake/macros/ConfigureTools.cmake110
-rw-r--r--src/cmake/showoptions.cmake25
4 files changed, 268 insertions, 19 deletions
diff --git a/src/cmake/macros/ConfigInstall.cmake b/src/cmake/macros/ConfigInstall.cmake
index 8dc97a8e6a..836ec610c8 100644
--- a/src/cmake/macros/ConfigInstall.cmake
+++ b/src/cmake/macros/ConfigInstall.cmake
@@ -12,32 +12,62 @@
#
# Use it like:
-# CopyDefaultConfig(worldserver)
+# CopyApplicationConfig(${APP_PROJECT_NAME} ${APPLICATION_NAME})
#
-function(CopyDefaultConfig servertype)
+function(CopyApplicationConfig projectName appName)
+ GetPathToApplication(${appName} SOURCE_APP_PATH)
+
if(WIN32)
if("${CMAKE_MAKE_PROGRAM}" MATCHES "MSBuild")
- add_custom_command(TARGET ${servertype}
+ add_custom_command(TARGET ${projectName}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/configs")
+ add_custom_command(TARGET ${projectName}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy "${SOURCE_APP_PATH}/${appName}.conf.dist" "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/configs")
+ elseif(MINGW)
add_custom_command(TARGET ${servertype}
POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${servertype}.conf.dist" "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/configs")
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/configs")
+ add_custom_command(TARGET ${servertype}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy "${SOURCE_APP_PATH}/${appName}.conf.dist ${CMAKE_BINARY_DIR}/bin/configs")
+ endif()
+ endif()
+
+ if(UNIX)
+ install(FILES "${SOURCE_APP_PATH}/${appName}.conf.dist" DESTINATION "${CONF_DIR}")
+ elseif(WIN32)
+ install(FILES "${SOURCE_APP_PATH}/${appName}.conf.dist" DESTINATION "${CMAKE_INSTALL_PREFIX}/configs")
+ endif()
+endfunction()
+
+function(CopyToolConfig projectName appName)
+ GetPathToTool(${appName} SOURCE_APP_PATH)
+
+ if(WIN32)
+ if("${CMAKE_MAKE_PROGRAM}" MATCHES "MSBuild")
+ add_custom_command(TARGET ${projectName}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/configs")
+ add_custom_command(TARGET ${projectName}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy "${SOURCE_APP_PATH}/${appName}.conf.dist" "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/configs")
elseif(MINGW)
add_custom_command(TARGET ${servertype}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/configs")
add_custom_command(TARGET ${servertype}
POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${servertype}.conf.dist ${CMAKE_BINARY_DIR}/bin/configs")
+ COMMAND ${CMAKE_COMMAND} -E copy "${SOURCE_APP_PATH}/${appName}.conf.dist ${CMAKE_BINARY_DIR}/bin/configs")
endif()
endif()
if(UNIX)
- install(FILES "${servertype}.conf.dist" DESTINATION "${CONF_DIR}")
+ install(FILES "${SOURCE_APP_PATH}/${appName}.conf.dist" DESTINATION "${CONF_DIR}")
elseif(WIN32)
- install(FILES "${servertype}.conf.dist" DESTINATION "${CMAKE_INSTALL_PREFIX}/configs")
+ install(FILES "${SOURCE_APP_PATH}/${appName}.conf.dist" DESTINATION "${CMAKE_INSTALL_PREFIX}/configs")
endif()
endfunction()
diff --git a/src/cmake/macros/ConfigureApplications.cmake b/src/cmake/macros/ConfigureApplications.cmake
new file mode 100644
index 0000000000..38009eb18c
--- /dev/null
+++ b/src/cmake/macros/ConfigureApplications.cmake
@@ -0,0 +1,108 @@
+#
+# This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
+#
+# 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.
+#
+
+set(BUILD_APPLICATION_AUTHSERVER 0)
+set(BUILD_APPLICATION_WORLDSERVER 0)
+
+# Returns the base path to the apps directory in the source directory
+function(GetApplicationsBasePath variable)
+ set(${variable} "${CMAKE_SOURCE_DIR}/src/server/apps" PARENT_SCOPE)
+endfunction()
+
+# Stores the absolut path of the given app in the variable
+function(GetPathToApplication app variable)
+ GetApplicationsBasePath(APPS_BASE_PATH)
+ set(${variable} "${APPS_BASE_PATH}/${app}" PARENT_SCOPE)
+endfunction()
+
+# Stores the project name of the given app in the variable
+function(GetProjectNameOfApplicationName app variable)
+ string(TOLOWER "${app}" GENERATED_NAME)
+ set(${variable} "${GENERATED_NAME}" PARENT_SCOPE)
+endfunction()
+
+# Creates a list of all applications and stores it in the given variable.
+function(GetApplicationsList variable)
+ GetApplicationsBasePath(BASE_PATH)
+ file(GLOB LOCALE_SOURCE_APP_LIST RELATIVE
+ ${BASE_PATH}
+ ${BASE_PATH}/*)
+
+ set(${variable})
+
+ foreach(SOURCE_APP ${LOCALE_SOURCE_APP_LIST})
+ GetPathToApplication(${SOURCE_APP} SOURCE_APP_PATH)
+ if(IS_DIRECTORY ${SOURCE_APP_PATH})
+ list(APPEND ${variable} ${SOURCE_APP})
+ endif()
+ endforeach()
+
+ set(${variable} ${${variable}} PARENT_SCOPE)
+endfunction()
+
+# Converts the given application name into it's
+# variable name which holds the build type.
+function(ApplicationNameToVariable application variable)
+ string(TOUPPER ${application} ${variable})
+ set(${variable} "APP_${${variable}}")
+ set(${variable} ${${variable}} PARENT_SCOPE)
+endfunction()
+
+function(CheckApplicationsBuildList)
+ GetApplicationsList(APPLICATIONS_BUILD_LIST)
+
+ if (APPS_BUILD STREQUAL "none")
+ set(APPS_DEFAULT_BUILD "disabled")
+ else()
+ set(APPS_DEFAULT_BUILD "enabled")
+ endif()
+
+ # Sets BUILD_APPS_USE_WHITELIST
+ # Sets BUILD_APPS_WHITELIST
+ if (APPS_BUILD MATCHES "-only")
+ set(BUILD_APPS_USE_WHITELIST ON)
+
+ if (APPS_BUILD STREQUAL "servers-only")
+ list(APPEND BUILD_APPS_WHITELIST authserver worldserver)
+ endif()
+
+ if (APPS_BUILD STREQUAL "dbimport-only")
+ list(APPEND BUILD_APPS_WHITELIST dbimport)
+ endif()
+ endif()
+
+ foreach(APPLICATION_BUILD_NAME ${APPLICATIONS_BUILD_LIST})
+ ApplicationNameToVariable(${APPLICATION_BUILD_NAME} APPLICATION_BUILD_VARIABLE)
+
+ if(${APPLICATION_BUILD_VARIABLE} STREQUAL "default")
+ if(BUILD_APPS_USE_WHITELIST)
+ list(FIND BUILD_APPS_WHITELIST "${APPLICATION_BUILD_NAME}" INDEX)
+ if(${INDEX} GREATER -1)
+ set(${APPLICATION_BUILD_VARIABLE} ${APPS_DEFAULT_BUILD})
+ else()
+ set(${APPLICATION_BUILD_VARIABLE} "disabled")
+ endif()
+ else()
+ set(${APPLICATION_BUILD_VARIABLE} ${APPS_DEFAULT_BUILD})
+ endif()
+ endif()
+
+ # Build the Graph values
+ if(${APPLICATION_BUILD_VARIABLE} MATCHES "enabled")
+ if (${APPLICATION_BUILD_NAME} MATCHES "authserver")
+ set (BUILD_APPLICATION_AUTHSERVER 1 PARENT_SCOPE)
+ elseif(${APPLICATION_BUILD_NAME} MATCHES "worldserver")
+ set (BUILD_APPLICATION_WORLDSERVER 1 PARENT_SCOPE)
+ endif()
+ endif()
+ endforeach()
+endfunction()
diff --git a/src/cmake/macros/ConfigureTools.cmake b/src/cmake/macros/ConfigureTools.cmake
new file mode 100644
index 0000000000..ece49ab481
--- /dev/null
+++ b/src/cmake/macros/ConfigureTools.cmake
@@ -0,0 +1,110 @@
+#
+# This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
+#
+# 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.
+#
+
+set(BUILD_TOOLS_MAPS 0)
+set(BUILD_TOOLS_DB_IMPORT 0)
+
+# Returns the base path to the tools directory in the source directory
+function(GetToolsBasePath variable)
+ set(${variable} "${CMAKE_SOURCE_DIR}/src/tools" PARENT_SCOPE)
+endfunction()
+
+# Stores the absolut path of the given tool in the variable
+function(GetPathToTool tool variable)
+ GetToolsBasePath(TOOLS_BASE_PATH)
+ set(${variable} "${TOOLS_BASE_PATH}/${tool}" PARENT_SCOPE)
+endfunction()
+
+# Stores the project name of the given tool in the variable
+function(GetProjectNameOfToolName tool variable)
+ string(TOLOWER "${tool}" GENERATED_NAME)
+ set(${variable} "${GENERATED_NAME}" PARENT_SCOPE)
+endfunction()
+
+# Creates a list of all applications and stores it in the given variable.
+function(GetToolsList variable)
+ GetToolsBasePath(BASE_PATH)
+ file(GLOB LOCALE_SOURCE_TOOL_LIST RELATIVE
+ ${BASE_PATH}
+ ${BASE_PATH}/*)
+
+ set(${variable})
+
+ foreach(SOURCE_TOOL ${LOCALE_SOURCE_TOOL_LIST})
+ GetPathToTool(${SOURCE_TOOL} SOURCE_TOOL_PATH)
+ if(IS_DIRECTORY ${SOURCE_TOOL_PATH})
+ list(APPEND ${variable} ${SOURCE_TOOL})
+ endif()
+ endforeach()
+
+ set(${variable} ${${variable}} PARENT_SCOPE)
+endfunction()
+
+# Converts the given application name into it's
+# variable name which holds the build type.
+function(ToolNameToVariable application variable)
+ string(TOUPPER ${application} ${variable})
+ set(${variable} "TOOL_${${variable}}")
+ set(${variable} ${${variable}} PARENT_SCOPE)
+endfunction()
+
+function(CheckToolsBuildList)
+ GetToolsList(TOOLS_BUILD_LIST)
+
+ if (TOOLS_BUILD STREQUAL "none")
+ set(TOOLS_DEFAULT_BUILD "disabled")
+ else()
+ set(TOOLS_DEFAULT_BUILD "enabled")
+ endif()
+
+ # Sets BUILD_TOOLS_USE_WHITELIST
+ # Sets BUILD_TOOLS_WHITELIST
+ if (TOOLS_BUILD MATCHES "-only")
+ set(BUILD_TOOLS_USE_WHITELIST ON)
+
+ if (TOOLS_BUILD STREQUAL "maps-only")
+ list(APPEND BUILD_TOOLS_WHITELIST map_extractor mmaps_generator vmap4_assembler vmap4_extractor)
+ endif()
+
+ # if (TOOLS_BUILD STREQUAL "db-only")
+ # list(APPEND BUILD_TOOLS_WHITELIST dbimport)
+ # endif()
+ endif()
+
+ # Set the TOOL_${TOOL_BUILD_NAME} variables from the
+ # variables set above
+ foreach(TOOL_BUILD_NAME ${TOOLS_BUILD_LIST})
+ ToolNameToVariable(${TOOL_BUILD_NAME} TOOL_BUILD_VARIABLE)
+
+ if (${TOOL_BUILD_VARIABLE} STREQUAL "default")
+ if (BUILD_TOOLS_USE_WHITELIST)
+ list(FIND BUILD_TOOLS_WHITELIST "${TOOL_BUILD_NAME}" INDEX)
+ if (${INDEX} GREATER -1)
+ set(${TOOL_BUILD_VARIABLE} ${TOOLS_DEFAULT_BUILD})
+ else()
+ set(${TOOL_BUILD_VARIABLE} "disabled")
+ endif()
+ else()
+ set(${TOOL_BUILD_VARIABLE} ${TOOLS_DEFAULT_BUILD})
+ endif()
+ endif()
+
+ # Build the Graph values
+ if (${TOOL_BUILD_VARIABLE} MATCHES "enabled")
+ if (${TOOL_BUILD_NAME} MATCHES "dbimport")
+ set(BUILD_TOOLS_DB_IMPORT 1 PARENT_SCOPE)
+ else()
+ set(BUILD_TOOLS_MAPS 1 PARENT_SCOPE)
+ endif()
+ endif()
+ endforeach()
+endfunction()
diff --git a/src/cmake/showoptions.cmake b/src/cmake/showoptions.cmake
index 08467d8df8..7111990b6f 100644
--- a/src/cmake/showoptions.cmake
+++ b/src/cmake/showoptions.cmake
@@ -32,31 +32,32 @@ message("")
# Show infomation about the options selected during configuration
-if( SERVERS )
- message("* Build world/auth : Yes (default)")
+if (APPS_BUILD AND (NOT APPS_BUILD STREQUAL "none"))
+ message("* Build applications : Yes (${APPS_BUILD})")
else()
- message("* Build world/authserver : No")
+ message("* Build applications : No")
endif()
-if(SCRIPTS AND (NOT SCRIPTS STREQUAL "none"))
+if (TOOLS_BUILD AND (NOT TOOLS_BUILD STREQUAL "none"))
+ message("* Build tools : Yes (${TOOLS_BUILD})")
+ add_definitions(-DNO_CORE_FUNCS)
+else()
+ message("* Build tools : No")
+endif()
+
+if (SCRIPTS AND (NOT SCRIPTS STREQUAL "none"))
message("* Build with scripts : Yes (${SCRIPTS})")
+
else()
message("* Build with scripts : No")
endif()
-if(MODULES AND (NOT MODULES STREQUAL "none"))
+if (MODULES AND (NOT MODULES STREQUAL "none"))
message("* Build with modules : Yes (${MODULES})")
else()
message("* Build with modules : No")
endif()
-if( TOOLS )
- message("* Build map/vmap tools : Yes")
- add_definitions(-DNO_CORE_FUNCS)
-else()
- message("* Build map/vmap tools : No (default)")
-endif()
-
if( BUILD_TESTING )
message("* Build unit tests : Yes")
else()