diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 8dae1e1..33b3899 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -39,15 +39,12 @@ jobs: - uses: actions/checkout@v4 - name: Set reusable strings - # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. id: strings shell: bash run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: > cmake -B ${{ steps.strings.outputs.build-output-dir }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} @@ -57,11 +54,23 @@ jobs: -S ${{ github.workspace }} - name: Build - # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} - # - name: Test - # working-directory: ${{ steps.strings.outputs.build-output-dir }} - # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - # run: ctest --build-config ${{ matrix.build_type }} + - name: Run example and compare output (Linux) + if: runner.os == 'Linux' + shell: bash + run: | + echo "Running example and capturing output..." + cd ${{ steps.strings.outputs.build-output-dir }} + ./example/rectpack2D-example > actual_output.txt + + echo "Comparing output..." + if diff -u ../tests/example_expected_output.txt actual_output.txt; then + echo "✅ Output matches expected." + else + echo "❌ Output differs from expected." + echo "---- Actual ----" + cat actual_output.txt + echo "----------------" + exit 1 + fi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 94f938e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,47 +0,0 @@ -os: linux -language: cpp -sudo: required -dist: trusty -addons: - apt: - packages: - - gdb - - apport - - gcc-7 - - g++-7 - - cmake - - ninja-build - sources: - - ubuntu-toolchain-r-test - -matrix: - include: - - env: c_compiler=gcc-7 cxx_compiler=g++-7 config=Debug - compiler: gcc - - env: c_compiler=gcc-7 cxx_compiler=g++-7 config=Release - compiler: gcc - -before_install: - - ulimit -c - - ulimit -a -S - - ulimit -a -H - - cat /proc/sys/kernel/core_pattern - - cat /etc/default/apport - - service --status-all || true - - initctl list || true - -script: - - ${c_compiler} -v && ${cxx_compiler} -v && cmake --version && ninja --version - - export CC=${c_compiler} - - export CXX=${cxx_compiler} - - cmake/build_example.sh ${config} ${c_compiler} ${cxx_compiler} - - ulimit -c unlimited -S - - pushd build/current - - ninja run -k 0 - - ls -l - - popd - - ls -l example - - cmake/print_bt_if_core_found.sh example/core - -notfications: - email: false diff --git a/README.md b/README.md index e6c4f8e..e3e3b99 100644 --- a/README.md +++ b/README.md @@ -106,18 +106,17 @@ Then just build the generated ``.sln`` file using the newest Visual Studio Previ From the repository's folder, run: ```bash -cmake/build_example.sh Release gcc g++ -cd build/current -ninja run +mkdir build +cd build +cmake -DRECTPACK2D_BUILD_EXAMPLE=1 .. +make ```` -Or, if you want to use clang, run: +Then run: ```bash -cmake/build_example.sh Release clang clang++ -cd build/current -ninja run -```` +make run +``` ## Algorithm diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 3d76cdf..7243ce8 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,5 +1,7 @@ add_executable(rectpack2D-example) +message("Build type: ${CMAKE_BUILD_TYPE}") + target_sources( rectpack2D-example PUBLIC @@ -21,11 +23,11 @@ set_property( set(RESULT_EXE_WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -# Enable LTO +# Enable LTO (only in release, not debug with sanitizers) include(CheckIPOSupported) check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT output) -if(IPO_SUPPORTED) +if(IPO_SUPPORTED AND CMAKE_BUILD_TYPE STREQUAL "Release") set_target_properties( rectpack2D-example PROPERTIES @@ -34,14 +36,12 @@ if(IPO_SUPPORTED) endif() if(MSVC) - # Set executable working directory to current folder if debugging in vs set_target_properties( rectpack2D-example PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${RESULT_EXE_WORKING_DIR} ) - # Set executable as a startup project set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT rectpack2D-example) target_compile_options( @@ -49,9 +49,17 @@ if(MSVC) PUBLIC /permissive- ) -endif() -if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + # Add runtime checks only in Debug builds (they conflict with /O2) + if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "") + target_compile_options( + rectpack2D-example + PUBLIC + /RTC1 + ) + endif() +else() + # GCC or Clang setup target_compile_options( rectpack2D-example PUBLIC @@ -60,4 +68,34 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUA -Wextra -ftemplate-backtrace-limit=0 ) + + # Enable sanitizers in Debug mode + if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "") + message(STATUS "Enabling Address + Undefined sanitizers for Debug build") + message(STATUS "THIS MIGHT SLOW DOWN THE EXAMPLE!") + message(STATUS "If you want to disable sophisticated debugging, specify -DCMAKE_BUILD_TYPE=Release") + + target_compile_options( + rectpack2D-example + PUBLIC + -fsanitize=address,undefined + -fno-omit-frame-pointer + -O1 + ) + + target_link_options( + rectpack2D-example + PUBLIC + -fsanitize=address,undefined + ) + endif() endif() + +add_custom_target( + run + COMMAND rectpack2D-example + DEPENDS rectpack2D-example + WORKING_DIRECTORY ${RESULT_EXE_WORKING_DIR} + COMMENT "Running rectpack2D-example..." + VERBATIM +) diff --git a/tests/example_expected_output.txt b/tests/example_expected_output.txt new file mode 100644 index 0000000..7b8f824 --- /dev/null +++ b/tests/example_expected_output.txt @@ -0,0 +1,24 @@ +Resultant bin: 284 875 +170 380 20 40 +85 439 120 40 +85 380 85 59 +85 0 199 380 +0 0 85 875 +Resultant bin: 509 875 +489 0 20 40 +369 0 120 40 +284 0 85 59 +0 0 199 380 +199 0 85 875 +Resultant bin: 284 974 +0 0 20 40 +20 0 120 40 +0 40 85 59 +0 99 199 380 +199 99 85 875 +Resultant bin: 304 974 +0 0 20 40 +20 0 120 40 +20 40 85 59 +20 99 199 380 +219 99 85 875