mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-22 05:27:19 +00:00
Add config update function (#1379)
Update CMakeLists.txt FINALLY dont ignore cmake module directory move to separate file very cool feature tested that this still works Co-authored-by: Aaron Kimbrell <aronwk.aaron@gmail.com>
This commit is contained in:
parent
1941679d27
commit
b1134b340f
1
.gitignore
vendored
1
.gitignore
vendored
@ -122,3 +122,4 @@ docker/__pycache__
|
|||||||
docker-compose.override.yml
|
docker-compose.override.yml
|
||||||
|
|
||||||
!*Test.bin
|
!*Test.bin
|
||||||
|
!cmake/*
|
||||||
|
@ -3,6 +3,7 @@ project(Darkflame)
|
|||||||
include(CTest)
|
include(CTest)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
# Read variables from file
|
# Read variables from file
|
||||||
FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables)
|
FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables)
|
||||||
@ -14,14 +15,13 @@ string(REPLACE "\n" ";" variables ${variables})
|
|||||||
foreach(variable ${variables})
|
foreach(variable ${variables})
|
||||||
# If the string contains a #, skip it
|
# If the string contains a #, skip it
|
||||||
if(NOT "${variable}" MATCHES "#")
|
if(NOT "${variable}" MATCHES "#")
|
||||||
|
|
||||||
# Split the variable into name and value
|
# Split the variable into name and value
|
||||||
string(REPLACE "=" ";" variable ${variable})
|
string(REPLACE "=" ";" variable ${variable})
|
||||||
|
|
||||||
# Check that the length of the variable is 2 (name and value)
|
# Check that the length of the variable is 2 (name and value)
|
||||||
list(LENGTH variable length)
|
list(LENGTH variable length)
|
||||||
if(${length} EQUAL 2)
|
|
||||||
|
|
||||||
|
if(${length} EQUAL 2)
|
||||||
list(GET variable 0 variable_name)
|
list(GET variable 0 variable_name)
|
||||||
list(GET variable 1 variable_value)
|
list(GET variable 1 variable_value)
|
||||||
|
|
||||||
@ -53,6 +53,7 @@ set(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "" FORCE)
|
|||||||
if(UNIX)
|
if(UNIX)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -fPIC")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -fPIC")
|
||||||
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0)
|
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0)
|
||||||
|
|
||||||
if(NOT APPLE)
|
if(NOT APPLE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -lstdc++fs")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -lstdc++fs")
|
||||||
endif()
|
endif()
|
||||||
@ -97,11 +98,16 @@ make_directory(${CMAKE_BINARY_DIR}/logs)
|
|||||||
# Copy resource files on first build
|
# Copy resource files on first build
|
||||||
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf")
|
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf")
|
||||||
message(STATUS "Checking resource file integrity")
|
message(STATUS "Checking resource file integrity")
|
||||||
|
|
||||||
|
include(Utils)
|
||||||
|
|
||||||
foreach(resource_file ${RESOURCE_FILES})
|
foreach(resource_file ${RESOURCE_FILES})
|
||||||
set(file_size 0)
|
set(file_size 0)
|
||||||
|
|
||||||
if(EXISTS ${PROJECT_BINARY_DIR}/${resource_file})
|
if(EXISTS ${PROJECT_BINARY_DIR}/${resource_file})
|
||||||
file(SIZE ${PROJECT_BINARY_DIR}/${resource_file} file_size)
|
file(SIZE ${PROJECT_BINARY_DIR}/${resource_file} file_size)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(${file_size} EQUAL 0)
|
if(${file_size} EQUAL 0)
|
||||||
configure_file(
|
configure_file(
|
||||||
${CMAKE_SOURCE_DIR}/resources/${resource_file} ${PROJECT_BINARY_DIR}/${resource_file}
|
${CMAKE_SOURCE_DIR}/resources/${resource_file} ${PROJECT_BINARY_DIR}/${resource_file}
|
||||||
@ -114,30 +120,39 @@ foreach (resource_file ${RESOURCE_FILES})
|
|||||||
string(REPLACE "\\\n" "" current_file_contents ${current_file_contents})
|
string(REPLACE "\\\n" "" current_file_contents ${current_file_contents})
|
||||||
string(REPLACE "\n" ";" current_file_contents ${current_file_contents})
|
string(REPLACE "\n" ";" current_file_contents ${current_file_contents})
|
||||||
set(parsed_current_file_contents "")
|
set(parsed_current_file_contents "")
|
||||||
|
|
||||||
# Remove comment lines so they do not interfere with the variable parsing
|
# Remove comment lines so they do not interfere with the variable parsing
|
||||||
foreach(line ${current_file_contents})
|
foreach(line ${current_file_contents})
|
||||||
string(FIND ${line} "#" is_comment)
|
string(FIND ${line} "#" is_comment)
|
||||||
|
|
||||||
if(NOT ${is_comment} EQUAL 0)
|
if(NOT ${is_comment} EQUAL 0)
|
||||||
string(APPEND parsed_current_file_contents ${line})
|
string(APPEND parsed_current_file_contents ${line})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
file(READ ${CMAKE_SOURCE_DIR}/resources/${resource_file} depot_file_contents)
|
file(READ ${CMAKE_SOURCE_DIR}/resources/${resource_file} depot_file_contents)
|
||||||
string(REPLACE "\\\n" "" depot_file_contents ${depot_file_contents})
|
string(REPLACE "\\\n" "" depot_file_contents ${depot_file_contents})
|
||||||
string(REPLACE "\n" ";" depot_file_contents ${depot_file_contents})
|
string(REPLACE "\n" ";" depot_file_contents ${depot_file_contents})
|
||||||
set(line_to_add "")
|
set(line_to_add "")
|
||||||
|
|
||||||
foreach(line ${depot_file_contents})
|
foreach(line ${depot_file_contents})
|
||||||
string(FIND ${line} "#" is_comment)
|
string(FIND ${line} "#" is_comment)
|
||||||
|
|
||||||
if(NOT ${is_comment} EQUAL 0)
|
if(NOT ${is_comment} EQUAL 0)
|
||||||
string(REPLACE "=" ";" line_split ${line})
|
string(REPLACE "=" ";" line_split ${line})
|
||||||
list(GET line_split 0 variable_name)
|
list(GET line_split 0 variable_name)
|
||||||
|
|
||||||
if(NOT ${parsed_current_file_contents} MATCHES ${variable_name})
|
if(NOT ${parsed_current_file_contents} MATCHES ${variable_name})
|
||||||
message(STATUS "Adding missing config option " ${variable_name} " to " ${resource_file})
|
message(STATUS "Adding missing config option " ${variable_name} " to " ${resource_file})
|
||||||
set(line_to_add ${line_to_add} ${line})
|
set(line_to_add ${line_to_add} ${line})
|
||||||
|
|
||||||
foreach(line_to_append ${line_to_add})
|
foreach(line_to_append ${line_to_add})
|
||||||
file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n" ${line_to_append})
|
file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n" ${line_to_append})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n")
|
file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(line_to_add "")
|
set(line_to_add "")
|
||||||
else()
|
else()
|
||||||
set(line_to_add ${line_to_add} ${line})
|
set(line_to_add ${line_to_add} ${line})
|
||||||
@ -145,6 +160,7 @@ foreach (resource_file ${RESOURCE_FILES})
|
|||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
message(STATUS "Resource file integrity check complete")
|
message(STATUS "Resource file integrity check complete")
|
||||||
|
|
||||||
# if navmeshes directory does not exist, create it
|
# if navmeshes directory does not exist, create it
|
||||||
@ -160,6 +176,7 @@ file(REMOVE ${PROJECT_BINARY_DIR}/navmeshes.zip)
|
|||||||
|
|
||||||
# Copy vanity files on first build
|
# Copy vanity files on first build
|
||||||
set(VANITY_FILES "CREDITS.md" "INFO.md" "TESTAMENT.md" "NPC.xml")
|
set(VANITY_FILES "CREDITS.md" "INFO.md" "TESTAMENT.md" "NPC.xml")
|
||||||
|
|
||||||
foreach(file ${VANITY_FILES})
|
foreach(file ${VANITY_FILES})
|
||||||
configure_file("${CMAKE_SOURCE_DIR}/vanity/${file}" "${CMAKE_BINARY_DIR}/vanity/${file}" COPYONLY)
|
configure_file("${CMAKE_SOURCE_DIR}/vanity/${file}" "${CMAKE_BINARY_DIR}/vanity/${file}" COPYONLY)
|
||||||
endforeach()
|
endforeach()
|
||||||
@ -167,6 +184,7 @@ endforeach()
|
|||||||
# Move our migrations for MasterServer to run
|
# Move our migrations for MasterServer to run
|
||||||
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/migrations/dlu/)
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/migrations/dlu/)
|
||||||
file(GLOB SQL_FILES ${CMAKE_SOURCE_DIR}/migrations/dlu/*.sql)
|
file(GLOB SQL_FILES ${CMAKE_SOURCE_DIR}/migrations/dlu/*.sql)
|
||||||
|
|
||||||
foreach(file ${SQL_FILES})
|
foreach(file ${SQL_FILES})
|
||||||
get_filename_component(file ${file} NAME)
|
get_filename_component(file ${file} NAME)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/migrations/dlu/${file} ${PROJECT_BINARY_DIR}/migrations/dlu/${file})
|
configure_file(${CMAKE_SOURCE_DIR}/migrations/dlu/${file} ${PROJECT_BINARY_DIR}/migrations/dlu/${file})
|
||||||
@ -174,6 +192,7 @@ endforeach()
|
|||||||
|
|
||||||
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/migrations/cdserver/)
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/migrations/cdserver/)
|
||||||
file(GLOB SQL_FILES ${CMAKE_SOURCE_DIR}/migrations/cdserver/*.sql)
|
file(GLOB SQL_FILES ${CMAKE_SOURCE_DIR}/migrations/cdserver/*.sql)
|
||||||
|
|
||||||
foreach(file ${SQL_FILES})
|
foreach(file ${SQL_FILES})
|
||||||
get_filename_component(file ${file} NAME)
|
get_filename_component(file ${file} NAME)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/migrations/cdserver/${file} ${PROJECT_BINARY_DIR}/migrations/cdserver/${file})
|
configure_file(${CMAKE_SOURCE_DIR}/migrations/cdserver/${file} ${PROJECT_BINARY_DIR}/migrations/cdserver/${file})
|
||||||
@ -313,8 +332,8 @@ endforeach()
|
|||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/libbcrypt/include/bcrypt")
|
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/libbcrypt/include/bcrypt")
|
||||||
endif()
|
endif()
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/libbcrypt/include")
|
|
||||||
|
|
||||||
|
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/libbcrypt/include")
|
||||||
|
|
||||||
# Add linking directories:
|
# Add linking directories:
|
||||||
link_directories(${PROJECT_BINARY_DIR})
|
link_directories(${PROJECT_BINARY_DIR})
|
||||||
|
47
cmake/Utils.cmake
Normal file
47
cmake/Utils.cmake
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Parses a config file for a specific option and appends the new option if it does not exist
|
||||||
|
# If the new option does exist, this function will do nothing.
|
||||||
|
# file_name: The name of the file to parse
|
||||||
|
# old_option_name: The name of the option to find
|
||||||
|
# new_option_name: The name of the option to add
|
||||||
|
function(UpdateConfigOption file_name old_option_name new_option_name)
|
||||||
|
string(APPEND old_option_name "=")
|
||||||
|
string(APPEND new_option_name "=")
|
||||||
|
message(STATUS "Checking " ${file_name} " for " ${old_option_name} " and adding " ${new_option_name} " if it does not exist")
|
||||||
|
file(READ ${file_name} current_file_contents)
|
||||||
|
string(REPLACE "\\\n" "" current_file_contents ${current_file_contents})
|
||||||
|
string(REPLACE "\n" ";" current_file_contents ${current_file_contents})
|
||||||
|
set(parsed_current_file_contents "")
|
||||||
|
|
||||||
|
# Remove comment lines so they do not interfere with the variable parsing
|
||||||
|
foreach(line ${current_file_contents})
|
||||||
|
string(FIND ${line} "#" is_comment)
|
||||||
|
|
||||||
|
if(NOT ${is_comment} EQUAL 0)
|
||||||
|
string(APPEND parsed_current_file_contents ${line})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(found_new_option -1)
|
||||||
|
set(found_old_option -1)
|
||||||
|
set(current_value -1)
|
||||||
|
|
||||||
|
foreach(line ${current_file_contents})
|
||||||
|
string(FIND ${line} ${old_option_name} old_option_in_file)
|
||||||
|
|
||||||
|
if(${old_option_in_file} EQUAL 0)
|
||||||
|
set(found_old_option 1)
|
||||||
|
set(current_value ${line})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(FIND ${line} ${new_option_name} found_new_option_in_file)
|
||||||
|
|
||||||
|
if(${found_new_option_in_file} EQUAL 0)
|
||||||
|
set(found_new_option 1)
|
||||||
|
endif()
|
||||||
|
endforeach(line ${current_file_contents})
|
||||||
|
|
||||||
|
if(${found_old_option} EQUAL 1 AND NOT ${found_new_option} EQUAL 1)
|
||||||
|
string(REPLACE ${old_option_name} ${new_option_name} current_value ${current_value})
|
||||||
|
file(APPEND ${file_name} "\n" ${current_value})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
Loading…
Reference in New Issue
Block a user