diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 700e27b85..5f7e6d396 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,78 +18,33 @@ jobs: fail-fast: false # see https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#handling-failures runs-on: ${{ matrix.os }} env: - BUILD_TYPE: Release # possible options: MinSizeRel Release, Debug, RelWithDebInfo - BUILD_PATH: cmake-build - INSTALL_PATH: out + # Those are read by rake script + BUILD_TYPE: debug # release|debug + VERBOSE: true steps: - - name: Install dependencies (Linux) - if: runner.os == 'Linux' # see https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context - run: sudo apt-get update && sudo apt-get install libegl1-mesa-dev libdbus-1-dev libgtk-3-dev - - - name: Install dependencies (macOS) - if: runner.os == 'macOS' # see https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context - run: brew install mesalib-glw - - name: Git Checkout uses: actions/checkout@v4 with: submodules: true - - name: Create Build Environment - # Some projects don't allow in-source building, so create a separate build directory - # We'll use this as our working directory for all subsequent commands - run: cmake -E make_directory ${{env.BUILD_PATH}} + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' # Not needed with a `.ruby-version` or `.tool-versions` - - name: Configure CMake + - name: Install Dependencies shell: bash - working-directory: ${{env.BUILD_PATH}} - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DGITHUB_REF_NAME=${{github.ref_name}} -DGITHUB_SHA=${{github.sha}} + run: rake install --trace - name: Build - working-directory: ${{env.BUILD_PATH}} - shell: bash - run: cmake --build . --config ${{env.BUILD_TYPE}} --target install - - - name: CTest - working-directory: ${{env.BUILD_PATH}} shell: bash - run: ctest -C ${{env.BUILD_TYPE}} --verbose --output-on-failure + run: rake build --trace - - name: CPack - working-directory: ${{env.BUILD_PATH}} + - name: Test shell: bash - run: cpack -C ${{env.BUILD_TYPE}} + run: rake test --trace - name: Binary Artifact uses: actions/upload-artifact@v4 with: name: nodable-${{ runner.os }} - path: ${{env.INSTALL_PATH}}/app/* - - - name: Package Artifact - uses: actions/upload-artifact@v4 - with: - name: nodable-package-${{ runner.os }} - path: | - !${{env.INSTALL_PATH}}/package/_CPack_Packages - ${{env.INSTALL_PATH}}/package/*.* - - doxygen: - runs-on: [ubuntu-20.04] - needs: [build] - if: ${{ success() }} # see https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions - steps: - - name: Git recursive checkout - uses: actions/checkout@v4 - - - name: Install dependencies - run: sudo apt-get update && sudo apt-get install doxygen - - - name: Generate documentation - run: cd docs && doxygen - - - name: Upload documentation artifact - uses: actions/upload-artifact@v4 - with: - name: Nodable-Technical-Documentation - path: ${{runner.workspace}}/Nodable/docs/doxygen \ No newline at end of file + path: build-${{env.BUILD_TYPE}}/nodable \ No newline at end of file diff --git a/.gitignore b/.gitignore index 03453c97e..4542a426f 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,8 @@ _screenshots/ /nodable/install/ /bin/ /cmake-** +/rake-** +/build-** /.idea .gitconfig .cache diff --git a/.gitmodules b/.gitmodules index bf0a0f41e..94a31c9e4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "libs/glm"] path = libs/glm url = https://github.com/g-truc/glm.git +[submodule "libs/cpptrace"] + path = libs/cpptrace + url = https://github.com/jeremy-rifkin/cpptrace.git diff --git a/CHANGELOG.md b/CHANGELOG.md index 9071b5bf2..697d70f8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Author: Bérenger Dalle-Cort, 2017-2024 ### v1.0: - graph is now always abstract + - fd - interpreter (build, run, debug etc) is disabled by default and is considered out of scope, but can be enabled via the Developer>Experimental menu, - improved the Graph user interface to create_new graph more easily, - implemented an optimized StateMachine to simplify code (it avoids an OOP version of it! Thanks to Rémi ;)), diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 4f4979ce1..000000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,578 +0,0 @@ -# Project CMakeLists.txt -#======================== - -# include *.cmake scripts -include(scripts/cmake/log.cmake) -include(scripts/cmake/set-build-ref-variable.cmake) - -# prerequisites: -cmake_policy(VERSION 3.14) -cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0" CACHE STRING "Minimum OS X deployment version") # must be declared BEFORE project -# GitHub Actions does not support v11 - -# project declaration -project("Nodable" - VERSION "1.0" - LANGUAGES CXX C) - -# options/variables -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/) -set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/out/app") # ./out/ folder must not be changed, referenced in readme.md -set(NDBL_APP_NAME "Nodable") -set(NDBL_PACKAGE_DIR "${CMAKE_CURRENT_LIST_DIR}/out/package") # // -set(NDBL_CONFIGURED_DIR "${PROJECT_BINARY_DIR}/configured/ndbl") -set(NDBL_SKIP_TESTS OFF) -set(TOOLS_POOL_ENABLE OFF) # Keep OFF until refactor, PoolID is too intrusive. - -# set a build type to Release by default if not set: -if ( NOT DEFINED CMAKE_BUILD_TYPE ) - set( CMAKE_BUILD_TYPE Release) -endif() - -# Get architecture -if ( NOT ${CMAKE_SIZEOF_VOID_P} MATCHES 8) - ndbl_err("A 64bits architecture CPU is required to build this project") -endif () - -# avoid "unable to run shared libraries" under linux -include(CheckPIESupported) -check_pie_supported() - -# specify the C++ standard -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) # when ON, it will use the custom lib++ instead of stdlib++ - -# enable threads (we have some std::async in ndbl_app) -set(THREADS_PREFER_PTHREAD_FLAG ON) - -# Defines TOOLS_DEBUG/NDBL_DEBUG when in Debug -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DTOOLS_DEBUG -DNDBL_DEBUG") - -if(WIN32) - add_compile_definitions(NOMINMAX) # avoid min/max macros causing conflicts with min/max functions -endif () - -if (TOOLS_NO_POOL) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTOOLS_NO_POOL") -endif () - -# disable char8_t when using CPP 20 -if ( CMAKE_CXX_STANDARD EQUAL 20 ) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-char8_t") - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-char8_t") - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-char8_t") - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:char8_t-") - else () - ndbl_err("The compiler you are using is not handled my this script, you have to manually add a case to is if/else in order to set a flag to disable char8_t") - endif() -endif() - -# add subdirectories -#------------------- - -# Libraries: we only add the libraries that have a CMakeList, otherwise we append sources directly. - -include(FetchContent) -FetchContent_Declare( - cpptrace - GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git - GIT_TAG v0.5.4 # - EXCLUDE_FROM_ALL -) -FetchContent_MakeAvailable(cpptrace) - -if (NOT NDBL_SKIP_TESTS) - enable_testing() - # https://stackoverflow.com/questions/12540970/how-to-make-gtest-build-mdd-instead-of-mtd-by-default-using-cmake - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - # we don't need mocks (for now) nor install - option(BUILD_GMOCK OFF) - option(INSTALL_GTEST OFF) - add_subdirectory(libs/googletest EXCLUDE_FROM_ALL) -endif () - -set(BENCHMARK_ENABLE_GTEST_TESTS OFF) -set(BENCHMARK_ENABLE_TESTING OFF) -add_subdirectory(libs/google/benchmark EXCLUDE_FROM_ALL) -set(GLM_EXT_INCLUDED ON) -add_subdirectory(libs/glm EXCLUDE_FROM_ALL) -add_subdirectory(libs/freetype EXCLUDE_FROM_ALL) -set(NFD_PORTAL ON) # use portal instead of gtk, read: https://github.com/btzy/nativefiledialog-extended#using-xdg-desktop-portal-on-linux -add_subdirectory(libs/nativefiledialog-extended EXCLUDE_FROM_ALL) # target is nfd -add_subdirectory(libs/SDL EXCLUDE_FROM_ALL) # SDL2 - -# 1) Nodable -#=========== - -ndbl_log("Looking for libraries ...") - -find_package(Threads REQUIRED) -if (NOT Threads_FOUND) - ndbl_err("Threads not found") -endif () - -find_package(OpenGL REQUIRED) -if (NOT OpenGL_FOUND) - ndbl_err("OpenGL not found") -endif () - -ndbl_log("Threads found: ${Threads_FOUND}") -ndbl_log("OpenGL found: ${OpenGL_FOUND}") - -# Includes for all (tools and nodable) targets -include_directories( - src - libs - libs/Observe/include - libs/SDL/include - libs/gl3w - libs/gl3w/GL - libs/imgui - libs/whereami/src - libs/glm - libs/IconFontCppHeaders -) - - -# 1.1) Framework Core -#-------------------- - -add_library( - tools-core - STATIC - src/tools/core/Event.h - src/tools/core/EventManager.cpp - src/tools/core/EventManager.h - src/tools/core/StateMachine.cpp - src/tools/core/StateMachine.h - src/tools/core/TIdentifier.h - src/tools/core/TaskManager.cpp - src/tools/core/TaskManager.cpp - src/tools/core/TaskManager.h - src/tools/core/TaskManager.h - src/tools/core/assertions.h - src/tools/core/format.cpp - src/tools/core/format.h - src/tools/core/hash.h - src/tools/core/log.cpp - src/tools/core/log.h - src/tools/core/math.h - src/tools/core/TryCatch.h - src/tools/core/memory/Pool.h - src/tools/core/memory/Pool.inl - src/tools/core/memory/PoolManager.cpp - src/tools/core/memory/PoolManager.h - src/tools/core/memory/memory.h - src/tools/core/memory/pointers.cpp - src/tools/core/memory/pointers.h - src/tools/core/reflection/Invokable.h - src/tools/core/reflection/Operator.h - src/tools/core/reflection/Operator_t.h - src/tools/core/reflection/Initializer.h - src/tools/core/reflection/enum.h - src/tools/core/reflection/qword.cpp - src/tools/core/reflection/qword.h - src/tools/core/reflection/reflection - src/tools/core/reflection/Type.cpp - src/tools/core/reflection/Type.h - src/tools/core/reflection/TypeRegister.cpp - src/tools/core/reflection/TypeRegister.h - src/tools/core/reflection/union.h - src/tools/core/reflection/variant.cpp - src/tools/core/reflection/variant.h - src/tools/core/string.h - src/tools/core/System.cpp - src/tools/core/System.h - src/tools/core/FileSystem.cpp - src/tools/core/FileSystem.h - src/tools/core/types.h - src/tools/gui/Color.h - # libraries - libs/whereami/src/whereami.c - libs/whereami/src/whereami.h -) - -target_link_libraries( - tools-core - PUBLIC - glm # math - Threads::Threads - cpptrace::cpptrace -) - -add_executable( - test-tools - src/tools/core/Delegate.specs.cpp - src/tools/core/reflection/reflection.specs.cpp - src/tools/core/reflection/Type.specs.cpp - src/tools/core/memory/Pool.specs.cpp - src/tools/gui/geometry/Rect.specs.cpp - src/tools/gui/geometry/SpatialNode2D.specs.cpp -) - -target_link_libraries(test-tools PUBLIC gtest_main gtest tools-core tools-gui) -add_test(NAME test_tools COMMAND test-tools) - -add_executable(bench-fw-core-string src/tools/core/string.bench.cpp) -target_link_libraries(bench-fw-core-string PUBLIC benchmark::benchmark tools-core) - -if( TOOLS_POOL_ENABLE ) - add_executable(bench-fw-core-Pool src/tools/core/memory/Pool.bench.cpp - NAMING.md) - target_link_libraries(bench-fw-core-Pool PUBLIC benchmark::benchmark tools-core) -endif() - -# 1.2) Framework GUI -#------------------- - -add_library( - tools-gui - STATIC - src/tools/gui/geometry/BoxShape2D.h - src/tools/gui/geometry/BoxShape2D.cpp - src/tools/gui/geometry/BezierCurveSegment2D.h - src/tools/gui/geometry/BezierCurveSegment2D.cpp - src/tools/gui/geometry/Rect.h - src/tools/gui/geometry/Rect.cpp - src/tools/gui/geometry/Space.h - src/tools/gui/geometry/Vec2.h - src/tools/gui/geometry/Vec4.h - src/tools/gui/geometry/SpatialNode2D.h - src/tools/gui/geometry/SpatialNode2D.cpp - src/tools/gui/geometry/TRSTransform2D.h - src/tools/gui/geometry/TRSTransform2D.cpp - src/tools/gui/Action.cpp - src/tools/gui/Action.h - src/tools/gui/ActionManager.cpp - src/tools/gui/ActionManager.h - src/tools/gui/ActionManagerView.cpp - src/tools/gui/ActionManagerView.h - src/tools/gui/App.cpp - src/tools/gui/App.h - src/tools/gui/AppView.cpp - src/tools/gui/AppView.h - src/tools/gui/Config.cpp - src/tools/gui/Config.h - src/tools/gui/FontManager.cpp - src/tools/gui/FontManager.h - src/tools/gui/FontManagerConfig.h - src/tools/gui/ImGuiEx.cpp - src/tools/gui/ImGuiEx.h - src/tools/gui/ImGuiExConfig.h - src/tools/gui/Texture.h - src/tools/gui/TextureManager.cpp - src/tools/gui/TextureManager.h - src/tools/gui/ViewState.cpp - src/tools/gui/ViewState.h - src/tools/gui/ImGuiTypeConvert.h - libs/imgui/imgui.cpp - libs/imgui/imgui_demo.cpp - libs/imgui/imgui_draw.cpp - libs/imgui/imgui_tables.cpp - libs/imgui/imgui_widgets.cpp - libs/imgui/misc/freetype/imgui_freetype.cpp - libs/imgui/backends/imgui_impl_opengl3.cpp # include backend as-is - libs/imgui/backends/imgui_impl_sdl.cpp # // - libs/ImGuiColorTextEdit/TextEditor.cpp - libs/gl3w/GL/gl3w.c # Open GL Wrangler - libs/gl3w/GL/gl3w.h - libs/gl3w/GL/gl3w.gcda - libs/gl3w/GL/gl3w.gcno - libs/lodepng/lodepng.cpp -) - -target_link_libraries( - tools-gui - PUBLIC - ${CMAKE_DL_LIBS} - OpenGL::GL - SDL2-static SDL2main - nfd # native file dialog - extended - freetype # because: https://github.com/ocornut/imgui/tree/master/misc/freetype - tools-core -) - -# link APPLE specific libraries -IF (APPLE) - ndbl_log("Looking for Apple specific libraries ...") - - find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation) - if (NOT CORE_FOUNDATION_FRAMEWORK) - ndbl_err("CoreFoundation not found") - endif () - - find_library(COCOA_FRAMEWORK Cocoa) - if (NOT COCOA_FRAMEWORK) - ndbl_err("Cocoa not found") - endif () - - ndbl_log("CORE_FOUNDATION_FRAMEWORK: ${CORE_FOUNDATION_FRAMEWORK}") - ndbl_log("COCOA_FRAMEWORK: ${COCOA_FRAMEWORK}") - - target_link_libraries( - tools-gui - PUBLIC - ${CORE_FOUNDATION_FRAMEWORK} - ${COCOA_FRAMEWORK} - ) -ENDIF () - -target_compile_definitions(tools-gui PUBLIC IMGUI_USER_CONFIG="${CMAKE_CURRENT_LIST_DIR}/src/tools/gui/ImGuiExConfig.h") # Override imconfig.h -set_target_properties(tools-gui PROPERTIES POSITION_INDEPENDENT_CODE FALSE) # required to run well on recent os (ex: ubuntu) -set_target_properties(tools-gui PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${BUILD_PATH}") # fix working directory for visual studio - -# define assets -set(TOOLS_ASSETS - "assets/fonts/CenturyGothic.ttf" - "assets/fonts/fa-solid-900.ttf" -) - -# copy each file (will dirty the build when file changes) -foreach (ASSET ${TOOLS_ASSETS}) - configure_file("${ASSET}" "${CMAKE_BINARY_DIR}/${ASSET}" COPYONLY) -endforeach () - -# 1.3) Framework GUI - Example application -#--------------------------------------- - -# add executable -add_executable( - tools-gui-example - WIN32 - src/tools/gui-example/main.cpp - src/tools/gui-example/AppExample.cpp - src/tools/gui-example/AppExample.h - src/tools/gui-example/AppExampleView.cpp - src/tools/gui-example/AppExampleView.h -) -target_link_libraries(tools-gui-example PUBLIC tools-gui) -set_target_properties(tools-gui-example PROPERTIES POSITION_INDEPENDENT_CODE FALSE) # required to run well on recent os (ex: ubuntu) -set_target_properties(tools-gui-example PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${BUILD_PATH}") # fix working directory for visual studio - -# Installation : -# install( TARGETS tools-gui-example RUNTIME PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE DESTINATION .) - -# 2.1) Nodable Core -#------------------ - -add_library( - ndbl-core - STATIC - src/ndbl/core/NodeComponent.cpp - src/ndbl/core/ComponentFactory.cpp - src/ndbl/core/IfNode.cpp - src/ndbl/core/DirectedEdge.cpp - src/ndbl/core/ForLoopNode.cpp - src/ndbl/core/Graph.cpp - src/ndbl/core/Utils.cpp - src/ndbl/core/FunctionNode.cpp - src/ndbl/core/LiteralNode.cpp - src/ndbl/core/Node.cpp - src/ndbl/core/NodeFactory.cpp - src/ndbl/core/Property.cpp - src/ndbl/core/PropertyBag.cpp - src/ndbl/core/Scope.cpp - src/ndbl/core/Slot.cpp - src/ndbl/core/SwitchBehavior.cpp - src/ndbl/core/Token.cpp - src/ndbl/core/TokenRibbon.cpp - src/ndbl/core/VariableNode.cpp - src/ndbl/core/Interpreter.cpp - src/ndbl/core/WhileLoopNode.cpp - src/ndbl/core/Code.cpp - src/ndbl/core/Compiler.cpp - src/ndbl/core/Instruction.cpp - src/ndbl/core/language/Nodlang.cpp - src/ndbl/core/language/Nodlang_biology.cpp - src/ndbl/core/language/Nodlang_math.cpp - src/ndbl/core/NodableHeadless.cpp - src/ndbl/core/NodableHeadless.h -) - -target_link_libraries( - ndbl-core - PUBLIC - tools-core -) - -ndbl_log("Defining install ...") -set_target_properties(ndbl-core PROPERTIES OUTPUT_NAME "core") - -ndbl_log("NDBL_SKIP_TESTS: ${NDBL_SKIP_TESTS}") - -if (NDBL_SKIP_TESTS) - return() -endif () - -add_executable( - test-ndbl-core - src/ndbl/core/Graph.specs.cpp - src/ndbl/core/Graph.specs.cpp - src/ndbl/core/Slot.specs.cpp - src/ndbl/core/Token.specs.cpp - src/ndbl/core/language/Nodlang.basics.specs.cpp - src/ndbl/core/language/Nodlang.tokenize.specs.cpp - src/ndbl/core/language/Nodlang.parse_function_call.specs.cpp - src/ndbl/core/language/Nodlang.parse_token.specs.cpp - src/ndbl/core/language/Nodlang.parse_and_serialize.specs.cpp - src/ndbl/core/Interpreter.specs.cpp -) -target_link_libraries(test-ndbl-core PUBLIC gtest_main gtest ndbl-core) -add_test(NAME test_ndbl_core COMMAND test-ndbl-core) - -# Benchmarks -add_executable(bench-ndbl-core-Nodlang src/ndbl/core/language/Nodlang.bench.cpp) -target_link_libraries(bench-ndbl-core-Nodlang PUBLIC benchmark::benchmark ndbl-core) - -# 2.1) Nodable CLI -#----------------- - -ndbl_log("Checking ...") -if (NOT NDBL_CONFIGURED_DIR) - ndbl_err("Variable NDBL_CONFIGURED_DIR must be set in main CMakeLists.txt") -endif () - -add_executable( - ndbl-cli - src/ndbl/cli/main.cpp - src/ndbl/cli/CLI.cpp -) - -target_link_libraries(ndbl-cli PUBLIC ndbl-core) -set_target_properties(ndbl-cli PROPERTIES POSITION_INDEPENDENT_CODE FALSE) # required to run well on recent os (ex: ubuntu) -set_target_properties(ndbl-cli PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${BUILD_PATH}") # fix working directory for visual studio -set_target_properties(ndbl-cli PROPERTIES OUTPUT_NAME "cli") - -# Installation : -install(TARGETS ndbl-cli DESTINATION . RUNTIME PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE) - -# 2.1) Nodable GUI -#------------------ - -# checks -ndbl_log("Checking ...") -if (NOT NDBL_CONFIGURED_DIR) - ndbl_err("Variable NDBL_CONFIGURED_DIR must be set in main CMakeLists.txt") -endif () - -# defines -set(NDBL_APP_ASSETS_DIR assets) -set(NDBL_APP_ASSETS_ABSOLUTE_DIR "${CMAKE_CURRENT_LIST_DIR}/${NDBL_APP_ASSETS_DIR}") - -# log variables -ndbl_log(" - NDBL_CONFIGURED_DIR: ${NDBL_CONFIGURED_DIR}") -ndbl_log(" - NDBL_APP_ASSETS_DIR: ${NDBL_APP_ASSETS_DIR}") -ndbl_log(" - NDBL_APP_ASSETS_ABSOLUTE_DIR: ${NDBL_APP_ASSETS_ABSOLUTE_DIR}") - -# Configure files -configure_file( - src/ndbl/gui/build_info.h.in - ${NDBL_CONFIGURED_DIR}/gui/build_info.h -) - -add_library( - ndbl-gui - STATIC - src/ndbl/gui/Config.cpp - src/ndbl/gui/Config.h - src/ndbl/gui/GraphView.cpp - src/ndbl/gui/CreateNodeCtxMenu.cpp - src/ndbl/gui/History.cpp - src/ndbl/gui/File.cpp - src/ndbl/gui/FileView.cpp - src/ndbl/gui/Nodable.cpp - src/ndbl/gui/NodableView.cpp - src/ndbl/gui/NodeView.cpp - src/ndbl/gui/Physics.cpp - src/ndbl/gui/PropertyView.cpp - src/ndbl/gui/SlotView.h - src/ndbl/gui/SlotView.cpp - src/ndbl/gui/Isolation.h - src/ndbl/gui/ScopeView.cpp -) - -target_link_libraries( - ndbl-gui - PUBLIC - ndbl-core - tools-gui -) - -target_include_directories( - ndbl-gui - PUBLIC - ${PROJECT_BINARY_DIR}/configured/ndbl/gui/ -) - -# define assets -set(ASSETS - assets/examples/arithmetic.cpp - assets/examples/for-loop.cpp - assets/examples/if-else.cpp - assets/examples/multi-instructions.cpp - assets/fonts/JetBrainsMono-Bold.ttf - assets/fonts/JetBrainsMono-Italic.ttf - assets/fonts/JetBrainsMono-Medium.ttf - assets/fonts/JetBrainsMono-Regular.ttf - assets/images/nodable-logo-xs.png -) - -# copy each file (will dirty the build when file changes) -foreach (ASSET ${ASSETS}) - configure_file("${ASSET}" "${CMAKE_BINARY_DIR}/${ASSET}" COPYONLY) -endforeach () - -ndbl_log("NDBL_SKIP_TESTS: ${NDBL_SKIP_TESTS}") - -if (NDBL_SKIP_TESTS) - return() -endif () - -add_executable(test-ndbl-gui src/ndbl/gui/Nodable.specs.cpp) -target_link_libraries(test-ndbl-gui PUBLIC gtest_main gtest ndbl-gui) - -# GUI tests does not work on every machine (only MacOS in software on GitHub Actions) -if ($ENV{JETBRAINS_IDE}) - ndbl_log("JETBRAINS_IDE is defined: Enable Nodable GUI tests (hardware rendering)") - add_test(NAME test_ndbl_gui COMMAND test-ndbl-gui) - add_definitions(-D NDBL_GUI_TEST_HUMAN_SPEED) -elseif (WIN32) - ndbl_log("Windows detected: Skip Nodable GUI tests") -elseif (APPLE) - ndbl_log("Apple detected: Enable Nodable GUI tests (software rendering)") - add_test(NAME test_ndbl_gui COMMAND test-ndbl-gui) -elseif (UNIX) # Should be tested after APPLE - ndbl_log("Linux detected: Skip Nodable GUI tests") -endif () - -# 2.1) Nodable App -#----------------- - -add_executable(ndbl-app WIN32 src/ndbl/app/main.cpp) -target_link_libraries(ndbl-app PUBLIC ndbl-gui) -set_target_properties(ndbl-app PROPERTIES POSITION_INDEPENDENT_CODE FALSE) # required to run well on recent os (ex: ubuntu) -set_target_properties(ndbl-app PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${BUILD_PATH}") # fix working directory for visual studio -set_target_properties(ndbl-app PROPERTIES OUTPUT_NAME "nodable") - -set(README README.md) -set(LICENSE LICENSE) -configure_file("${README}" . COPYONLY) -configure_file("${LICENSE}" . COPYONLY) - -# Installation : -install(TARGETS ndbl-app DESTINATION . RUNTIME PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE) -install(DIRECTORY assets DESTINATION .) -install(FILES ${LICENSE} ${README} DESTINATION .) - -# 3) Packaging: -#============== - -include(scripts/cmake/cpack.cmake) diff --git a/libs/cpptrace b/libs/cpptrace new file mode 160000 index 000000000..4354eb21e --- /dev/null +++ b/libs/cpptrace @@ -0,0 +1 @@ +Subproject commit 4354eb21ea3565a73afdf32ec0ba768fd648c425 diff --git a/rake/_cmake.rb b/rake/_cmake.rb new file mode 100644 index 000000000..e6c398369 --- /dev/null +++ b/rake/_cmake.rb @@ -0,0 +1,69 @@ + +CMakeTarget = Struct.new( + :name, + :path, + :config_flags, + :install_flags, + :build_flags, + keyword_init: true # If the optional keyword_init keyword argument is set to true, .new takes keyword arguments instead of normal arguments. +) + +def new_cmake_target(name, path) + CMakeTarget.new( + name: name, + path: path, + config_flags: "", + install_flags: "", + build_flags: "" + ) +end + +def tasks_for_cmake_target( target ) + build_dir = "#{BUILD_DIR}/cmake/#{target.name}" + install_dir = BUILD_DIR # two folders (lib and include) will be created + + if BUILD_TYPE == "release" + config = "Release" + else + config = "Debug" + end + + task :rebuild => [:clean, :build] + + task :clean do + puts "Cleaning ..." + FileUtils.rm_rf build_dir + puts "Cleaned" + end + + task :build => build_dir + + file build_dir do + # ensure folder exists + if Dir.exist? build_dir + FileUtils.rm_rf build_dir + end + FileUtils.mkdir_p build_dir + + config_cmd = "cmake -S #{target.path} -B #{build_dir}" + + if BUILD_OS_MACOS + config_flags = "-DCMAKE_OSX_DEPLOYMENT_TARGET=#{MACOSX_VERSION_MIN}" + elsif BUILD_OS_LINUX + # none + elsif BUILD_OS_MINGW + config_flags = "-G \"Visual Studio 17 2022\" -A x64" + end + sh "#{config_cmd} #{config_flags} #{target.config_flags}" # configure + sh "cmake --build #{build_dir} --config #{config} #{target.build_flags}" + end + + task :install => :build do + cmd = "cmake --install #{build_dir} --config #{config} --prefix #{install_dir}" + if not install_dir and (BUILD_OS_LINUX or BUILD_OS_MACOS) + sh "sudo #{cmd}" + else + sh "#{cmd}" + end + end +end diff --git a/rake/_utils.rb b/rake/_utils.rb new file mode 100644 index 000000000..ec9d7e200 --- /dev/null +++ b/rake/_utils.rb @@ -0,0 +1,252 @@ +require "rbconfig" +require 'json' + +VERBOSE = false +C_COMPILER = "clang" +CXX_COMPILER = "clang++" +COMPILER_FOUND = system "#{C_COMPILER} --version" || false +BUILD_OS = RbConfig::CONFIG['build_os'] +HOST_OS = RbConfig::CONFIG['host_os'] +TARGET_OS = RbConfig::CONFIG['target_os'] +BUILD_TYPE = (ENV["BUILD_TYPE"] || "release").downcase +BUILD_TYPE_RELEASE = BUILD_TYPE == "release" +BUILD_TYPE_DEBUG = !BUILD_TYPE_RELEASE +BUILD_DIR = ENV["BUILD_DIR"] || "build-#{BUILD_TYPE}" +OBJ_DIR = "#{BUILD_DIR}/obj" +DEP_DIR = "#{BUILD_DIR}/dep" +BIN_DIR = "#{BUILD_DIR}/bin" +BUILD_OS_LINUX = BUILD_OS.include?("linux") +BUILD_OS_MACOS = BUILD_OS.include?("darwin") +BUILD_OS_MINGW = BUILD_OS.include?("mingw") +GITHUB_ACTIONS = ENV["GITHUB_ACTIONS"] +MACOSX_VERSION_MIN = "12.0" # GitHub Actions does not support 11.0 +CMAKE_INSTALL_PREFIX_MINGW = "\"c:\\Program Files (x86)\\nodable-build-dependencies\"" + +if VERBOSE + system "echo Ruby version: && ruby -v" + puts "BUILD_OS_LINUX: #{BUILD_OS_LINUX}" + puts "BUILD_OS_MACOS: #{BUILD_OS_MACOS}" + puts "BUILD_OS_MINGW: #{BUILD_OS_MINGW}" + + puts "COMPILER_FOUND: #{COMPILER_FOUND}" + puts "BUILD_TYPE_RELEASE: #{BUILD_TYPE_RELEASE}" + puts "BUILD_TYPE_DEBUG: #{BUILD_TYPE_DEBUG}" +end + +if not COMPILER_FOUND + raise "Unable to find #{C_COMPILER}, this compiler is required, please install an retry." +elsif (not BUILD_OS_LINUX) and (not BUILD_OS_MACOS) and (not BUILD_OS_MINGW) + raise "Unable to determine the operating system" +end + +#--------------------------------------------------------------------------- + +module TargetType + EXECUTABLE = 0 + STATIC_LIBRARY = 1 + OBJECTS = 2 +end + +Target = Struct.new( + :name, + :type, + :sources, # list of .c|.cpp files + :link_library, # list of other targets to link with (their compiled *.o will be linked) + :includes, # list of path dir to include + :defines, + :compiler_flags, + :c_flags, + :cxx_flags, + :linker_flags, + :asset_folder_path, + keyword_init: true # If the optional keyword_init keyword argument is set to true, .new takes keyword arguments instead of normal arguments. +) + +def new_empty_target(name, type) + target = Target.new + target.name = name + target.type = type + target.sources = FileList[] + target.link_library = [] + target.includes = FileList[] + target.c_flags = [] + target.cxx_flags = [] + target.linker_flags = [] + target.asset_folder_path = nil + target.defines = [] + target.compiler_flags = [] + target.link_library = [] + target +end + +def get_objects_from_targets( targets ) + objects = FileList[] + targets.each do |other| + objects |= get_objects(other); + end + objects +end + +def src_to_obj( obj ) + "#{OBJ_DIR}/#{ obj.ext(".o")}" +end + +def src_to_dep( src ) + "#{DEP_DIR}/#{src.ext(".d")}" +end + +def obj_to_src( obj, _target) + stem = obj.sub("#{OBJ_DIR}/", "").ext("") + _target.sources.detect{|src| src.ext("") == stem } or raise "unable to find #{obj}'s source (stem: #{stem})" +end + +def to_objects( sources ) + sources.map{|src| src_to_obj(src) }; +end + +def get_objects( target ) + to_objects( target.sources ) +end + +def get_objects_to_link( target ) + objects = get_objects( target ) + target.link_library.each do |other_target| + objects |= get_objects_to_link( other_target ) + end + objects +end + +def copy_assets_to( dest_dir, target ) + from = target.asset_folder_path + to = "#{dest_dir}/#{target.asset_folder_path}" + if Dir.exist?(to) + puts "Skip assets copy (#{to} already exists)" + else + puts "#{target.name} Copying assets to #{to} ..." + FileUtils.mkdir_p to + FileUtils.copy_entry( from, to ) + puts "#{target.name} Assets copy OK" + end +end + +def get_library_name( target ) + "#{BUILD_DIR}/lib/lib#{target.name.ext(".a")}" +end + +def build_static_library( target ) + + objects = get_objects_to_link( target ).join(" ") + binary = get_library_name( target ) + linker_flags = target.linker_flags.join(" ") + + FileUtils.mkdir_p File.dirname(binary) + sh "llvm-ar r #{binary} #{objects}", verbose: VERBOSE +end + +def get_binary( target ) + path = "#{BIN_DIR}/#{target.name}" + if BUILD_OS_MINGW + path.ext(".exe") + else + path + end +end + +def build_executable_binary( target ) + + objects = get_objects_to_link(target).join(" ") + binary = get_binary( target ) + defines = target.defines.map{|d| "-D\"#{d}\"" }.join(" ") + linker_flags = target.linker_flags.join(" ") + + FileUtils.mkdir_p File.dirname(binary) + + sh "#{CXX_COMPILER} #{defines} -o #{binary} #{objects} #{linker_flags}", verbose: VERBOSE +end + +def compile_file(src, target) + + # Generate stringified version of the flags + # TODO: store this in a cache? + includes = target.includes.map{|path| "-I#{path}"}.join(" ") + cxx_flags = target.cxx_flags.join(" ") + c_flags = target.c_flags.join(" ") + defines = target.defines.map{|d| "-D\"#{d}\"" }.join(" ") + linker_flags = target.linker_flags.join(" -l") + compiler_flags = target.compiler_flags.join(" ") + + if File.extname( src ) == ".cpp" + # TODO: add a regular flags for both, and remove this c_flags below + compiler = "#{CXX_COMPILER} #{cxx_flags} #{compiler_flags}" + else + compiler = "#{C_COMPILER} #{c_flags} #{compiler_flags}" + end + + obj = src_to_obj( src ) + dep = src_to_dep( src ) + dep_flags = "-MD -MF#{dep}" + + + if VERBOSE + puts "-- obj: #{obj}" + puts "-- dep: #{dep}" + end + + FileUtils.mkdir_p File.dirname(obj) + FileUtils.mkdir_p File.dirname(dep) + + sh "#{compiler} -c #{includes} #{defines} #{dep_flags} -o #{obj} #{src}", verbose: VERBOSE +end + +def tasks_for_target(target) + + desc "Clean #{target.name}'s intermediate files" + task :clean do + FileUtils.rm_f get_objects(target) + end + + if target.type == TargetType::EXECUTABLE + desc "Run the #{target.name}" + task :run => [ :build ] do + sh "./#{get_binary(target)}" + end + end + + desc "Clean and build target #{target.name}" + task :rebuild => [:clean, :build] + + desc "Compile #{target.name}" + task :build => get_binary(target) do + if target.asset_folder_path + copy_assets_to( BIN_DIR, target ) # easier to copy there to run the app immediately + end + end + + file get_binary(target) => :link do + case target.type + when TargetType::EXECUTABLE + puts "#{target.name} Linking ..." + build_executable_binary( target ) + puts "#{target.name} Linking OK" + + when TargetType::STATIC_LIBRARY + puts "#{target.name} Creating static library ..." + build_static_library( target ) + puts "#{target.name} Static library OK" + when TargetType::OBJECTS + # nothing to go + else + raise "Unhandled case: #{target.type}" + end + end + + multitask :link => get_objects_to_link( target ) + + get_objects(target).each_with_index do |obj, index| + src = obj_to_src( obj, target ) + file obj => src do |task| + puts "#{target.name} | Compiling #{src} ..." + compile_file( src, target) + end + end +end diff --git a/rake/base.rb b/rake/base.rb new file mode 100644 index 000000000..5d7f3be08 --- /dev/null +++ b/rake/base.rb @@ -0,0 +1,129 @@ +require_relative '_utils' + +# Provide a base target +def new_target_from_base(name, type) + + target = new_empty_target(name, type) + target.includes |= FileList[ + "src", + "src/ndbl", + "src/tools", + "libs", + "libs/whereami/src", + "libs/imgui", + "libs/imgui", + "libs/glm", + "libs/gl3w/GL", + "libs/gl3w", + "libs/SDL/include", + "libs/IconFontCppHeaders", + "/usr/include/X11/mesa/GL", + "#{BUILD_DIR}/include", + "#{BUILD_DIR}/include/freetype2" + ] + + target.asset_folder_path = "assets" # a single folder + + target.defines |= [ + "IMGUI_USER_CONFIG=\\\"tools/gui/ImGuiExConfig.h\\\"", + "NDBL_APP_ASSETS_DIR=\\\"#{target.asset_folder_path}\\\"", + "NDBL_APP_NAME=\\\"#{target.name}\\\"", + "NDBL_BUILD_REF=\\\"local\\\"", + "CPPTRACE_STATIC_DEFINE", # error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl cpptrace::stacktrace::print_with_snippets... + ] + + if BUILD_TYPE_RELEASE + target.compiler_flags |= [ + "-O2" + ] + elsif BUILD_TYPE_DEBUG + target.compiler_flags |= [ + "-g", # generates symbols + "-O0", # no optim + "-Wfatal-errors", + #"-pedantic" + ] + end + + target.cxx_flags |= [ + "--std=c++20", + "-fno-char8_t" + ] + + target.linker_flags |= [ + "-L#{BUILD_DIR}/lib", + "-v" + ] + + if BUILD_OS_LINUX or BUILD_OS_MACOS + + target.linker_flags |= [ + "-lGL", # opengl + "-lfreetype -lpng -lz -lbrotlidec -lbz2", + "-lSDL2 -lSDL2main", + #"-lcpptrace -ldwarf -lz -lzstd -ldl", # https://github.com/jeremy-rifkin/cpptrace?tab=readme-ov-file#use-without-cmake + "-lnfd `pkg-config --cflags --libs gtk+-3.0`", + ] + + if BUILD_OS_MACOS + + target.linker_flags |= [ + "-lnfd -framework CoreFoundation -framework Cocoa" + ] + + target.compiler_flags |= [ + "-mmacosx-version-min=#{MACOSX_VERSION_MIN}", + ] + end + + elsif BUILD_OS_MINGW + + target.linker_flags |= [ + "-lopengl32", + "-lfreetype", + "-lSDL2main -lSDL2", + #"-lcpptrace -ldbghelp", # https://github.com/jeremy-rifkin/cpptrace?tab=readme-ov-file#use-without-cmake + "-lnfd -lole32 -luuid -lshell32", + "-luser32", + "-lkernel32", + "-lgdi32", + "-limm32", + "-lshell32", + "-Xlinker /SUBSYSTEM:CONSOLE", # LINK : fatal error LNK1561: entry point must be defined (WinMain vs main, here we want to use main) + "-Xlinker /NODEFAULTLIB" + ] + + # see https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170#c-runtime-lib-files + if BUILD_TYPE_DEBUG + target.linker_flags |= [ + "-lmsvcrtd", + "-lucrtd", + "-lvcruntimed", + "-llibcpmtd", + ] + else + target.linker_flags |= [ + "-lmsvcrt", + "-lucrt", + "-lvcruntime", + "-llibcpmt", + ] + end + + target.includes |= [ + "#{CMAKE_INSTALL_PREFIX_MINGW}\\include", # windows does not add to the path automatically + ] + + target.linker_flags |= [ + "-L#{CMAKE_INSTALL_PREFIX_MINGW}\\lib", # windows does not add to the path automatically + ] + + target.defines |= [ + "WIN32", # to have an MSVC-like macro + "NOMINMAX", # in WIN32, min and max are macros by default, it creates conflicts with std::min/std::max + ] + + end + + target +end \ No newline at end of file diff --git a/rake/libs.rb b/rake/libs.rb new file mode 100644 index 000000000..a3bbb3896 --- /dev/null +++ b/rake/libs.rb @@ -0,0 +1,89 @@ +require_relative "base" +require_relative "_utils" +require_relative "_cmake" + +task :libs => 'libs:build' +namespace :libs do + + task :build => [ + # compile .a/.lib first + 'freetype:install', + 'googletest:install', + 'nfd:install', + 'sdl:install', + # then .o + 'whereami:build', + 'gl3w:build', + 'imgui:build', + 'lodepng:build', + 'text_editor:build', + ] + + namespace :gl3w do + $gl3w = new_target_from_base("gl3w", TargetType::OBJECTS) + $gl3w.sources |= FileList[ + "libs/gl3w/GL/gl3w.c" + ] + tasks_for_target( $gl3w ) + end + + namespace :text_editor do + $text_editor = new_target_from_base("text_editor", TargetType::OBJECTS) + $text_editor.sources |= FileList[ + "libs/ImGuiColorTextEdit/TextEditor.cpp" + ] + tasks_for_target( $text_editor ) + end + + namespace :lodepng do + $lodepng = new_target_from_base("lodepng", TargetType::OBJECTS) + $lodepng.sources |= FileList[ + "libs/lodepng/lodepng.cpp" + ] + tasks_for_target( $lodepng ) + end + + namespace :imgui do + $imgui = new_target_from_base("imgui", TargetType::OBJECTS) + $imgui.sources |= FileList[ + "libs/imgui/imgui.cpp", + "libs/imgui/imgui_demo.cpp", + "libs/imgui/imgui_draw.cpp", + "libs/imgui/imgui_tables.cpp", + "libs/imgui/imgui_widgets.cpp", + "libs/imgui/misc/freetype/imgui_freetype.cpp", + "libs/imgui/backends/imgui_impl_sdl.cpp", + "libs/imgui/backends/imgui_impl_opengl3.cpp", + ] + tasks_for_target( $imgui ) + end + + namespace :whereami do + $whereami = new_target_from_base("whereami", TargetType::OBJECTS) + $whereami.sources |= FileList[ + "libs/whereami/src/whereami.c" + ] + tasks_for_target( $whereami ) + end + + namespace :nfd do + nfd = CMakeTarget.new(name: "nfd", path: "libs/nativefiledialog-extended" ) + tasks_for_cmake_target( nfd ) + end + + namespace :googletest do + googletest = CMakeTarget.new(name: "googletest", path: "libs/googletest" ) + tasks_for_cmake_target( googletest ) + end + + namespace :freetype do + freetype = CMakeTarget.new(name: "freetype", path: "libs/freetype" ) + tasks_for_cmake_target( freetype ) + end + + namespace :sdl do + sdl = CMakeTarget.new(name: "sdl", path: "libs/SDL" ) + tasks_for_cmake_target( sdl ) + end + +end # namespace libs \ No newline at end of file diff --git a/rake/ndbl.rb b/rake/ndbl.rb new file mode 100644 index 000000000..c1c43e644 --- /dev/null +++ b/rake/ndbl.rb @@ -0,0 +1,129 @@ +require_relative 'base' +require_relative 'tools' + +#--------------------------------------------------------------------------- +ndbl_core = new_target_from_base("ndbl_core", TargetType::OBJECTS) +ndbl_core.sources |= FileList[ + "src/ndbl/core/language/Nodlang.cpp", + "src/ndbl/core/language/Nodlang_biology.cpp", + "src/ndbl/core/language/Nodlang_math.cpp", + "src/ndbl/core/Code.cpp", + "src/ndbl/core/Compiler.cpp", + "src/ndbl/core/ComponentFactory.cpp", + "src/ndbl/core/DirectedEdge.cpp", + "src/ndbl/core/ForLoopNode.cpp", + "src/ndbl/core/FunctionNode.cpp", + "src/ndbl/core/Graph.cpp", + "src/ndbl/core/IfNode.cpp", + "src/ndbl/core/Instruction.cpp", + "src/ndbl/core/Interpreter.cpp", + "src/ndbl/core/LiteralNode.cpp", + "src/ndbl/core/NodableHeadless.cpp", + "src/ndbl/core/Node.cpp", + "src/ndbl/core/NodeComponent.cpp", + "src/ndbl/core/NodeFactory.cpp", + "src/ndbl/core/Property.cpp", + "src/ndbl/core/PropertyBag.cpp", + "src/ndbl/core/Scope.cpp", + "src/ndbl/core/Slot.cpp", + "src/ndbl/core/SwitchBehavior.cpp", + "src/ndbl/core/Token.cpp", + #"src/ndbl/core/Token.specs.cpp", + "src/ndbl/core/TokenRibbon.cpp", + "src/ndbl/core/Utils.cpp", + "src/ndbl/core/VariableNode.cpp", + "src/ndbl/core/WhileLoopNode.cpp", +] +#--------------------------------------------------------------------------- +ndbl_gui = new_target_from_base("ndbl_gui", TargetType::OBJECTS) +ndbl_gui.sources |= FileList[ + "src/ndbl/gui/CreateNodeCtxMenu.cpp", + "src/ndbl/gui/GraphView.cpp", + "src/ndbl/gui/Nodable.cpp", + #"src/ndbl/gui/benchmark.cpp", + "src/ndbl/gui/Config.cpp", + "src/ndbl/gui/File.cpp", + "src/ndbl/gui/FileView.cpp", + "src/ndbl/gui/History.cpp", + "src/ndbl/gui/NodableView.cpp", + "src/ndbl/gui/NodeView.cpp", + "src/ndbl/gui/Physics.cpp", + "src/ndbl/gui/PropertyView.cpp", + "src/ndbl/gui/ScopeView.cpp", + "src/ndbl/gui/SlotView.cpp", +] +#--------------------------------------------------------------------------- +ndbl_app = new_target_from_base("nodable", TargetType::EXECUTABLE) +ndbl_app.sources |= FileList[ + "src/ndbl/app/main.cpp", +] +ndbl_app.link_library |= [ + $tools_gui, + $tools_core, + $text_editor, + ndbl_core, + ndbl_gui +] + +#--------------------------------------------------------------------------- +ndbl_test = new_target_from_base("ndbl-specs", TargetType::EXECUTABLE) +ndbl_test.sources |= FileList[ + "src/ndbl/core/language/Nodlang.parse_and_serialize.specs.cpp", + "src/ndbl/core/language/Nodlang.parse_function_call.specs.cpp", + "src/ndbl/core/language/Nodlang.parse_token.specs.cpp", + "src/ndbl/core/language/Nodlang.tokenize.specs.cpp", + "src/ndbl/core/Graph.specs.cpp", + "src/ndbl/core/Interpreter.specs.cpp", +] + +ndbl_test.linker_flags |= [ + "-lgtest", + "-lgtest_main" +] + +ndbl_test.link_library |= [ + $tools_core, + $tools_gui, + ndbl_core +] + +# On GitHub actions, the only runner able to run this is the macos one +if ENV["NDBL_ENABLE_GUI_TEST"] or (GITHUB_ACTIONS and BUILD_OS_MACOS) + ndbl_test.sources |= [ + "src/ndbl/gui/Nodable.specs.cpp" + ] + ndbl_test.link_library |= [ + ndbl_gui, + $text_editor + ] +else + puts "Nodable GUI tests will be disable, export NDBL_ENABLE_GUI_TEST env var to enable them." +end + + +#--------------------------------------------------------------------------- +task :ndbl => 'ndbl:build' +namespace :ndbl do + task :clean => ['core:clean', 'gui:clean', 'app:clean', 'test:clean'] + task :rebuild => ['clean', 'build'] + task :build => ['core:build', 'gui:build', 'app:build', 'test:build'] + task :test => ['test:run'] + task :pack => ['app:pack'] + + namespace :core do + tasks_for_target( ndbl_core ) + end + + namespace :gui do + tasks_for_target( ndbl_gui ) + end + + namespace :app do + tasks_for_target( ndbl_app ) + end + + namespace :test do + tasks_for_target( ndbl_test ) + end +end +#--------------------------------------------------------------------------- \ No newline at end of file diff --git a/rake/tools.rb b/rake/tools.rb new file mode 100644 index 000000000..574f742c7 --- /dev/null +++ b/rake/tools.rb @@ -0,0 +1,101 @@ +require_relative 'base' +require_relative 'libs' + +#--------------------------------------------------------------------------- +$tools_core = new_target_from_base("tools_core", TargetType::OBJECTS) +$tools_core.sources |= FileList[ + "src/tools/core/reflection/qword.cpp", + "src/tools/core/reflection/Type.cpp", + "src/tools/core/reflection/TypeRegister.cpp", + "src/tools/core/reflection/variant.cpp", + #"src/tools/core/memory/pointers.cpp", + "src/tools/core/EventManager.cpp", + "src/tools/core/FileSystem.cpp", + "src/tools/core/format.cpp", + "src/tools/core/log.cpp", + "src/tools/core/StateMachine.cpp", + "src/tools/core/System.cpp", + "src/tools/core/TaskManager.cpp" +] +$tools_core.link_library |= [$whereami] + +#--------------------------------------------------------------------------- +$tools_gui = new_target_from_base("tools_gui", TargetType::OBJECTS) +$tools_gui.sources |= FileList[ + "src/tools/gui/geometry/BezierCurveSegment2D.cpp", + "src/tools/gui/geometry/BoxShape2D.cpp", + "src/tools/gui/geometry/Rect.cpp", + "src/tools/gui/geometry/SpatialNode2D.cpp", + "src/tools/gui/geometry/TRSTransform2D.cpp", + "src/tools/gui/Action.cpp", + "src/tools/gui/ActionManager.cpp", + "src/tools/gui/ActionManagerView.cpp", + "src/tools/gui/App.cpp", + "src/tools/gui/AppView.cpp", + "src/tools/gui/Config.cpp", + "src/tools/gui/FontManager.cpp", + "src/tools/gui/ImGuiEx.cpp", + "src/tools/gui/ViewState.cpp", + "src/tools/gui/TextureManager.cpp", +] +$tools_gui.link_library |= [$gl3w, $lodepng, $imgui] + +#--------------------------------------------------------------------------- + +app = new_target_from_base("tools-gui-example", TargetType::EXECUTABLE) +app.sources |= FileList[ + "src/tools/gui-example/AppExample.cpp", + "src/tools/gui-example/AppExampleView.cpp", + "src/tools/gui-example/main.cpp" +] +app.link_library |= [$tools_core, $tools_gui] + +#--------------------------------------------------------------------------- + +tools_test = new_target_from_base("tools-test", TargetType::EXECUTABLE) +tools_test.sources |= FileList[ + "src/tools/core/Delegate.specs.cpp", + "src/tools/core/string.specs.cpp", + "src/tools/core/reflection/reflection.specs.cpp", + "src/tools/gui/geometry/SpatialNode2D.specs.cpp", + "src/tools/gui/geometry/Rect.specs.cpp" +] +tools_test.linker_flags |= [ + "-lgtest", + "-lgtest_main" +] +tools_test.link_library |= [$tools_core, $tools_gui] + +#--------------------------------------------------------------------------- + +desc "Build tools" +namespace :tools do + + desc "Clean tools" + task :clean => ['core:clean', 'gui:clean', 'app:clean', 'test:clean'] + desc "Rebuild tools" + task :rebuild => ['clean', 'build'] + desc "Build tools" + task :build => ['core:build', 'gui:build', 'app:build', 'test:build'] + task :test => ['test:run'] + + namespace :core do + tasks_for_target( $tools_core ) + end + + task :gui + namespace :gui do + tasks_for_target( $tools_gui ) + end + + task :app + namespace :app do + tasks_for_target( app ) + end + + namespace :test do + tasks_for_target( tools_test ) + end + +end +#--------------------------------------------------------------------------- \ No newline at end of file diff --git a/rakefile b/rakefile new file mode 100644 index 000000000..05b8b8ebc --- /dev/null +++ b/rakefile @@ -0,0 +1,37 @@ +require 'fileutils' +require 'rake/clean' + +require_relative 'rake/_utils' +require_relative 'rake/libs' +require_relative 'rake/base' +require_relative 'rake/tools' +require_relative 'rake/ndbl' + +CLEAN.include [OBJ_DIR, DEP_DIR] # intermediate files +CLOBBER.include [BUILD_DIR] # final files + +task :default => :help + +desc "says hello" +task :help do + print("Welcome to Nodable's rakefile.\nFor more info, run: rake --tasks\n") +end + +desc "Install system dependencies" +task :install => [] do + if BUILD_OS_LINUX + cmd = "sudo apt-get update && sudo apt-get install libegl1-mesa-dev libdbus-1-dev libgtk-3-dev" + puts "We need to escalate privileges to run:" + sh cmd or raise "Unable to install packages" + elsif BUILD_OS_MACOS + sh "brew install mesalib-glw" or raise "Unable to install packages" + elsif BUILD_OS_MINGW + puts "No system dependencies to install for #{BUILD_OS}" + else + raise "Your system (#{BUILD_OS}) is not supported by this script" + end +end + +task :build => ['libs:build', 'tools:build', 'ndbl:build'] do puts "Build DONE" end +task :test => ['tools:test', 'ndbl:test'] +task :pack => ['ndbl:pack'] do puts "Pack DONE" end diff --git a/src/ndbl/gui/build_info.h b/src/ndbl/gui/build_info.h new file mode 100644 index 000000000..6f4862ab2 --- /dev/null +++ b/src/ndbl/gui/build_info.h @@ -0,0 +1,8 @@ +#pragma once + +namespace ndbl::BuildInfo +{ + static const char* assets_dir = NDBL_APP_ASSETS_DIR; + static const char* version = NDBL_APP_NAME NDBL_BUILD_REF; + static const char* version_extended = NDBL_APP_NAME NDBL_BUILD_REF " - Built " __DATE__ " at " __TIME__; +} diff --git a/src/ndbl/gui/build_info.h.in b/src/ndbl/gui/build_info.h.in deleted file mode 100644 index 7eceaf217..000000000 --- a/src/ndbl/gui/build_info.h.in +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -/** - >> DO NOT EDIT BuildInfo.h, edit BuildInfo.h.in (source file) << - - BuildInfo.h.in will be configured by cmake, check CMakelists.txt -*/ - -namespace ndbl::BuildInfo -{ - static const char* assets_dir = "@NDBL_APP_ASSETS_DIR@"; - static const char* version = "@NDBL_APP_NAME@ @NDBL_BUILD_REF@"; - static const char* version_extended = "@NDBL_APP_NAME@ @NDBL_BUILD_REF@ - Built " __DATE__ " at " __TIME__; -} diff --git a/src/tools/core/Exceptions.h b/src/tools/core/Exceptions.h index a7410a18c..cf2290578 100644 --- a/src/tools/core/Exceptions.h +++ b/src/tools/core/Exceptions.h @@ -1,15 +1,12 @@ #pragma once - -#include +#include namespace tools { - typedef cpptrace::runtime_error runtime_error; - typedef cpptrace::domain_error domain_error; - - class unreachable : public domain_error + class unreachable : public std::logic_error { public: - unreachable(): domain_error("This code should not be reachable") {} + unreachable(): std::logic_error("This code should not be reachable") {} }; -} \ No newline at end of file +} + diff --git a/src/tools/core/TryCatch.h b/src/tools/core/TryCatch.h index 9be9d6274..982930955 100644 --- a/src/tools/core/TryCatch.h +++ b/src/tools/core/TryCatch.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #ifndef TOOLS_TRY_CATCH_ENABLE # define TOOLS_TRY_CATCH_ENABLE true @@ -15,15 +15,14 @@ try #define TOOLS_catch \ - catch(const cpptrace::logic_error& logic_error) \ + catch(const std::logic_error& e) \ { \ - logic_error.trace().print_with_snippets(); \ - std::cout << std::flush; \ + std::cout << e.what() << std::flush; \ exit(1); \ } \ - catch(const std::exception & std_error) \ + catch(const std::exception & e) \ { \ - std::cout << std_error.what() << std::flush; \ + std::cout << e.what() << std::flush; \ exit(1); \ } diff --git a/src/tools/core/string.spec.cpp b/src/tools/core/string.specs.cpp similarity index 100% rename from src/tools/core/string.spec.cpp rename to src/tools/core/string.specs.cpp diff --git a/src/tools/gui/AppView.cpp b/src/tools/gui/AppView.cpp index d03bf4daa..320d01897 100644 --- a/src/tools/gui/AppView.cpp +++ b/src/tools/gui/AppView.cpp @@ -1,10 +1,10 @@ -#include "AppView.h" +#include // must be included first +#include "AppView.h" #include #include #include // to save screenshot as PNG #include -#include #include "tools/core/log.h" #include "tools/core/System.h" @@ -12,6 +12,8 @@ #include "tools/core/memory/memory.h" #include "tools/gui/TextureManager.h" #include "tools/gui/FontManager.h" +#include "tools/gui/ActionManager.h" +#include "tools/gui/ImGuiEx.h" #include "App.h" #include "Config.h" diff --git a/src/tools/gui/AppView.h b/src/tools/gui/AppView.h index c19ab7b18..8c0e271db 100644 --- a/src/tools/gui/AppView.h +++ b/src/tools/gui/AppView.h @@ -2,11 +2,12 @@ #include #include -#include "tools/core/FileSystem.h" +#include #include #include +#include "TextureManager.h" +#include "tools/core/FileSystem.h" #include "tools/core/types.h" -#include "ImGuiEx.h" #include "Config.h" #include "tools/core/Signals.h" @@ -15,10 +16,10 @@ namespace tools // forward declarations class App; class History; - class TextureManager; class EventManager; class FontManager; class VirtualMachine; + class ActionManager; /* This class contain the basic setup for and OpenGL/SDL basic window. diff --git a/src/tools/gui/FontManager.cpp b/src/tools/gui/FontManager.cpp index aaada5bc1..73d72c9f7 100644 --- a/src/tools/gui/FontManager.cpp +++ b/src/tools/gui/FontManager.cpp @@ -1,6 +1,8 @@ #include "FontManager.h" #include "App.h" #include "Config.h" +#include +#include using namespace tools; diff --git a/src/tools/gui/Texture.h b/src/tools/gui/Texture.h index 3958ad3f2..7129372bd 100644 --- a/src/tools/gui/Texture.h +++ b/src/tools/gui/Texture.h @@ -1,6 +1,5 @@ #pragma once - -#include "gl3w/GL/gl3w.h" +#include // must be included first #include "tools/gui/geometry/Vec2.h" #include "tools/core/types.h" diff --git a/src/tools/gui/TextureManager.cpp b/src/tools/gui/TextureManager.cpp index 4a9eabb50..06e6921ac 100644 --- a/src/tools/gui/TextureManager.cpp +++ b/src/tools/gui/TextureManager.cpp @@ -1,7 +1,8 @@ +#include // must be included first +#include + #include "TextureManager.h" -#include -#include #include #include #include diff --git a/src/tools/gui/geometry/Vec2.h b/src/tools/gui/geometry/Vec2.h index c868c3c1e..d43167d03 100644 --- a/src/tools/gui/geometry/Vec2.h +++ b/src/tools/gui/geometry/Vec2.h @@ -1,11 +1,11 @@ #pragma once -#include "glm/glm/common.hpp" -#include "glm/glm/ext/matrix_float3x3.hpp" -#include "glm/glm/ext/matrix_transform.hpp" -#include "glm/glm/vec2.hpp" +#include "glm/common.hpp" +#include "glm/ext/matrix_float3x3.hpp" +#include "glm/ext/matrix_transform.hpp" +#include "glm/vec2.hpp" -#include "tools/core/types.h" +#include "core/types.h" namespace tools {