diff --git a/CMakeLists.txt b/CMakeLists.txt index d614dcae..e9c00464 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # CMake build instructions for Gwork # configure cmake -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) # we require C++11 - this set appropriate flags for compilers, which may not be portable set(CMAKE_CXX_STANDARD 14) diff --git a/cmake/Config.cmake b/cmake/Config.cmake index c210a767..8bfceee6 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -66,7 +66,9 @@ if(WIN32 AND NOT UNIX) set(INSTALL_MISC_DIR .) # Determine the target architecture, which is useful for linking. - if (CMAKE_GENERATOR MATCHES "Win64") + cmake_host_system_information(RESULT host_is_64 QUERY IS_64BIT) + + if (host_is_64) set(GWK_TARGET_ARCH "x64") else() set(GWK_TARGET_ARCH "x86") @@ -172,14 +174,37 @@ if(RENDER_OPENGL_CORE) set(GWK_INPUT_NAME "GLFW3") set(GWK_PLATFORM_NAME "Cross") - find_package(glm REQUIRED) - find_package(GLEW REQUIRED) + if(USE_VCPKG) + find_package(glm CONFIG REQUIRED) + set(GLM_INCLUDE_DIR ${glm_DIR}) + else() + find_package(glm REQUIRED) + endif() + + if(USE_GLEW) + find_package(GLEW REQUIRED) + set(GWK_RENDER_INCLUDES "${GLM_INCLUDE_DIR}" "${GLEW_INCLUDE_DIR}") + set(GWK_RENDER_LIBRARIES ${GLM_LIBRARIES} ${GLEW_LIBRARIES}) + elseif(USE_GLAD) + find_package(glad CONFIG REQUIRED) + set(GWK_RENDER_LIBRARIES ${GLM_LIBRARIES} glad::glad) + set(GWK_GLAD_API "GLAD") + endif() - set(GWK_RENDER_INCLUDES "${GLM_INCLUDE_DIR}" "${GLEW_INCLUDE_DIR}") - set(GWK_RENDER_LIBRARIES ${GLM_LIBRARIES} ${GLEW_LIBRARIES}) if(USE_GLFW) - find_package(GLFW REQUIRED) + + if(USE_VCPKG) + find_package(glfw3 CONFIG REQUIRED) + elseif() + find_package(GLFW REQUIRED) + endif() + + if(USE_VCPKG) + set(GLFW_LIBRARIES glfw) + set(GLFW_INCLUDE_DIR ${glfw3_DIR}) + endif() + if (APPLE) set(GLFW_DEPENDENCIES "-framework OpenGL") elseif(UNIX) @@ -263,7 +288,7 @@ endif() #----------------------------------------------------------- # MinGW problems -if (WIN32) +if (CMAKE_CXX_COMPILER_ID MATCHES MINGW) set(GWK_RENDER_LIBRARIES ${GWK_RENDER_LIBRARIES} -liconv) endif() diff --git a/source/platform/CMakeLists.txt b/source/platform/CMakeLists.txt index 14f00318..36a64c79 100644 --- a/source/platform/CMakeLists.txt +++ b/source/platform/CMakeLists.txt @@ -44,6 +44,10 @@ source_group("${GWK_SOURCE_FOLDER}" add_definitions(${GWK_LIB_DEFINES}) +if(GWK_GLAD_API) +add_definitions("-DGWK_GL_GLAD=1") +endif() + # Gwork renderer & platform library add_library(Gwork${GWK_RENDER_NAME} STATIC ${GWK_PLATFORM_HEADERS} ${GWK_RENDERER_HEADERS} ${GWK_INPUT_HEADERS} diff --git a/source/platform/renderers/OpenGLCore/OpenGLCore.cpp b/source/platform/renderers/OpenGLCore/OpenGLCore.cpp index a3196d16..97ee4c7c 100644 --- a/source/platform/renderers/OpenGLCore/OpenGLCore.cpp +++ b/source/platform/renderers/OpenGLCore/OpenGLCore.cpp @@ -6,10 +6,18 @@ #include #if defined(__APPLE__) +#if defined(GWK_GL_GLAD) +# include +#else # include +#endif # include #else +#if defined(GWK_GL_GLAD) +# include +#else # include +#endif # include #endif #include diff --git a/source/samples/CMakeLists.txt b/source/samples/CMakeLists.txt index 47edb63a..6a78dad0 100644 --- a/source/samples/CMakeLists.txt +++ b/source/samples/CMakeLists.txt @@ -38,6 +38,10 @@ if(WITH_SAMPLE) add_definitions(-DGWK_SAMPLE -DGWK_SAMPLE_RESOURCE_DIR="${APP_RUNTIME_RESOURCE_DIR}") + if(GWK_GLAD_API) + add_definitions("-DGWK_GL_GLAD=1") + endif() + add_executable(${SAMPLE_NAME} ${APP_BUILD_TYPE} ${SAMPLE_SOURCES} ${SAMPLE_RESOURCES}) target_link_libraries(${SAMPLE_NAME} diff --git a/source/samples/OpenGLCore/OpenGLCoreSample.cpp b/source/samples/OpenGLCore/OpenGLCoreSample.cpp index 1e65d1ad..1030dbcc 100644 --- a/source/samples/OpenGLCore/OpenGLCoreSample.cpp +++ b/source/samples/OpenGLCore/OpenGLCoreSample.cpp @@ -3,8 +3,12 @@ * Copyright (c) 2013-2018 Billy Quith * See license in Gwork.h */ - -#include + +#if defined(GWK_GL_GLAD) +# include +#else +# include +#endif #ifdef USE_DEBUG_FONT # include #else @@ -49,7 +53,7 @@ int main() return EXIT_FAILURE; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); @@ -63,6 +67,15 @@ int main() } glfwMakeContextCurrent(window); + + #if defined(GWK_GL_GLAD) + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { + std::cout << "Glad init error." << std::endl; + glfwTerminate(); + return EXIT_FAILURE; + } + #else glewExperimental = GL_TRUE; GLuint error; if ((error = glewInit()) != GLEW_OK) @@ -71,6 +84,7 @@ int main() glfwTerminate(); return EXIT_FAILURE; } + #endif Gwk::Platform::RelativeToExecutablePaths paths(GWK_SAMPLE_RESOURCE_DIR); @@ -95,7 +109,7 @@ int main() canvas->SetBackgroundColor(Gwk::Color(150, 170, 170, 255)); // Create our unittest control (which is a Window with controls in it) - auto unit = new TestFrame(canvas); + auto unit = new Gwk::Test::TestFrame(canvas); GworkInput.Initialize(canvas); glfwSetKeyCallback(window, key_callback); diff --git a/source/test/CMakeLists.txt b/source/test/CMakeLists.txt index 75826129..3b3c0982 100644 --- a/source/test/CMakeLists.txt +++ b/source/test/CMakeLists.txt @@ -4,8 +4,8 @@ include_directories( ${GWK_SOURCE_DIR}/source/platform/include ${GWK_SOURCE_DIR}/source/gwork/include ${GWK_RENDER_INCLUDES} - ${CMAKE_SOURCE_DIR}/source/util/include - ${CMAKE_SOURCE_DIR}/source/test/include + ${GWK_SOURCE_DIR}/source/util/include + ${GWK_SOURCE_DIR}/source/test/include ${GWK_REFLECT_INCLUDE} )