Skip to content

Commit

Permalink
vcpkg replaced by conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloPicose committed Dec 30, 2024
1 parent 9d0ce7c commit 6e4be32
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 113 deletions.
42 changes: 8 additions & 34 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,38 @@ name: C/C++ CI
on:
push:
branches: [ "main" ]
#paths:
# - '**/*.cpp'
# - '**/*.h'
# - '**/CMakeLists.txt'
pull_request:
branches: [ "main" ]
#paths:
# - '**/*.cpp'
# - '**/*.h'
# - '**/CMakeLists.txt'

jobs:
build-ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Set up a specific Node.js version
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

# Install system dependencies
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config

# Install and cache vcpkg
- name: Setup vcpkg
uses: actions/cache@v3
with:
path: |
./vcpkg
!./vcpkg/downloads
key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/*.cpp', '**/*.h') }}
restore-keys: |
${{ runner.os }}-vcpkg-
# Install vcpkg
- name: Install vcpkg
- name: Setup Conan
run: |
if [ ! -d "vcpkg" ]; then
git clone https://github.com/Microsoft/vcpkg.git
fi
./vcpkg/bootstrap-vcpkg.sh
pip install conan
conan --version
conan profile new default --detect --force
# Install dependencies
- name: Install dependencies
- name: Install Conan dependencies
run: |
./vcpkg/vcpkg install
conan install . --build=missing -s build_type=Release
# Configure project with CMake and set toolchain file
- name: Configure CMake
- name: Configure CMake with Conan
run: |
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=conan_paths.cmake
cmake --build build
# Optionally run tests or other commands
- name: Execute tests
run: |
cmake --build build --target test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ compile_commands.json
CMakeUserPresets.json
.scannerwork
sonar-project.properties
.conan
.venv

lib/GUI/bindings
25 changes: 15 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
cmake_minimum_required(VERSION 3.28)

cmake_policy(SET CMP0167 NEW)
cmake_minimum_required(VERSION 3.26)

project(NexusNodeFramework)

# option to enable/disable testing
option(ENABLE_TESTING "Enable testing" ON)
# option to enable/disable building the GUI
option(BUILD_GUI "Build the GUI" ON)

enable_testing()

set(CMAKE_CXX_STANDARD 20)

add_executable(POACS main.cpp)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(lib/Core)
add_subdirectory(lib/Network)
#add_subdirectory(lib/Graphics)
add_subdirectory(lib/GUI)

target_link_libraries(POACS PRIVATE IRCCore IRCNetwork)
if(BUILD_GUI)
add_subdirectory(lib/GUI)

add_executable(graphics_test test_graphics.cpp)
target_link_libraries(graphics_test IRCNetwork IRCGui)
endif()

add_subdirectory(tests)
if (ENABLE_TESTING)
add_subdirectory(tests)
endif()

add_executable(graphics_test test_graphics.cpp)
target_link_libraries(graphics_test IRCNetwork IRCGui)
19 changes: 0 additions & 19 deletions CMakePresets.json

This file was deleted.

77 changes: 77 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
from conan import ConanFile
from conan.tools.files import copy
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps

# you may need the option:
# -c tools.system.package_manager:mode=install
# -c tools.system.package_manager:sude=True

# Options can be passed with the command line with the following syntax:
# -o nnf/*:shared=True -o nnf/*:with_tests=False -o nnf/*:with_gui=True

class NexusNodeFramework(ConanFile):
name = "nnf"
version = "0.1"

# Binary configuration
settings = "os", "compiler", "build_type"
options = {"shared": [True, False], "with_tests": [True, False], "with_gui": [True, False]}
default_options = {"shared": False, "with_tests": True, "with_gui": True}

def requirements(self):
self.requires("boost/[~1]")
if self.options.with_gui:
self.requires("imgui/[~1]")
self.requires("glad/[~0]")
self.requires("glfw/[~3]")
if self.options.with_tests:
self.requires("gtest/[~1]")

def build_requirements(self):
self.tool_requires("cmake/[~3]")
self.tool_requires("ninja/[~1]")

def layout(self):
cmake_layout(self)
# configure the output of the conan files to '.conan' in linux
# in windows will be in 'build'
multi = True if self.settings.get_safe("compiler") == "msvc" else False
if multi:
self.folders.generators = os.path.join("build", "generators")
self.folders.build = "build"
else:
self.folders.generators = os.path.join(".conan", str(self.settings.build_type), "generators")
self.folders.build = os.path.join(".conan", str(self.settings.build_type))

def generate(self):
# imports the backend render from imgui into the folder bindings
if self.options.with_gui:
copy(self, "*glfw*", os.path.join(self.dependencies["imgui"].package_folder,
"res", "bindings"), os.path.join(self.source_folder, "lib/GUI/bindings"))
copy(self, "*opengl3*", os.path.join(self.dependencies["imgui"].package_folder,
"res", "bindings"), os.path.join(self.source_folder, "lib/GUI/bindings"))

# Generates the project files from cmake
deps = CMakeDeps(self)
deps.generate()

tc = CMakeToolchain(self,
generator="Ninja")
tc.variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = "ON"
tc.variables["CMAKE_BUILD_TYPE"] = self.settings.build_type
# pass the option BUILD_GUI to the cmake
tc.variables["BUILD_GUI"] = self.options.with_gui
tc.variables["ENABLE_TESTING"] = self.options.with_tests
tc.generate()

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

def package(self):
cmake = CMake(self)
cmake.install()


47 changes: 31 additions & 16 deletions lib/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
cmake_minimum_required(VERSION 3.28)
cmake_minimum_required(VERSION 3.26)
project(IRCCore)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(H_FILES)
set(CPP_FILES)
function(add_class CLASS_NAME)
# Append the header and source file paths to the global lists
list(APPEND H_FILES "src/Core/${CLASS_NAME}.h")
list(APPEND CPP_FILES "src/Core/${CLASS_NAME}.cpp")

find_package(Boost REQUIRED COMPONENTS signals2)
# Set the variables in the parent scope (CMakeLists.txt where the function is called)
set(H_FILES "${H_FILES}" PARENT_SCOPE)
set(CPP_FILES "${CPP_FILES}" PARENT_SCOPE)
endfunction()

find_package(Boost REQUIRED)

add_class(Application)
add_class(CommandLineParser)
add_class(Node)
add_class(NodePtr)
add_class(Timer)

add_library(IRCCore STATIC
src/Core/Application.cpp
src/Core/Application.h
src/Core/CommandLineParser.cpp
src/Core/CommandLineParser.h
src/Core/pch.h
src/Core/Node.cpp
src/Core/Node.h
src/Core/NodePtr.cpp
src/Core/NodePtr.h
src/Core/Timer.h
src/Core/Timer.cpp
${H_FILES}
${CPP_FILES}
)

target_precompile_headers(IRCCore PUBLIC
src/Core/pch.h
)

set_target_properties(IRCCore PROPERTIES PUBLIC_HEADER "${H_FILES}")

target_include_directories(IRCCore PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)

target_link_libraries(IRCCore PUBLIC Boost::signals2)
target_link_libraries(IRCCore PUBLIC boost::boost)

# Install the library, the library should be in the lib folder
# and the headers should be in the include folder
install(TARGETS IRCCore
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/IRCCore
)
22 changes: 17 additions & 5 deletions lib/GUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.28)
cmake_minimum_required(VERSION 3.26)
project(IRCGui)

# find glfw3 package
Expand All @@ -8,9 +8,6 @@ find_package(OpenGL REQUIRED)

find_package(imgui CONFIG REQUIRED)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(IRCGui STATIC
src/GUI/GUIWindow.cpp
src/GUI/GUIWindow.h
Expand All @@ -21,6 +18,21 @@ target_include_directories(IRCGui PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)

target_link_libraries(IRCGui PUBLIC IRCCore)
target_link_libraries(IRCGui PUBLIC IRCCore imgui_glfw_opengl3_bindings)
target_link_libraries(IRCGui PUBLIC imgui::imgui)
target_link_libraries(IRCGui PRIVATE OpenGL::GL glad::glad glfw)


# compile bindings
add_library(imgui_glfw_opengl3_bindings STATIC
bindings/imgui_impl_glfw.cpp
bindings/imgui_impl_glfw.h
bindings/imgui_impl_opengl3_loader.h
bindings/imgui_impl_opengl3.h
bindings/imgui_impl_opengl3.cpp
)

target_include_directories(imgui_glfw_opengl3_bindings PUBLIC bindings)

target_link_libraries(imgui_glfw_opengl3_bindings PRIVATE OpenGL::GL glad::glad glfw)
target_link_libraries(imgui_glfw_opengl3_bindings PUBLIC imgui::imgui)
2 changes: 1 addition & 1 deletion lib/Graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.28)
cmake_minimum_required(VERSION 3.26)
project(IRCGraphics)

set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion lib/Network/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.28)
cmake_minimum_required(VERSION 3.26)
project(IRCNetwork)

set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 0 additions & 2 deletions test_graphics.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <glad/glad.h>

#include "GUI/GUIWindow.h"

#include "Core/Application.h"
Expand Down
16 changes: 8 additions & 8 deletions tests/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ add_test(core_tests core_tests)

# command line parser test

add_executable(command_line_parser_test
command_line_parser_test.cpp)
#add_executable(command_line_parser_test
#command_line_parser_test.cpp)

target_link_libraries(command_line_parser_test
IRCCore
GTest::GTest
GTest::Main
)
#target_link_libraries(command_line_parser_test
#IRCCore
#GTest::GTest
#GTest::Main
#)

add_test(command_line_parser_test command_line_parser_test)
#add_test(command_line_parser_test command_line_parser_test)
7 changes: 7 additions & 0 deletions tests/core/command_line_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@


using namespace IRC;

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}
7 changes: 7 additions & 0 deletions tests/core/core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,10 @@ TEST_F(CoreFixture, TimerSingleShotFunction) {
ASSERT_EQ(Application::instance()->getAliveNodesCount(), 0);
EXPECT_EQ(Application::instance()->getRootNodesCount(), 0);
}

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}
2 changes: 1 addition & 1 deletion tests/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_executable(network_tests
target_link_libraries(network_tests
IRCNetwork
GTest::GTest
GTest::Main
# GTest::Main
)

add_test(network_tests network_tests )
Loading

0 comments on commit 6e4be32

Please sign in to comment.