diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 1d16ee7..54e53c7 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -3,16 +3,8 @@ 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: @@ -20,47 +12,29 @@ jobs: 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 diff --git a/.gitignore b/.gitignore index f0fbff8..edd8bbf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,7 @@ compile_commands.json CMakeUserPresets.json .scannerwork sonar-project.properties +.conan +.venv + +lib/GUI/bindings \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3141d07..40f86ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakePresets.json b/CMakePresets.json deleted file mode 100644 index bf619df..0000000 --- a/CMakePresets.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 26, - "patch": 0 - }, - "configurePresets": [ - { - "name": "default-debug", - "hidden": true, - "generator": "Ninja", - "description": "Use this preset for Debug builds", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - } - ] -} diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..b4ddddf --- /dev/null +++ b/conanfile.py @@ -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() + + \ No newline at end of file diff --git a/lib/Core/CMakeLists.txt b/lib/Core/CMakeLists.txt index 90b1d97..eefe9e4 100644 --- a/lib/Core/CMakeLists.txt +++ b/lib/Core/CMakeLists.txt @@ -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 +) diff --git a/lib/GUI/CMakeLists.txt b/lib/GUI/CMakeLists.txt index c94edae..1ca3e24 100644 --- a/lib/GUI/CMakeLists.txt +++ b/lib/GUI/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.26) project(IRCGui) # find glfw3 package @@ -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 @@ -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) \ No newline at end of file diff --git a/lib/Graphics/CMakeLists.txt b/lib/Graphics/CMakeLists.txt index 63d4379..3643d1b 100644 --- a/lib/Graphics/CMakeLists.txt +++ b/lib/Graphics/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.26) project(IRCGraphics) set(CMAKE_CXX_STANDARD 20) diff --git a/lib/Network/CMakeLists.txt b/lib/Network/CMakeLists.txt index ba6a078..5a5fe0d 100644 --- a/lib/Network/CMakeLists.txt +++ b/lib/Network/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.26) project(IRCNetwork) set(CMAKE_CXX_STANDARD 20) diff --git a/test_graphics.cpp b/test_graphics.cpp index 56e639b..f0614c9 100644 --- a/test_graphics.cpp +++ b/test_graphics.cpp @@ -1,5 +1,3 @@ -#include - #include "GUI/GUIWindow.h" #include "Core/Application.h" diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 97c9737..aed5be7 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -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) diff --git a/tests/core/command_line_parser_test.cpp b/tests/core/command_line_parser_test.cpp index f40c374..f243839 100644 --- a/tests/core/command_line_parser_test.cpp +++ b/tests/core/command_line_parser_test.cpp @@ -3,3 +3,10 @@ using namespace IRC; + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} \ No newline at end of file diff --git a/tests/core/core_test.cpp b/tests/core/core_test.cpp index 4e0f939..ae5af1e 100644 --- a/tests/core/core_test.cpp +++ b/tests/core/core_test.cpp @@ -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; +} \ No newline at end of file diff --git a/tests/network/CMakeLists.txt b/tests/network/CMakeLists.txt index 9926c67..d5b9744 100644 --- a/tests/network/CMakeLists.txt +++ b/tests/network/CMakeLists.txt @@ -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 ) \ No newline at end of file diff --git a/tests/network/network_test.cpp b/tests/network/network_test.cpp index 7defe86..e34da14 100644 --- a/tests/network/network_test.cpp +++ b/tests/network/network_test.cpp @@ -200,3 +200,10 @@ TEST_F(NetworkFixture, TcpServerNextPendingConnection) { EXPECT_FALSE(socketServer->getFileDescriptor().has_value()); EXPECT_FALSE(socketClient.getFileDescriptor().has_value()); } + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json deleted file mode 100644 index 63c5327..0000000 --- a/vcpkg.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "dependencies": [ - "boost-signals2", - "gtest", - "glfw3", - "glad", - "glm", - { - "name": "imgui", - "features": [ - "glfw-binding", - "opengl3-binding" - ] - } - ] -}