From 8967531d8d733f20a6b55885a885b2d18239369d Mon Sep 17 00:00:00 2001 From: Jostein Bratlie Date: Tue, 27 Aug 2019 20:01:55 +0200 Subject: [PATCH] Saperation of the interface part of the engine library. Plus minor fixes. Fixes: - minor comment fix - removal of unused cmake config file - syntactic exception catch bug: gcc, catch polymorphic type by value --- CMakeLists.txt | 3 +- libs/engine/CMakeLists.txt | 34 ++---------- libs/engine/cmake/engine-config.cmake.in | 5 -- libs/engine/include/engine/mygameengine.h | 4 +- libs/engine/include/engine/orangemonkey_ai.h | 2 +- libs/engine/include/engine/utility.h | 2 +- libs/interface/CMakeLists.txt | 54 +++++++++++++++++++ .../include/engine/interface/basic_types.h | 0 .../engine/interface/gameengine_interface.h | 0 .../engine/interface/player_interface.h | 0 .../engine/interface/utility_interface.h | 0 qtclient/CMakeLists.txt | 1 - qtclient/main.cpp | 2 +- .../predefined_utility_benchmark_examples.cpp | 2 +- 14 files changed, 65 insertions(+), 44 deletions(-) delete mode 100644 libs/engine/cmake/engine-config.cmake.in create mode 100644 libs/interface/CMakeLists.txt rename libs/{engine => interface}/include/engine/interface/basic_types.h (100%) rename libs/{engine => interface}/include/engine/interface/gameengine_interface.h (100%) rename libs/{engine => interface}/include/engine/interface/player_interface.h (100%) rename libs/{engine => interface}/include/engine/interface/utility_interface.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c422e2..3dd0d54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,8 @@ SET(MSVC_COMPILE_OPTIONS ) -# Include engine to build +# Include internal libraries to build +add_subdirectory(libs/interface) add_subdirectory(libs/engine) # Include qtclient to build diff --git a/libs/engine/CMakeLists.txt b/libs/engine/CMakeLists.txt index bd84d35..fd0ef2e 100644 --- a/libs/engine/CMakeLists.txt +++ b/libs/engine/CMakeLists.txt @@ -3,10 +3,6 @@ cmake_minimum_required(VERSION 3.8) ### Setup qtclient project project(engine VERSION 0.1 LANGUAGES CXX) -# interface part of engine library -SET(IF_PROJECT_NAME ${PROJECT_NAME}_interface) -add_library(${IF_PROJECT_NAME} INTERFACE) - # engine library (build static on Windows MSVC) if(MSVC) add_library(${PROJECT_NAME} STATIC) @@ -19,32 +15,7 @@ endif() ########################### # Compiler spesific options -message("Clang compile options: ${CLANG_COMPILE_OPTIONS}") -message("GCC compile options: ${GCC_COMPILE_OPTIONS}") -message("MSVC compile options: ${MSVC_COMPILE_OPTIONS}") - -## INTERFACE -# Turn on c++17 compile features -- minimum CMake Version 3.8 required -target_compile_features(${IF_PROJECT_NAME} - INTERFACE $<$:cxx_std_17> - INTERFACE $<$:cxx_std_17> - INTERFACE $<$:cxx_std_17> - ) - -# Compile definitions -target_compile_definitions( ${IF_PROJECT_NAME} - INTERFACE $<$: _USE_MATH_DEFINES> - ) - -# Comple options -target_compile_options(${IF_PROJECT_NAME} - INTERFACE $<$: ${CLANG_COMPILE_OPTIONS}> - INTERFACE $<$: ${GCC_COMPILE_OPTIONS}> - INTERFACE $<$: ${MSVC_COMPILE_OPTIONS}> - ) - -## ENGINE # Turn on c++17 compile features -- minimum CMake Version 3.8 required target_compile_features(${PROJECT_NAME} PUBLIC $<$:cxx_std_17> @@ -69,6 +40,9 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) +### Include the engine interface library +target_link_libraries( ${PROJECT_NAME} PUBLIC engine_interface::engine_interface) + ############################ # Target sources and friends @@ -88,8 +62,6 @@ target_sources( ${PROJECT_NAME} PRIVATE - - ################################## # Export targets and configuration export( TARGETS ${PROJECT_NAME} diff --git a/libs/engine/cmake/engine-config.cmake.in b/libs/engine/cmake/engine-config.cmake.in deleted file mode 100644 index 577ba2a..0000000 --- a/libs/engine/cmake/engine-config.cmake.in +++ /dev/null @@ -1,5 +0,0 @@ -include(CMakeFindDependencyMacro) - -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") -message(STATUS "Found @PROJECT_NAME@") - diff --git a/libs/engine/include/engine/mygameengine.h b/libs/engine/include/engine/mygameengine.h index 0eaffc5..6c84d68 100644 --- a/libs/engine/include/engine/mygameengine.h +++ b/libs/engine/include/engine/mygameengine.h @@ -4,8 +4,8 @@ #include "utility.h" // engine interface -#include "interface/basic_types.h" -#include "interface/gameengine_interface.h" +#include +#include namespace gameengine { diff --git a/libs/engine/include/engine/orangemonkey_ai.h b/libs/engine/include/engine/orangemonkey_ai.h index a004f49..ecaa4dd 100644 --- a/libs/engine/include/engine/orangemonkey_ai.h +++ b/libs/engine/include/engine/orangemonkey_ai.h @@ -2,7 +2,7 @@ #define ORANGEMONKEY_H // engine interface -#include "interface/player_interface.h" +#include // stl #include diff --git a/libs/engine/include/engine/utility.h b/libs/engine/include/engine/utility.h index 55c0a01..ae800d1 100644 --- a/libs/engine/include/engine/utility.h +++ b/libs/engine/include/engine/utility.h @@ -2,7 +2,7 @@ #define UTILITY_H // engine interface -#include "interface/utility_interface.h" +#include namespace gameengine::utility { diff --git a/libs/interface/CMakeLists.txt b/libs/interface/CMakeLists.txt new file mode 100644 index 0000000..b12f1d8 --- /dev/null +++ b/libs/interface/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.8) + +### Setup qtclient project +project(engine_interface VERSION 0.1 LANGUAGES CXX) + +# interface part of engine library +add_library(${PROJECT_NAME} INTERFACE) + + +########################### +# Compiler spesific options +message("Clang compile options: ${CLANG_COMPILE_OPTIONS}") +message("GCC compile options: ${GCC_COMPILE_OPTIONS}") +message("MSVC compile options: ${MSVC_COMPILE_OPTIONS}") + +# Turn on c++17 compile features -- minimum CMake Version 3.8 required +target_compile_features(${PROJECT_NAME} + INTERFACE $<$:cxx_std_17> + INTERFACE $<$:cxx_std_17> + INTERFACE $<$:cxx_std_17> + ) + +# Compile definitions +target_compile_definitions( ${PROJECT_NAME} + INTERFACE $<$: _USE_MATH_DEFINES> + ) + +# Comple options +target_compile_options(${PROJECT_NAME} + INTERFACE $<$: ${CLANG_COMPILE_OPTIONS}> + INTERFACE $<$: ${GCC_COMPILE_OPTIONS}> + INTERFACE $<$: ${MSVC_COMPILE_OPTIONS}> + ) + + +############################ +# Target sources and friends + +# Headers +target_include_directories( ${PROJECT_NAME} INTERFACE + $ +) + + +################################## +# Export targets and configuration +export( TARGETS ${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-targets.cmake" + ) + +# Add alias gmlib2::${PROJECT_NAME} to ${PROJECT_NAME} such that we can reference this +# in the same way as for other consumer usages (external library) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) diff --git a/libs/engine/include/engine/interface/basic_types.h b/libs/interface/include/engine/interface/basic_types.h similarity index 100% rename from libs/engine/include/engine/interface/basic_types.h rename to libs/interface/include/engine/interface/basic_types.h diff --git a/libs/engine/include/engine/interface/gameengine_interface.h b/libs/interface/include/engine/interface/gameengine_interface.h similarity index 100% rename from libs/engine/include/engine/interface/gameengine_interface.h rename to libs/interface/include/engine/interface/gameengine_interface.h diff --git a/libs/engine/include/engine/interface/player_interface.h b/libs/interface/include/engine/interface/player_interface.h similarity index 100% rename from libs/engine/include/engine/interface/player_interface.h rename to libs/interface/include/engine/interface/player_interface.h diff --git a/libs/engine/include/engine/interface/utility_interface.h b/libs/interface/include/engine/interface/utility_interface.h similarity index 100% rename from libs/engine/include/engine/interface/utility_interface.h rename to libs/interface/include/engine/interface/utility_interface.h diff --git a/qtclient/CMakeLists.txt b/qtclient/CMakeLists.txt index a6c5ca4..a206296 100644 --- a/qtclient/CMakeLists.txt +++ b/qtclient/CMakeLists.txt @@ -38,7 +38,6 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) ### Include the engine library -#find_package(engine REQUIRED) target_link_libraries( ${PROJECT_NAME} PUBLIC engine::engine) diff --git a/qtclient/main.cpp b/qtclient/main.cpp index 5aa66a1..a088216 100644 --- a/qtclient/main.cpp +++ b/qtclient/main.cpp @@ -28,6 +28,6 @@ int main(int argc, char** argv) try { catch (std::string exception) { std::cout << "Runtime exception: " << exception << std::endl; } -catch (std::runtime_error exception) { +catch (const std::runtime_error& exception) { std::cout << "Runtime exception: " << exception.what() << std::endl; } diff --git a/tools/benchmark/predefined_utility_benchmark_examples.cpp b/tools/benchmark/predefined_utility_benchmark_examples.cpp index c901b67..d55aece 100644 --- a/tools/benchmark/predefined_utility_benchmark_examples.cpp +++ b/tools/benchmark/predefined_utility_benchmark_examples.cpp @@ -1,7 +1,7 @@ // gtest #include // googletest header file -// cc library +// engine #include namespace detail -- GitLab