Overhaul directory organization; simplify CMake build paths.

This commit is contained in:
S David 2024-05-16 16:56:50 -04:00
parent abe4238423
commit c9442cde2f
40 changed files with 112 additions and 33 deletions

4
.gitmodules vendored
View File

@ -1,6 +1,6 @@
[submodule "third_party/QJsonModel"]
path = Modules/QJsonModel
path = Modules/third_party/QJsonModel
url = https://gitea.beniquez.me/sdaveb/QJsonModel.git
[submodule "third_party/IOCore"]
path = Modules/IOCore
path = Modules/third_party/IOCore
url = https://gitea.beniquez.me/sdaveb/IOCore.git

View File

@ -36,7 +36,7 @@ endif
let s:build_dir = 'debug'
let s:build_cores = 6
let s:make_args = '-C '. s:build_dir . ' -j ' . s:build_cores . ' all'
let s:make_args = '-C '. s:build_dir . ' -j ' . s:build_cores . ' ctest all'
let s:cmake_path = substitute(system('which ' . 'cmake'),'\n$', '', '')
let s:ninja_path = substitute(system('which ' . 'ninja'),'\n$', '', '')

View File

@ -48,6 +48,54 @@ function(set_artifact_dir path)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${path}/bin" PARENT_SCOPE)
endfunction()
function(package_library_headers LibraryTarget)
# Create the custom target name
set(target_name "${LibraryTarget}_copy_include_directory")
# Create a list to hold custom commands
set(custom_commands)
set(is_glob false)
# Iterate over each argument to copy them
foreach(item IN LISTS ARGN)
if (IS_DIRECTORY ${item})
get_filename_component(item_name ${item} NAME)
list(APPEND custom_commands
COMMAND ${CMAKE_COMMAND} -E copy_directory ${item} ${CMAKE_BINARY_DIR}/include/${LibraryTarget}/${item_name}
)
else()
if (${is_glob})
file(GLOB glob_files ${item})
list(APPEND expanded_items ${glob_files})
message(STATUS "glob_files" ${glob_files})
set(is_glob false)
foreach(expanded IN LISTS expanded_items)
get_filename_component(item_name ${expanded} NAME)
list(APPEND custom_commands
COMMAND ${CMAKE_COMMAND} -E copy ${expanded} ${CMAKE_BINARY_DIR}/include/${LibraryTarget}/${item_name}
)
endforeach()
elseif (item STREQUAL "GLOB")
set(is_glob true)
else()
get_filename_component(item_name ${item} NAME)
list(APPEND custom_commands
COMMAND ${CMAKE_COMMAND} -E copy ${item} ${CMAKE_BINARY_DIR}/include/${LibraryTarget}/${item_name}
)
endif()
endif()
endforeach()
# Create the target to copy directories and files
add_custom_target(${target_name} ALL
${custom_commands}
COMMENT "Copying files and directories to ${CMAKE_BINARY_DIR}/include/${LibraryTarget}/"
)
# Add the custom target as a dependency of the library target
add_dependencies(${LibraryTarget} ${target_name})
endfunction()
function(disable_tests_if_subproject)
option(BUILD_TESTING "Build unit tests" ON)

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.26)
# Additional paths to search for custom and third-party CMake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
include(BuildProperties)
@ -144,7 +144,7 @@ endif()
# Add subdirectories
add_subdirectory(Modules)
include_directories(PREPEND ${Elemental_CMAKE_SOURCE_DIR}/Modules)
include_directories(BEFORE ${Elemental_CMAKE_SOURCE_DIR}/Modules)
if(BUILD_TESTING)
add_subdirectory(Tests)

View File

@ -1,7 +1,10 @@
add_subdirectory(IOCore)
add_subdirectory(third_party/IOCore)
add_subdirectory(third_party/QJsonModel)
# Add third_party modules to the C++ include search path
include_directories(third_party)
add_subdirectory(elemental)
add_subdirectory(QJsonModel)
add_subdirectory(EditorWidgets)

View File

@ -8,8 +8,8 @@ OBJECT
paths.cpp)
target_include_directories(elemental
BEFORE
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(elemental PUBLIC
@ -20,4 +20,34 @@ target_link_libraries(elemental PUBLIC
${NLOHMANN_JSON_LIBS}
)
#package_library_headers(elemental
# GLOB ${Elemental_ARTIFACT_DIR}/*.hpp
# ${Elemental_ARTIFACT_DIR}/sys
# ${Elemental_ARTIFACT_DIR}/types
# ${Elemental_ARTIFACT_DIR}/details
# ${Elemental_ARTIFACT_DIR}/util
#)
target_include_directories(elemental
INTERFACE
${CMAKE_BINARY_DIR}/include
)
#target_include_directories(elemental
#PUBLIC
# $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
# $<INSTALL_INTERFACE:include>
#)
#install(TARGETS elemental
# EXPORT elemental
# ARCHIVE DESTINATION lib
# LIBRARY DESTINATION lib
# RUNTIME DESTINATION bin
#)
#install(DIRECTORY ${CMAKE_BINARY_DIR}/include DESTINATION include)
#
#install(EXPORT elemental
# NAMESPACE Elemental::
# DESTINATION lib/cmake/elemental
#)
# vim: ts=4 sw=4 noet foldmethod=indent :

View File

@ -24,22 +24,22 @@ target_compile_definitions(test-runner PRIVATE
)
target_include_directories(test-runner
PRIVATE ${Elemental_ARTIFACT_DIR}/include/elemental
#PRIVATE ${Elemental_ARTIFACT_DIR}/include/elemental
PRIVATE ${Elemental_CMAKE_SOURCE_DIR}/Tests
)
set(Elemental_TEST_SUITE_LIBS
#set(Elemental_TEST_SUITE_LIBS
#IOCore
#${SDL2_COMBINED_LINK_DEPS}
#${STACKTRACE_DEP_LIBS}
#)
target_link_libraries(test-runner
PRIVATE
elemental
IOCore
Catch2::Catch2WithMain
FakeIt::FakeIt-catch
Threads::Threads
${SDL2_COMBINED_LINK_DEPS}
${STACKTRACE_DEP_LIBS}
)
target_link_libraries(test-runner
PRIVATE
${Elemental_TEST_SUITE_LIBS}
)
# Set output directories for build targets
@ -73,6 +73,6 @@ add_dependencies(ctest
copy_test_assets
)
add_subdirectory(sdl)
#add_subdirectory(sdl)
# vim: ts=2 sw=2 noet foldmethod=indent :

View File

@ -7,7 +7,7 @@
* obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "IRenderer.hpp"
#include "elemental/IRenderer.hpp"
#include "types/rendering.hpp"
#include "test-utils/common.hpp"
@ -18,8 +18,7 @@
BEGIN_TEST_SUITE("elemental::IRenderer")
{
using namespace elemental;
struct DummyRenderer : public IRenderer
{
struct DummyRenderer : public IRenderer {
friend class IRenderer;
~DummyRenderer() override = default;
@ -33,21 +32,22 @@ BEGIN_TEST_SUITE("elemental::IRenderer")
void clearScreen() override { return; }
void flip() override { return; }
void blit(std::shared_ptr<void> image_data,
Rectangle& placement) override
void blit(std::shared_ptr<void> image_data, Rectangle& placement)
override
{
return;
}
protected:
protected:
DummyRenderer() : IRenderer() {}
};
TEST("elemental::IRenderer::GetInstance works with "
"properly-derived class")
{
REQUIRE_NOTHROW(
[&]() { IRenderer::GetInstance<DummyRenderer>(); }());
REQUIRE_NOTHROW([&]() {
IRenderer::GetInstance<DummyRenderer>();
}());
SUCCEED();
}

View File

@ -7,7 +7,7 @@
* obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Singleton.hpp"
#include "elemental/Singleton.hpp"
#include "test-utils/common.hpp"
@ -20,19 +20,17 @@ using elemental::Singleton;
BEGIN_TEST_SUITE("elemental::Singleton<T>")
{
struct SimpleStructure
{
struct SimpleStructure {
uint32_t id;
char name[128];
uint32_t flags;
};
struct NonConstructibleStructure
{
struct NonConstructibleStructure {
uint32_t id;
char name[128];
private:
private:
NonConstructibleStructure(){};
friend class Singleton;
};