Skip to content

Commit

Permalink
Updated conanfile and cmake (#56)
Browse files Browse the repository at this point in the history
Updated cmake build to using updated cmake utils
  • Loading branch information
SpinnerX authored Nov 13, 2024
1 parent 34d28d3 commit 4e80031
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 170 deletions.
122 changes: 1 addition & 121 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,126 +2,6 @@ cmake_minimum_required(VERSION 3.25)
project(engine3d C CXX)

set(CMAKE_CXX_STANDARD 23)
set(ENGINE_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/engine3d)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") # works (in creating the compile_commands.json file)

find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)

find_package(Vulkan REQUIRED)
find_package(VulkanHeaders REQUIRED)

if(LINUX)
find_package(VulkanLoader REQUIRED)
endif(LINUX)

find_package(glm REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(imguidocking REQUIRED)
find_package(box2d REQUIRED)
find_package(joltphysics REQUIRED)
find_package(EnTT REQUIRED)

add_subdirectory(Editor)
add_subdirectory(src)

# Copy to compile_commands.json for .clangd
add_custom_target(
copy-compile-commands ALL
DEPENDS
${CMAKE_SOURCE_DIR}/compile_commands.json
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_LIST_DIR}/compile_commands.json
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_LIST_DIR}/compile_commands.json
DEPENDS
# Unlike "proper" targets like executables and libraries,
# custom command / target pairs will not set up source
# file dependencies, so we need to list file explicitly here
generate-compile-commands
${CMAKE_BINARY_DIR}/compile_commands.json
)

# Generate the compilation commands. Necessary so cmake knows where it came
# from and if for some reason you delete it.
add_custom_target(generate-compile-commands
DEPENDS
${CMAKE_BINARY_DIR}/compile_commands.json
)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/compile_commands.json
COMMAND ${CMAKE_COMMAND} -B${CMAKE_BINARY_DIR} -S${CMAKE_SOURCE_DIR}
)

# This is used because if we do not have this users systems may give them a linked error with oldnames.lib
# Usage - used to suppress that lld-link error and use the defaulted linked .library
if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "/Z1" "/NOD")
endif(MSVC)

# target_include_directory is setting some private settings for differentiating what internal includes are privates and what should be includes should be exposed to the application-dev
target_include_directories(${PROJECT_NAME} PRIVATE engine3d/ engine3d/Core)
target_include_directories(${PROJECT_NAME} PUBLIC ${JoltPhysics_SOURCE_DIR} ${GLM_INCLUDE_DIR} ./engine3d)

if(WIN32)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
glfw
${OPENGL_LIBRARIES}
Vulkan::Vulkan
vulkan-headers::vulkan-headers
glm::glm
fmt::fmt
spdlog::spdlog
yaml-cpp::yaml-cpp
imguidocking::imguidocking
box2d::box2d
Jolt::Jolt
EnTT::EnTT
)
endif(WIN32)

if(LINUX)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
glfw
${OPENGL_LIBRARIES}
Vulkan::Loader
glm::glm
fmt::fmt
spdlog::spdlog
yaml-cpp::yaml-cpp
imguidocking::imguidocking
box2d::box2d
Jolt::Jolt
EnTT::EnTT
)
endif(LINUX)

if(APPLE)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
glfw
${OPENGL_LIBRARIES}
Vulkan::Vulkan
vulkan-headers::vulkan-headers
glm::glm
fmt::fmt
spdlog::spdlog
yaml-cpp::yaml-cpp
imguidocking::imguidocking
box2d::box2d
EnTT::EnTT
)
endif(APPLE)

install(TARGETS ${PROJECT_NAME})
26 changes: 2 additions & 24 deletions Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(Editor CXX)

set(
all_src
build_demos(
SOURCES
Editor/Editor.hpp
Editor/Editor.cpp
)

find_package(spdlog REQUIRED)
find_package(glm REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(Vulkan REQUIRED)
# find_package(imguidocking REQUIRED)
# find_package(engine3d REQUIRED)

add_executable(${PROJECT_NAME} ${all_src})

target_include_directories(${PROJECT_NAME} PRIVATE ../)

target_link_libraries(
${PROJECT_NAME}
spdlog::spdlog
glm::glm
yaml-cpp::yaml-cpp
Vulkan::Vulkan
# imguidocking::imguidocking
# engine3d::engine3d
engine3d
)
7 changes: 5 additions & 2 deletions Editor/Editor/Editor.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "Editor.hpp"
#include "Core/Event/InputPoll.hpp"
#include "Core/Event/KeyCodes.hpp"
// #include "Core/Event/InputPoll.hpp"
// #include "Core/Event/KeyCodes.hpp"
#include <engine3d/Core/Event/InputPoll.hpp>
#include <engine3d/Core/Event/KeyCodes.hpp>
#include <engine3d/Core/EngineLogger.hpp>
#include <engine3d/Core/Timestep.hpp>

namespace engine3d{

EditorApplication::EditorApplication(const std::string& p_DebugName) : ApplicationInstance(p_DebugName) {
Expand Down
1 change: 1 addition & 0 deletions Editor/Editor/Editor.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
// #include <engine3d/Core/ApplicationInstance.hpp>
#include <engine3d/Core/ApplicationInstance.hpp>

namespace engine3d{
Expand Down
26 changes: 25 additions & 1 deletion Editor/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,32 @@ class Editor(ConanFile):
settings = "os", "compiler", "build_type", "arch"
exports_sources = "CMakeLists.txt", "Editor/*"

def build_requirements(self):
self.tool_requires("make/4.4.1")
self.tool_requires("cmake/3.27.1")
self.tool_requires("engine3d-cmake-utils/1.0")

def requirements(self):
self.requires("glfw/3.4", transitive_headers=True)
self.requires("opengl/system", transitive_headers=True)
# These end in 1.0 because they are engine3d-customized conan packages
# Slighly modified of the conan packages and it's CMake generators to using "Unix Makefiles"
self.requires("fmt/10.2.1", transitive_headers=True)
self.requires("spdlog/1.14.1", transitive_headers=True)
self.requires("glm/1.0.1", transitive_headers=True)
self.requires("yaml-cpp/0.8.0", transitive_headers=True)
self.requires("box2d/2.4.2")
self.requires("imguidocking/1.0")
self.requires("entt/3.13.2")


self.requires("joltphysics/1.0")

self.requires("vulkan-headers/1.3.290.0")
if self.settings.os == "Linux":
self.requires("vulkan-loader/1.3.290.0")
print(f"OS = {self.settings.os}")

self.requires("engine3d/1.0")

def generate(self):
Expand All @@ -28,4 +52,4 @@ def build(self):
cmake.build()

def layout(self):
cmake_layout(self)
cmake_layout(self)
12 changes: 8 additions & 4 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ class engine3dRecipe(ConanFile):
default_options = {"shared": False, "fPIC": True}

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/CMakeLists.txt", "Editor/CMakeLists.txt", "src/*", "engine3d/*", "Editor/*", "Testbed/*"
# exports_sources = "CMakeLists.txt", "src/CMakeLists.txt", "Editor/CMakeLists.txt", "src/*", "engine3d/*", "Editor/*", "Testbed/*"
exports_sources = "CMakeLists.txt", "src/CMakeLists.txt", "Editor/CMakeLists.txt", "src/*", "engine3d/*",

def requirements(self):
self.requires("make/4.4.1")
def build_requirements(self):
self.tool_requires("make/4.4.1")
self.tool_requires("cmake/3.27.1")
self.tool_requires("engine3d-cmake-utils/1.0")

def requirements(self):
self.requires("glfw/3.4", transitive_headers=True)
self.requires("opengl/system", transitive_headers=True)

self.requires("engine3d-cmake-utils/1.0")

# These end in 1.0 because they are engine3d-customized conan packages
# Slighly modified of the conan packages and it's CMake generators to using "Unix Makefiles"
Expand Down
10 changes: 2 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ set(ENGINE_SRC_DIR engine3d)
set(VULKAN_INCLUDE_DIR ${ENGINE_INCLUDE_NAME}/Core/internal/VulkanCpp)
set(VULKAN_SRC_DIR ${ENGINE_SRC_DIR}/Core/internal/VulkanCpp)

set(
all_headers

build_library(
SOURCES
${ENGINE_INCLUDE_NAME}/Core/ApplicationInstance.hpp

${ENGINE_INCLUDE_NAME}/Core/EngineLogger.hpp
Expand All @@ -30,10 +29,7 @@ set(

# Renderer Includes
${ENGINE_INCLUDE_NAME}/Core/Renderer/Renderer.hpp
)

set(
all_src
${ENGINE_SRC_DIR}/Core/ApplicationInstance.cpp


Expand All @@ -54,5 +50,3 @@ set(

${ENGINE_SRC_DIR}/Core/Renderer/Renderer.cpp
)

add_library(${PROJECT_NAME} ${all_headers} ${all_src})
12 changes: 3 additions & 9 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(example CXX)

find_package(Vulkan REQUIRED)
find_package(engine3d REQUIRED CONFIG)

find_package(engine3d CONFIG REQUIRED)
add_executable(example Application.hpp Application.cpp)
add_executable(${PROJECT_NAME} Application.hpp Application.cpp)

target_link_libraries(${PROJECT_NAME}
Vulkan::Vulkan
# vulkan-headers::vulkan-headers
# imguidocking::imguidocking
engine3d::engine3d
)
target_link_libraries(${PROJECT_NAME} engine3d::engine3d)
4 changes: 3 additions & 1 deletion test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run

class engine3dTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
# self.requires("engine3d/1.0")
self.requires("vulkan-headers/1.3.290.0")
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down

0 comments on commit 4e80031

Please sign in to comment.