From f6bcee45bb5e98934f132ab9362ff11700cbcdfe Mon Sep 17 00:00:00 2001 From: Jayden Grubb Date: Tue, 4 Feb 2025 10:28:18 +1000 Subject: [PATCH] Add basic project setup with engine and editor subdirectories --- CMakeLists.txt | 74 +++++++++++++++++++++----------------- LICENSE | 28 +++++++++++++++ editor/CMakeLists.txt | 34 ++++++++++++++++++ editor/src/main.cpp | 11 ++++++ engine/CMakeLists.txt | 24 +++++++++++++ engine/include/nova/api.h | 25 +++++++++++++ engine/include/nova/test.h | 11 ++++++ engine/src/test.cpp | 13 +++++++ include/.gitkeep | 0 src/main.cpp | 12 ------- 10 files changed, 188 insertions(+), 44 deletions(-) create mode 100644 LICENSE create mode 100644 editor/CMakeLists.txt create mode 100644 editor/src/main.cpp create mode 100644 engine/CMakeLists.txt create mode 100644 engine/include/nova/api.h create mode 100644 engine/include/nova/test.h create mode 100644 engine/src/test.cpp delete mode 100644 include/.gitkeep delete mode 100644 src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e5da0a..056635f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,44 +1,54 @@ +# Copyright (c) 2025, Jayden Grubb +# SPDX-License-Identifier: BSD-3-Clause + cmake_minimum_required(VERSION 3.12) set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") -project(Example) +project(nova) enable_language(CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_compile_options( - -Wall - -Wextra - -Wpedantic - -Wold-style-cast -) +# Configuration Options +set(NOVA_BUILD_ENGINE ON CACHE BOOL "Build the engine") +set(NOVA_BUILD_EDITOR ON CACHE BOOL "Build the editor") +set(NOVA_ENGINE_SHARED ON CACHE BOOL "Build the engine as a shared library") +set(NOVA_ENGINE_STATIC OFF CACHE BOOL "Build the engine as a static library") +set(NOVA_EDITOR_STATIC OFF CACHE BOOL "Link the editor against the engine statically") -add_executable( - ${PROJECT_NAME} - src/main.cpp -) +if (NOVA_BUILD_EDITOR) + if (NOVA_EDITOR_STATIC) + set(NOVA_BUILD_ENGINE ON) + set(NOVA_ENGINE_STATIC ON) + else () + set(NOVA_ENGINE_SHARED ON) + endif () +endif () -# find_package(Example REQUIRED) - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/include - # ${Example_INCLUDE_DIRS} -) - -target_link_libraries( - ${PROJECT_NAME} - # ${Example_LIBRARIES} -) - -if (CMAKE_IMPORT_LIBRARY_SUFFIX) - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS +if (MSVC) + add_compile_options( + /W3 + /permissive- + /EHsc + ) +else () + add_compile_options( + -Wall + -Wextra + -Wpedantic ) endif () -add_custom_target(run - COMMAND ${PROJECT_NAME} - DEPENDS ${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) +if (WIN32) + add_compile_definitions( + _CRT_SECURE_NO_WARNINGS + NOMINMAX + ) +endif () + +if (NOVA_BUILD_ENGINE) + add_subdirectory(engine) +endif () +if (NOVA_BUILD_EDITOR) + add_subdirectory(editor) +endif () diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8734cff --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2025, Jayden Grubb + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt new file mode 100644 index 0000000..755bf87 --- /dev/null +++ b/editor/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (c) 2025, Jayden Grubb +# SPDX-License-Identifier: BSD-3-Clause + +set(SRC + main.cpp +) + +list(TRANSFORM SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/) + +add_executable(nova-editor ${SRC}) + +target_include_directories(nova-editor PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/engine/include +) + +if (NOVA_EDITOR_STATIC) + target_link_libraries(nova-editor PRIVATE + nova_static + ) +else () + target_link_libraries(nova-editor PRIVATE + nova + ) + target_compile_definitions(nova-editor PRIVATE + NOVA_DLL_IMPORT + ) + if (CMAKE_IMPORT_LIBRARY_SUFFIX) + add_custom_command(TARGET nova-editor POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) + endif () +endif () diff --git a/editor/src/main.cpp b/editor/src/main.cpp new file mode 100644 index 0000000..f7528f7 --- /dev/null +++ b/editor/src/main.cpp @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2025, Jayden Grubb + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +int main() { + func(); +} diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt new file mode 100644 index 0000000..2bb2dde --- /dev/null +++ b/engine/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2025, Jayden Grubb +# SPDX-License-Identifier: BSD-3-Clause + +set(SRC + test.cpp +) + +list(TRANSFORM SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${Vulkan_INCLUDE_DIRS} +) + +if (NOVA_ENGINE_SHARED) + add_library(nova SHARED ${SRC}) + target_compile_definitions(nova PRIVATE + NOVA_DLL_EXPORT + ) +endif () +if (NOVA_ENGINE_STATIC) + add_library(nova_static STATIC ${SRC}) +endif () diff --git a/engine/include/nova/api.h b/engine/include/nova/api.h new file mode 100644 index 0000000..e71b6a1 --- /dev/null +++ b/engine/include/nova/api.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2025, Jayden Grubb + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#pragma once + +#ifndef NOVA_API + #ifdef WIN32 + #ifdef NOVA_DLL_EXPORT + #define NOVA_API __declspec(dllexport) + #elif NOVA_DLL_IMPORT + #define NOVA_API __declspec(dllimport) + #else + #define NOVA_API + #endif + #else + #ifdef NOVA_DLL_EXPORT + #define NOVA_API __attribute__((visibility("default"))) + #else + #define NOVA_API + #endif + #endif +#endif diff --git a/engine/include/nova/test.h b/engine/include/nova/test.h new file mode 100644 index 0000000..66b58a9 --- /dev/null +++ b/engine/include/nova/test.h @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2025, Jayden Grubb + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#pragma once + +#include + +NOVA_API void func(); diff --git a/engine/src/test.cpp b/engine/src/test.cpp new file mode 100644 index 0000000..5968b9b --- /dev/null +++ b/engine/src/test.cpp @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2025, Jayden Grubb + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include + +void func() { + std::printf("Hello, world!\n"); +} diff --git a/include/.gitkeep b/include/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 423030b..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int main(int argc, char **argv) { - std::printf("Hello, World!\n"); - - for (int i = 0; i < argc; i++) { - std::printf("argv[%d] = %s\n", i, argv[i]); - } - - return EXIT_SUCCESS; -} \ No newline at end of file