diff --git a/CMakeLists.txt b/CMakeLists.txt index e0af6f2..ceaf548 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,14 +4,7 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) # Package definition # -set(PACKAGE_VERSION_MAJOR "0") -set(PACKAGE_VERSION_MINOR "0") -set(PACKAGE_VERSION_PATCH "0") -set(PACKAGE_VERSION_TWEAK "1") -set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}.${PACKAGE_VERSION_TWEAK}") -set(PACKAGE_SHORT_NAME "engine") -set(PACKAGE_FULL_NAME "${PACKAGE_SHORT_NAME} v${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}") -project("${PACKAGE_SHORT_NAME}" VERSION "${PACKAGE_VERSION}") +project(engine) # # Package configuration @@ -19,8 +12,6 @@ project("${PACKAGE_SHORT_NAME}" VERSION "${PACKAGE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -include(GNUInstallDirs) - include(SetupPackageOptions) include(SetupBuildConfig) include(SetupOutputDirectories) @@ -30,4 +21,7 @@ include(SetupCompiler) # Modules # -# add_subdirectory(path/to/module) \ No newline at end of file +# add_subdirectory(path/to/module) +add_subdirectory(src/runtime/foundation) +add_subdirectory(src/runtime/main) +add_subdirectory(src/launcher) diff --git a/cmake/Compiler/msvc.cmake b/cmake/Compiler/msvc.cmake index 0c496da..6398076 100644 --- a/cmake/Compiler/msvc.cmake +++ b/cmake/Compiler/msvc.cmake @@ -52,9 +52,9 @@ endif() string(REPLACE ";" " " MSVC_DEBUG_FLAGS "${MSVC_DEBUG_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_DEFAULT_FLAGS}" CACHE INTERNAL "" FORCE) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MSVC_DEBUG_FLAGS}" CACHE INTERNAL "" FORCE) -set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${MSVC_OPTIMIZED_FLAGS}" CACHE INTERNAL "" FORCE) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MSVC_OPTIMIZED_FLAGS} /Oy" CACHE INTERNAL "" FORCE) +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /DNRELEASE ${MSVC_DEBUG_FLAGS}" CACHE INTERNAL "" FORCE) +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /D_DEBUG /D_PROFILE /DNRELEASE ${MSVC_OPTIMIZED_FLAGS}" CACHE INTERNAL "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /DNDEBUG /DRELEASE ${MSVC_OPTIMIZED_FLAGS} /Oy" CACHE INTERNAL "" FORCE) set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /DEBUG:FULL" CACHE INTERNAL "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG:FULL" CACHE INTERNAL "" FORCE) diff --git a/cmake/SetupCompiler.cmake b/cmake/SetupCompiler.cmake index 7317e12..37079e3 100644 --- a/cmake/SetupCompiler.cmake +++ b/cmake/SetupCompiler.cmake @@ -34,7 +34,7 @@ else() endif() # Set compiler-independent options -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) if(BUILD_SHARED) diff --git a/src/launcher/CMakeLists.txt b/src/launcher/CMakeLists.txt new file mode 100644 index 0000000..6b94a43 --- /dev/null +++ b/src/launcher/CMakeLists.txt @@ -0,0 +1,30 @@ +project(launcher) + +# Define all source files here +set(PROJECT_SRC + src/main.cpp +) + +# Create shared or static library as per the global settings +if(WIN32) + add_executable(launcher WIN32 ${PROJECT_SRC}) +else() + add_executable(launcher ${PROJECT_SRC}) +endif() +# Specify the include directories to the compiler +target_include_directories(main +PUBLIC + $ + $ +PRIVATE + $) + +# Specify dependent libraries to the linker +target_link_libraries(launcher +PUBLIC + foundation + main +) + +# Create virtual folders inside Visual Studio and XCode +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${PROJECT_SRC}) diff --git a/src/launcher/src/main.cpp b/src/launcher/src/main.cpp new file mode 100644 index 0000000..483d7d6 --- /dev/null +++ b/src/launcher/src/main.cpp @@ -0,0 +1,11 @@ +#include "main.h" +#include "logging.h" + +extern int main(int argc, char **argv) +{ + (void)(argc); + (void)(argv); + LOGV("-- Launcher started {%d,%p}\n", argc, argv); + getchar(); + return 0; +} diff --git a/src/runtime/foundation/CMakeLists.txt b/src/runtime/foundation/CMakeLists.txt new file mode 100644 index 0000000..4c75db4 --- /dev/null +++ b/src/runtime/foundation/CMakeLists.txt @@ -0,0 +1,34 @@ +project(foundation) + +# Define all source files here +set(PROJECT_SRC + include/foundation/platform.h + include/foundation/logging.h + include/foundation/platform/win32/minimal_win32.h + src/dummy.cpp + src/logging.cpp +) + +# Create shared or static library as per the global settings +if (BUILD_SHARED) + add_library(foundation SHARED ${PROJECT_SRC}) +else () + add_library(foundation STATIC ${PROJECT_SRC}) +endif () + +# Specify the include directories to the compiler +target_include_directories(foundation +PUBLIC + $ + $ +PRIVATE + $) + +# Specify dependent libraries to the linker +#target_link_libraries(foundation +#PUBLIC +# third-party +#) + +# Create virtual folders inside Visual Studio and XCode +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${PROJECT_SRC}) diff --git a/src/runtime/foundation/include/foundation/logging.h b/src/runtime/foundation/include/foundation/logging.h new file mode 100644 index 0000000..d3694ed --- /dev/null +++ b/src/runtime/foundation/include/foundation/logging.h @@ -0,0 +1,46 @@ +#pragma once + +#ifdef _MSC_VER +// Disable warnings that we don't have control over +// since external libraries bring them. +#pragma warning(push) +//#pragma warning(disable : 4514 4710 4820) +// Disable C4514: unreferenced inline function has been removed +#pragma warning(disable: 4514) +// Disable C4710: `f()` function not inlined +#pragma warning(disable: 4710) +// Disable C4820: x bytes padding added after data member xy +#pragma warning(disable : 4820) +#endif +#include +#include +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#ifdef _DEBUG +#define LOG(fmt) \ + { \ + auto currtime = std::chrono::system_clock::now(); \ + auto time = std::chrono::system_clock::to_time_t(currtime); \ + auto rtime = std::chrono::system_clock::from_time_t(time); \ + int usec = std::chrono::duration_cast>(currtime - rtime).count(); \ + char timefmt[32] = {}; \ + strftime(timefmt, sizeof(timefmt), "%Y-%m-%dT%H:%M:%S", localtime(&time)); \ + fprintf_s(stdout, "-- [%s.%d] [%s:%ld %s]: %s", timefmt, usec, __FILE__, __LINE__, __FUNCTION__, fmt); \ + } +#define LOGV(fmt, ...) \ + { \ + auto currtime = std::chrono::system_clock::now(); \ + auto time = std::chrono::system_clock::to_time_t(currtime); \ + auto rtime = std::chrono::system_clock::from_time_t(time); \ + int usec = std::chrono::duration_cast>(currtime - rtime).count(); \ + char timefmt[32] = {}; \ + strftime(timefmt, sizeof(timefmt), "%Y-%m-%dT%H:%M:%S", localtime(&time)); \ + fprintf_s(stdout, "-- [%s.%d] [%s:%ld %s]: ", timefmt, usec, __FILE__, __LINE__, __FUNCTION__); \ + fprintf_s(stdout, fmt, ##__VA_ARGS__); \ + } +#else +#define LOG(fmt) +#define LOGV(fmt, ...) +#endif diff --git a/src/runtime/foundation/include/foundation/platform.h b/src/runtime/foundation/include/foundation/platform.h new file mode 100644 index 0000000..3c5a2d1 --- /dev/null +++ b/src/runtime/foundation/include/foundation/platform.h @@ -0,0 +1,7 @@ +#pragma once + +#if defined _WIN32 +#include "platform/win32/minimal_win32.h" +#else +#error Platform not supported. +#endif diff --git a/src/runtime/foundation/include/foundation/platform/win32/minimal_win32.h b/src/runtime/foundation/include/foundation/platform/win32/minimal_win32.h new file mode 100644 index 0000000..2058fae --- /dev/null +++ b/src/runtime/foundation/include/foundation/platform/win32/minimal_win32.h @@ -0,0 +1,64 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN +#define WIN32_EXTRA_LEAN + +#define NOIME +#define NOWINRES +#define NOGDICAPMASKS +#define NOVIRTUALKEYCODES +#define NOWINMESSAGES +#define NOWINSTYLES +#define NOSYSMETRICS +#define NOMENUS +#define NOICONS +#define NOKEYSTATES +#define NOSYSCOMMANDS +#define NORASTEROPS +#define NOSHOWWINDOW +#define OEMRESOURCE +#define NOATOM +#define NOCLIPBOARD +#define NOCOLOR +#define NOCTLMGR +#define NODRAWTEXT +#define NOGDI +#define NOUSER +#define NOMB +#define NOMEMMGR +#define NOMETAFILE +#define NOMINMAX +#define NOMSG +#define NOOPENFILE +#define NOSCROLL +#define NOSERVICE +#define NOSOUND +#define NOTEXTMETRIC +#define NOWH +#define NOWINOFFSETS +#define NOCOMM +#define NOKANJI +#define NOHELP +#define NOPROFILER +#define NODEFERWINDOWPOS +#define NOMCX +#define NOIME +#define NOPROXYSTUB +#define NOIMAGE +#define NO +#define NOTAPE + +#ifdef _MSC_VER +// Disable warnings that we don't have direct control over... +#pragma warning(push) +// Disable C5039: `TpSetCallbackCleanupGroup`: pointer or reference to +// potentially throwing function passed to extern C function under +// -EHc. Undefined behavior may occur if this function throws an +// exception. +#pragma warning(disable : 5039) +#endif +#include +#ifdef _MSC_VER +#pragma warning(pop) +#endif + diff --git a/src/runtime/foundation/src/dummy.cpp b/src/runtime/foundation/src/dummy.cpp new file mode 100644 index 0000000..a6bd76a --- /dev/null +++ b/src/runtime/foundation/src/dummy.cpp @@ -0,0 +1,4 @@ +void dummy() +{ + +} diff --git a/src/runtime/foundation/src/logging.cpp b/src/runtime/foundation/src/logging.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/runtime/main/CMakeLists.txt b/src/runtime/main/CMakeLists.txt new file mode 100644 index 0000000..ecbb457 --- /dev/null +++ b/src/runtime/main/CMakeLists.txt @@ -0,0 +1,42 @@ +project(main) + +# Define all source files here +set(PROJECT_SRC + include/main/main.h +) +if(WIN32) + set(PROJECT_SRC ${PROJECT_SRC} src/main_win32.cpp) +elseif(APPLE) + set(PROJECT_SRC ${PROJECT_SRC} src/main_mac.cpp) +elseif(UNIX) + set(PROJECT_SRC ${PROJECT_SRC} src/main_linux.cpp) +else() + set(PROJECT_SRC ${PROJECT_SRC} src/main_generic.cpp) +endif() + + +# Create shared or static library as per the global settings +#if (BUILD_SHARED) +# add_library(main SHARED ${PROJECT_SRC}) +#else () +# TODO: For some reason we can only link libmain statically +# Let's investigate why + add_library(main STATIC ${PROJECT_SRC}) +#endif () + +# Specify the include directories to the compiler +target_include_directories(main +PUBLIC + $ + $ +PRIVATE + $) + +# Specify dependent libraries to the linker +target_link_libraries(main +PUBLIC + foundation +) + +# Create virtual folders inside Visual Studio and XCode +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${PROJECT_SRC}) diff --git a/src/runtime/main/include/main/main.h b/src/runtime/main/include/main/main.h new file mode 100644 index 0000000..a29901d --- /dev/null +++ b/src/runtime/main/include/main/main.h @@ -0,0 +1,10 @@ +#pragma once + +/** + * @brief This function should be implemented by the application + * that includes this header. + * @param argc the number of commandline arguments + * @param argv the array of commandline arguments in strings + * @return errorcode + */ +extern int main(int argc, char **argv); diff --git a/src/runtime/main/src/main_generic.cpp b/src/runtime/main/src/main_generic.cpp new file mode 100644 index 0000000..1e7e0a7 --- /dev/null +++ b/src/runtime/main/src/main_generic.cpp @@ -0,0 +1,18 @@ +#include "main.h" +#include "logging.h" + +static int _main(int argc, char **argv) +{ + (void)(argc); + (void)(argv); + LOG("\n"); + return main(argc, argv); +} + +int main(int argc, char** argv) +{ + (void)(argc); + (void)(argv); + LOG("\n"); + return _main(argc, argv); +} diff --git a/src/runtime/main/src/main_linux.cpp b/src/runtime/main/src/main_linux.cpp new file mode 100644 index 0000000..1e7e0a7 --- /dev/null +++ b/src/runtime/main/src/main_linux.cpp @@ -0,0 +1,18 @@ +#include "main.h" +#include "logging.h" + +static int _main(int argc, char **argv) +{ + (void)(argc); + (void)(argv); + LOG("\n"); + return main(argc, argv); +} + +int main(int argc, char** argv) +{ + (void)(argc); + (void)(argv); + LOG("\n"); + return _main(argc, argv); +} diff --git a/src/runtime/main/src/main_mac.cpp b/src/runtime/main/src/main_mac.cpp new file mode 100644 index 0000000..1e7e0a7 --- /dev/null +++ b/src/runtime/main/src/main_mac.cpp @@ -0,0 +1,18 @@ +#include "main.h" +#include "logging.h" + +static int _main(int argc, char **argv) +{ + (void)(argc); + (void)(argv); + LOG("\n"); + return main(argc, argv); +} + +int main(int argc, char** argv) +{ + (void)(argc); + (void)(argv); + LOG("\n"); + return _main(argc, argv); +} diff --git a/src/runtime/main/src/main_win32.cpp b/src/runtime/main/src/main_win32.cpp new file mode 100644 index 0000000..2176a9b --- /dev/null +++ b/src/runtime/main/src/main_win32.cpp @@ -0,0 +1,48 @@ +#include "main.h" +#include "platform/win32/minimal_win32.h" +#include "logging.h" + +static int _main(int argc, char **argv) +{ + (void)(argc); + (void)(argv); + LOGV("[%d, %p]\n", argc, argv); + return main(argc, argv); +} + +extern int WINAPI WinMain(HINSTANCE hCurrInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int iCmdShow) +{ + (void)(hCurrInst); + (void)(hPrevInst); + (void)(lpCmdLine); + (void)(iCmdShow); + + LOGV("[%p, %p, %p, %d]\n", hCurrInst, hPrevInst, lpCmdLine, iCmdShow); + return _main(0, 0); +} + +// This class is responsible for showing the logs +// and manage itself in memory. +class Console +{ +public: + Console() + { +#ifdef _WIN32 + AllocConsole(); + FILE *fpstdin = stdin, *fpstdout = stdout, *fpstderr = stderr; + freopen_s(&fpstdin, "CONIN$", "r", stdin); + freopen_s(&fpstdout, "CONOUT$", "w", stdout); + freopen_s(&fpstderr, "CONOUT$", "w", stderr); +#endif + } + + ~Console() + { +#ifdef _WIN32 + FreeConsole(); +#endif + } +}; + +Console console;