Fix segmentation fault with QJsonModel
Some checks failed
buildbot/elemental-game-linux-builder Build done.
buildbot/elemental-game-freebsd-builder Build done.
buildbot/elemental-game-macos-builder Build done.

A != should have been a == comparison, resulting in a variable not being
intialized and a nullptr access.

Additionally:
 - Add git submodule initialization to CMake configuration in
   BuildProperties.cmake
 - Add support for the mold and sold linkers, also in
   BuildProperties.cmake
 - Rename docs directory to Docs
 - Add nlohmann_json and SDL include search paths to whole project.
 - Add screenshot for documentation
This commit is contained in:
S David 2024-04-29 22:27:09 -04:00
parent 8c42557063
commit c99e45db7a
8 changed files with 126 additions and 93 deletions

View File

@ -10,11 +10,12 @@ qt_add_executable(ResourceEditor
target_link_libraries(ResourceEditor
PRIVATE
IOCore::IOCoreStatic
${NLOHMANN_JSON_LIBS}
Qt6::Core
Qt6::Widgets
Qt6::Gui
Qt6::Widgets
QJsonModel
IOCore::IOCoreStatic
)
set_target_properties(ResourceEditor

View File

@ -153,13 +153,15 @@ void MainWindow::onclick_fstree_file(const QModelIndex& index)
if (suffix == "json") {
auto tree_widget = new QTreeView(this->ui->mdiArea);
auto found = this->json_models.find(filename);
QJsonModel* model = nullptr;
if (found != this->json_models.end()) {
if (found == this->json_models.end()) {
this->json_models[filename] =
std::make_unique<QJsonModel>(this);
}
auto& model = this->json_models[filename];
tree_widget->setModel(model.get());
model = this->json_models.at(filename).get();
tree_widget->setModel(model);
QFile file(path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream file_text(&file);
@ -168,7 +170,6 @@ void MainWindow::onclick_fstree_file(const QModelIndex& index)
file.close();
}
subwindow = this->ui->mdiArea->addSubWindow(tree_widget);
subwindow->setObjectName(path);
subwindow->setWindowTitle(path_info.fileName());

View File

@ -12,6 +12,28 @@ function(prevent_in_source_build)
endif()
endfunction()
function(disable_deprecated_features)
# Use new timestamp behavior when extracting files archives
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
endfunction()
function(git_setup_submodules)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Git submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
endfunction()
function(set_artifact_dir path)
# Set local variable, not necessary to be parent scope since it's not used outside this function
@ -26,35 +48,67 @@ function(set_artifact_dir path)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${path}/bin" PARENT_SCOPE)
endfunction()
function(disable_deprecated_features)
# Use new timestamp behavior when extracting files archives
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
endfunction()
function(disable_tests_if_subproject)
if (NOT DEFINED PROJECT_NAME)
option(BUILD_TESTING "Build and run unit tests" ON)
else()
option(BUILD_TESTING "Build and run unit tests" OFF)
endif()
endfunction()
function(git_setup_submodules)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Git submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
if (NOT DEFINED PROJECT_NAME)
option(BUILD_TESTING "Build and run unit tests" ON)
else()
option(BUILD_TESTING "Build and run unit tests" OFF)
endif()
endfunction()
# vim: ts=4 sts=4 sw=4 noet :
function(use_ccache)
option(USE_CCACHE
[=[Use ccache compiler cache to speed up builds.
Enabled by default if ccache is found]=]
ON
)
# Search for the code caching compiler wrapper, ccache and enable it
# if found. This will speed up repeated builds.
if (USE_CCACHE)
message(CHECK_START "Detecting cacche")
find_program(CCACHE_PATH ccache)
if(CCACHE_PATH)
message(CHECK_PASS("found"))
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PATH})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_PATH})
endif()
list(APPEND CMAKE_MESSAGE_INDENT " ")
message(STATUS "(set -DUSE_CCACHE=Off to disable)")
list(POP_BACK CMAKE_MESSAGE_INDENT)
endif()
endfunction()
function(check_and_set_linker)
option(USE_MOLD "Use the mold/sold parallel linker for faster builds" ON)
if(USE_MOLD)
# Determine if the compiler is GCC or Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
message(STATUS "Detected GCC/Clang, checking for mold/sold linker...")
# Check for mold linker on general systems and ld64.mold on macOS
if(APPLE)
find_program(MOLD_LINKER ld64.mold)
set(CMAKE_LINKER_TYPE SOLD)
else()
find_program(MOLD_LINKER mold)
set(CMAKE_LINKER_TYPE MOLD)
endif()
if(MOLD_LINKER)
message(STATUS "LINKER_TYPE set to ${CMAKE_LINKER_TYPE} for faster builds")
list(APPEND CMAKE_MESSAGE_INDENT " ")
message(STATUS "(set -DUSE_MOLD=OFF to disable)")
list(POP_BACK CMAKE_MESSAGE_INDENT)
else()
message(STATUS " -- No suitable mold linker found. Using default linker.")
endif()
else()
message(STATUS "Compiler is neither GCC nor Clang. Skipping mold linker check.")
endif()
endif()
endfunction()
# vim: ts=4 sts=4 sw=4 noet foldmethod=indent :

View File

@ -10,10 +10,8 @@ disable_deprecated_features()
# When this package is included as a subproject, there's no need to
# build and run the unit-tests.
# Sets -DBUILD_TESTING to false by default if this is a third-party lib build
# This check must appear before project()
disable_tests_if_subproject()
git_setup_submodules()
project(Elemental
VERSION 0.0.3
LANGUAGES C CXX
@ -21,8 +19,10 @@ project(Elemental
# HOMEPAGE_URL <URL>
DESCRIPTION "A simple top-down strategy game"
)
check_and_set_linker()
include(CPM)
git_setup_submodules()
SET(${PROJECT_NAME}_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
@ -31,12 +31,6 @@ if (CI_BUILD)
add_compile_definitions(-DCI_BUILD=1)
endif()
option(USE_CCACHE
[=[Use ccache compiler cache to speed up builds.
Enabled by default if ccache is found]=]
ON
)
# enable compile_commands.json generation for clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
@ -51,23 +45,6 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
# Search for the code caching compiler wrapper, ccache and enable it
# if found. This will speed up repeated builds.
if (USE_CCACHE)
message(CHECK_START "Detecting cacche")
find_program(CCACHE_PATH ccache)
if(CCACHE_PATH)
message(CHECK_PASS("found"))
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PATH})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_PATH})
endif()
list(APPEND CMAKE_MESSAGE_INDENT " ")
message(STATUS "(set -DUSE_CCACHE=Off to disable)")
list(POP_BACK CMAKE_MESSAGE_INDENT)
endif()
if (BUILD_TESTING)
CPMFindPackage(NAME Catch2
GITHUB_REPOSITORY catchorg/Catch2
@ -120,6 +97,7 @@ find_package(Qt6 COMPONENTS
)
qt_standard_project_setup()
# Set output directories for build targets
set_artifact_dir(${CMAKE_BINARY_DIR}/out)
@ -128,7 +106,7 @@ include(FetchContent)
include(CheckIncludeFile)
# Initialize pkgconf
find_package(Threads)
find_package(Threads) # POSIX thread support
find_package(PkgConfig REQUIRED)
# Example: Find SDL2, SDL2_image, and SDL2_gfx using PkgConfig
@ -136,22 +114,26 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2)
pkg_check_modules(SDL2_IMAGE REQUIRED IMPORTED_TARGET SDL2_image)
pkg_check_modules(SDL2_GFX REQUIRED IMPORTED_TARGET SDL2_gfx)
find_package(PkgConfig REQUIRED)
pkg_check_modules(NLOHMANN_JSON "nlohmann_json >= 3.11.2" REQUIRED)
SET(SDL2_COMBINED_INCLUDE_DIRS "")
list(APPEND SDL2_COMBINED_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
list(APPEND SDL2_COMBINED_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIRS})
list(APPEND SDL2_COMBINED_INCLUDE_DIRS ${SDL2_GFX_INCLUDE_DIRS})
list(REMOVE_DUPLICATES SDL2_COMBINED_INCLUDE_DIRS)
include_directories(SYSTEM ${SDL_COMBINED_INCLUDE_DIRS})
set(SDL2_COMBINED_LINK_DEPS
PkgConfig::SDL2
PkgConfig::SDL2_IMAGE
PkgConfig::SDL2_GFX
)
pkg_check_modules(NLOHMANN_JSON "nlohmann_json >= 3.11.2" REQUIRED)
include_directories(SYSTEM ${NLOHMANN_JSON_INCLUDE_DIRS})
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(-DDEBUG=1)
endif()

0
Docs/.keep Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

View File

@ -50,7 +50,7 @@ PROJECT_BRIEF =
# the logo to the output directory.
PROJECT_LOGO =
OUTPUT_DIRECTORY = "docs"
OUTPUT_DIRECTORY = "Docs"
CREATE_SUBDIRS = YES
# Controls the number of sub-directories that will be created when
@ -213,9 +213,9 @@ QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
# By default Python docstrings are displayed as preformatted text and doxygen's
# By default Python Docstrings are displayed as preformatted text and doxygen's
# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
# doxygen's special commands can be used and the contents of the docstring
# doxygen's special commands can be used and the contents of the Docstring
# documentation blocks is shown as doxygen documentation.
# The default value is: YES.
@ -1254,7 +1254,7 @@ IGNORE_PREFIX =
GENERATE_HTML = YES
# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
# The HTML_OUTPUT tag is used to specify where the HTML Docs will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
# it.
# The default directory is: html.
@ -1327,7 +1327,7 @@ HTML_STYLESHEET =
# documentation.
# This tag requires that the tag GENERATE_HTML is set to YES.
HTML_EXTRA_STYLESHEET = docs/extra/dark-mode.css
HTML_EXTRA_STYLESHEET = Docs/extra/dark-mode.css
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the HTML output directory. Note
@ -1337,7 +1337,7 @@ HTML_EXTRA_STYLESHEET = docs/extra/dark-mode.css
# files will be copied as-is; there are no commands or markers available.
# This tag requires that the tag GENERATE_HTML is set to YES.
HTML_EXTRA_FILES = docs/extra/dark-mode.css
HTML_EXTRA_FILES = Docs/extra/dark-mode.css
# The HTML_COLORSTYLE tag can be used to specify if the generated HTML output
# should be rendered with a dark or light theme.
@ -1446,8 +1446,8 @@ HTML_INDEX_NUM_ENTRIES = 100
# environment (see:
# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To
# create a documentation set, doxygen will generate a Makefile in the HTML
# output directory. Running make will produce the docset in that directory and
# running make install will install the docset in
# output directory. Running make will produce the Docset in that directory and
# running make install will install the Docset in
# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
# genXcode/_index.html for more information.
@ -1456,15 +1456,15 @@ HTML_INDEX_NUM_ENTRIES = 100
GENERATE_DOCSET = NO
# This tag determines the name of the docset feed. A documentation feed provides
# This tag determines the name of the Docset feed. A documentation feed provides
# an umbrella under which multiple documentation sets from a single provider
# (such as a company or product suite) can be grouped.
# The default value is: Doxygen generated docs.
# The default value is: Doxygen generated Docs.
# This tag requires that the tag GENERATE_DOCSET is set to YES.
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_FEEDNAME = "Doxygen generated Docs"
# This tag determines the URL of the docset feed. A documentation feed provides
# This tag determines the URL of the Docset feed. A documentation feed provides
# an umbrella under which multiple documentation sets from a single provider
# (such as a company or product suite) can be grouped.
# This tag requires that the tag GENERATE_DOCSET is set to YES.
@ -1473,7 +1473,7 @@ DOCSET_FEEDURL =
# This tag specifies a string that should uniquely identify the documentation
# set bundle. This should be a reverse domain-name style string, e.g.
# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
# com.mycompany.MyDocSet. Doxygen will append .Docset to the name.
# The default value is: org.doxygen.Project.
# This tag requires that the tag GENERATE_DOCSET is set to YES.
@ -1684,7 +1684,7 @@ GENERATE_TREEVIEW = NO
# FULL_SIDEBAR option determines if the side bar is limited to only the treeview
# area (value NO) or if it should extend to the full height of the window (value
# YES). Setting this to YES gives a layout similar to
# https://docs.readthedocs.io with more room for contents, but less room for the
# https://Docs.readtheDocs.io with more room for contents, but less room for the
# project logo, title, and description. If either GENERATE_TREEVIEW or
# DISABLE_INDEX is set to NO, this option has no effect.
# The default value is: NO.
@ -1774,9 +1774,9 @@ MATHJAX_VERSION = MathJax_2
# When MathJax is enabled you can set the default output format to be used for
# the MathJax output. For more details about the output format see MathJax
# version 2 (see:
# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3
# http://Docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3
# (see:
# http://docs.mathjax.org/en/latest/web/components/output.html).
# http://Docs.mathjax.org/en/latest/web/components/output.html).
# Possible values are: HTML-CSS (which is slower, but has the best
# compatibility. This is the name for Mathjax version 2, for MathJax version 3
# this will be translated into chtml), NativeMML (i.e. MathML. Only supported
@ -1805,10 +1805,10 @@ MATHJAX_RELPATH =
# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
# extension names that should be enabled during MathJax rendering. For example
# for MathJax version 2 (see
# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions):
# https://Docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions):
# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
# For example for MathJax version 3 (see
# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html):
# http://Docs.mathjax.org/en/latest/input/tex/extensions/index.html):
# MATHJAX_EXTENSIONS = ams
# This tag requires that the tag USE_MATHJAX is set to YES.
@ -1817,7 +1817,7 @@ MATHJAX_EXTENSIONS =
# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
# of code that will be used on startup of the MathJax code. See the MathJax site
# (see:
# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an
# http://Docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an
# example see the documentation.
# This tag requires that the tag USE_MATHJAX is set to YES.
@ -1826,7 +1826,7 @@ MATHJAX_CODEFILE =
# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
# the HTML output. The underlying search engine uses javascript and DHTML and
# should work on any modern browser. Note that when using HTML help
# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or Docsets (GENERATE_DOCSET)
# there is already a search function so this one should typically be disabled.
# For large projects the javascript based search engine can be slow, then
# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
@ -1920,7 +1920,7 @@ EXTRA_SEARCH_MAPPINGS =
GENERATE_LATEX = YES
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
# The LATEX_OUTPUT tag is used to specify where the LaTeX Docs will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
# it.
# The default directory is: latex.
@ -2105,7 +2105,7 @@ LATEX_EMOJI_DIRECTORY =
GENERATE_RTF = NO
# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
# The RTF_OUTPUT tag is used to specify where the RTF Docs will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
# it.
# The default directory is: rtf.

View File

@ -10,11 +10,6 @@ set(ELEMENTAL_SOURCES
add_library(elemental OBJECT ${ELEMENTAL_SOURCES})
target_include_directories(elemental SYSTEM BEFORE
PUBLIC ${SDL2_COMBINED_INCLUDE_DIRS}
PUBLIC ${NLOHMANN_JSON_INCLUDE_DIRS}
)
#file(MAKE_DIRECTORY ${Elemental_ARTIFACT_DIR}/include/)
#add_custom_target(elemental_include_files
# COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include ${Elemental_ARTIFACT_DIR}/include/elemental