From 620b9870c782f5bffca62524fa2444d61c76091c Mon Sep 17 00:00:00 2001 From: valerioformato Date: Sat, 29 Oct 2022 10:44:38 +0200 Subject: [PATCH 1/5] Trying to get VulkanSDK found --- CMakeLists.txt | 16 ++++++++++++++++ WalnutApp/CMakeLists.txt | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 WalnutApp/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..3a94f930 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required (VERSION 3.13) + +project(Walnut) + +if(NOT DEFINED Vulkan_DIR) + message(ERROR "Please provide a valid path to the VulkanSDK") +endif() + +set(CMAKE_PREFIX_PATH ${Vulkan_DIR}) +find_package(Vulkan REQUIRED) + +# TODO: Figure out how to allow later standards +set(CMAKE_CXX_STANDARD 17) + +# add_subdirectory(Walnut) +add_subdirectory(WalnutApp) diff --git a/WalnutApp/CMakeLists.txt b/WalnutApp/CMakeLists.txt new file mode 100644 index 00000000..4e6edffc --- /dev/null +++ b/WalnutApp/CMakeLists.txt @@ -0,0 +1,6 @@ +file(GLOB_RECURSE WalnutApp_SRC LIST_DIRECTORIES false src/*.cpp) + +add_executable(WalnutApp ${WalnutApp_SRC}) +target_include_directories(WalnutApp PRIVATE src) + +install(WalnutApp DESTINATION bin) \ No newline at end of file From f38fb299402728180fe8d33d80439851516cacb8 Mon Sep 17 00:00:00 2001 From: Valerio Formato Date: Sat, 29 Oct 2022 12:59:46 +0200 Subject: [PATCH 2/5] Integrate all vendor projects and setup compilation Still TODO: main is still under windows-only flags, create a linux version? --- .gitignore | 1 + CMakeLists.txt | 11 +++++------ Walnut/CMakeLists.txt | 9 +++++++++ WalnutApp/CMakeLists.txt | 3 ++- vendor/CMakeLists.txt | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 Walnut/CMakeLists.txt create mode 100644 vendor/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 984bf650..ba14b481 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .vs/ bin/ bin-int/ +*build*/ # Files *.vcxproj diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a94f930..23582798 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,15 +2,14 @@ cmake_minimum_required (VERSION 3.13) project(Walnut) -if(NOT DEFINED Vulkan_DIR) - message(ERROR "Please provide a valid path to the VulkanSDK") -endif() - set(CMAKE_PREFIX_PATH ${Vulkan_DIR}) find_package(Vulkan REQUIRED) # TODO: Figure out how to allow later standards -set(CMAKE_CXX_STANDARD 17) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() -# add_subdirectory(Walnut) +add_subdirectory(vendor) +add_subdirectory(Walnut) add_subdirectory(WalnutApp) diff --git a/Walnut/CMakeLists.txt b/Walnut/CMakeLists.txt new file mode 100644 index 00000000..b30d8c7a --- /dev/null +++ b/Walnut/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB_RECURSE Walnut_SRC LIST_DIRECTORIES false src/*.cpp) + +add_library(Walnut STATIC ${Walnut_SRC}) +target_include_directories(Walnut PUBLIC src) +set_property(TARGET Walnut PROPERTY POSITION_INDEPENDENT_CODE ON) + +target_link_libraries(Walnut PUBLIC imgui glfw glm::glm stb_image vulkan) + +install(TARGETS Walnut DESTINATION bin) diff --git a/WalnutApp/CMakeLists.txt b/WalnutApp/CMakeLists.txt index 4e6edffc..d2b8cf64 100644 --- a/WalnutApp/CMakeLists.txt +++ b/WalnutApp/CMakeLists.txt @@ -2,5 +2,6 @@ file(GLOB_RECURSE WalnutApp_SRC LIST_DIRECTORIES false src/*.cpp) add_executable(WalnutApp ${WalnutApp_SRC}) target_include_directories(WalnutApp PRIVATE src) +target_link_libraries(WalnutApp PRIVATE Walnut) -install(WalnutApp DESTINATION bin) \ No newline at end of file +install(TARGETS WalnutApp DESTINATION bin) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt new file mode 100644 index 00000000..a0d5680e --- /dev/null +++ b/vendor/CMakeLists.txt @@ -0,0 +1,16 @@ +# Setup vendor libraries +## IMGUI (No CMake support, we have to roll or own) +set(imgui_SRC imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/imgui_demo.cpp) +add_library(imgui STATIC ${imgui_SRC}) +target_include_directories(imgui PUBLIC imgui) +set_property(TARGET imgui PROPERTY POSITION_INDEPENDENT_CODE ON) + +## GLFW (comes with its own CMakeLists, let's use that) +add_subdirectory(GLFW) + +## glm (comes with its own CMakeLists, let's use that) +add_subdirectory(glm) + +## stb_image (header-only, create a dummy interface library) +add_library(stb_image INTERFACE) +target_include_directories(stb_image INTERFACE stb_image) From ea51fa20180409845c28f000b0f71089895ae15b Mon Sep 17 00:00:00 2001 From: Valerio Formato Date: Sat, 29 Oct 2022 17:19:39 +0200 Subject: [PATCH 3/5] Add an entrypoint for linux as well :) --- Walnut/CMakeLists.txt | 15 ++++++++++++++- Walnut/src/Walnut/EntryPoint.h | 8 ++------ WalnutApp/CMakeLists.txt | 13 +++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Walnut/CMakeLists.txt b/Walnut/CMakeLists.txt index b30d8c7a..d6f583cf 100644 --- a/Walnut/CMakeLists.txt +++ b/Walnut/CMakeLists.txt @@ -2,7 +2,20 @@ file(GLOB_RECURSE Walnut_SRC LIST_DIRECTORIES false src/*.cpp) add_library(Walnut STATIC ${Walnut_SRC}) target_include_directories(Walnut PUBLIC src) -set_property(TARGET Walnut PROPERTY POSITION_INDEPENDENT_CODE ON) +# set_property(TARGET Walnut PROPERTY POSITION_INDEPENDENT_CODE ON) + +# setup internal project compile definition +if(WIN32) + target_compile_definitions(Walnut PRIVATE WL_PLATFORM_WINDOWS) +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_definitions(Walnut PRIVATE WL_DEBUG) +elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + target_compile_definitions(Walnut PRIVATE WL_RELEASE) +elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + target_compile_definitions(Walnut PRIVATE WL_DIST) +endif() target_link_libraries(Walnut PUBLIC imgui glfw glm::glm stb_image vulkan) diff --git a/Walnut/src/Walnut/EntryPoint.h b/Walnut/src/Walnut/EntryPoint.h index 8e88cffb..a44a1c74 100644 --- a/Walnut/src/Walnut/EntryPoint.h +++ b/Walnut/src/Walnut/EntryPoint.h @@ -1,7 +1,5 @@ #pragma once -#ifdef WL_PLATFORM_WINDOWS - extern Walnut::Application* Walnut::CreateApplication(int argc, char** argv); bool g_ApplicationRunning = true; @@ -21,7 +19,7 @@ namespace Walnut { } -#ifdef WL_DIST +#if defined(WL_DIST) && defined(WL_PLATFORM_WINDOWS) #include @@ -37,6 +35,4 @@ int main(int argc, char** argv) return Walnut::Main(argc, argv); } -#endif // WL_DIST - -#endif // WL_PLATFORM_WINDOWS +#endif // WL_DIST && WL_PLATFORM_WINDOWS diff --git a/WalnutApp/CMakeLists.txt b/WalnutApp/CMakeLists.txt index d2b8cf64..1e5c96f8 100644 --- a/WalnutApp/CMakeLists.txt +++ b/WalnutApp/CMakeLists.txt @@ -4,4 +4,17 @@ add_executable(WalnutApp ${WalnutApp_SRC}) target_include_directories(WalnutApp PRIVATE src) target_link_libraries(WalnutApp PRIVATE Walnut) +# setup internal project compile definition +if(WIN32) + target_compile_definitions(Walnut PRIVATE WL_PLATFORM_WINDOWS) +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_definitions(WalnutApp PRIVATE WL_DEBUG) +elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + target_compile_definitions(WalnutApp PRIVATE WL_RELEASE) +elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + target_compile_definitions(WalnutApp PRIVATE WL_DIST) +endif() + install(TARGETS WalnutApp DESTINATION bin) From 2f0acf576128e5080e3fb54224a520cb522ac1c5 Mon Sep 17 00:00:00 2001 From: Valerio Formato Date: Sun, 30 Oct 2022 11:07:46 +0100 Subject: [PATCH 4/5] Link correct Vulkan target --- CMakeLists.txt | 1 - Walnut/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23582798..28fe4fd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required (VERSION 3.13) project(Walnut) -set(CMAKE_PREFIX_PATH ${Vulkan_DIR}) find_package(Vulkan REQUIRED) # TODO: Figure out how to allow later standards diff --git a/Walnut/CMakeLists.txt b/Walnut/CMakeLists.txt index d6f583cf..993133ba 100644 --- a/Walnut/CMakeLists.txt +++ b/Walnut/CMakeLists.txt @@ -17,6 +17,6 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release") target_compile_definitions(Walnut PRIVATE WL_DIST) endif() -target_link_libraries(Walnut PUBLIC imgui glfw glm::glm stb_image vulkan) +target_link_libraries(Walnut PUBLIC imgui glfw glm::glm stb_image Vulkan::Vulkan) install(TARGETS Walnut DESTINATION bin) From b87dd5c28e8d7333201644cebd2aaf2a46041c00 Mon Sep 17 00:00:00 2001 From: Valerio Formato Date: Sun, 30 Oct 2022 11:08:08 +0100 Subject: [PATCH 5/5] Link to dwmapi dll on Windows (required by GLFW) --- Walnut/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Walnut/CMakeLists.txt b/Walnut/CMakeLists.txt index 993133ba..5bc06210 100644 --- a/Walnut/CMakeLists.txt +++ b/Walnut/CMakeLists.txt @@ -18,5 +18,8 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release") endif() target_link_libraries(Walnut PUBLIC imgui glfw glm::glm stb_image Vulkan::Vulkan) +if(WIN32) + target_link_libraries(Walnut PUBLIC dwmapi) +endif() install(TARGETS Walnut DESTINATION bin)