Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
47 changes: 0 additions & 47 deletions .travis.yml

This file was deleted.

15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
50 changes: 44 additions & 6 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
add_executable(rectpack2D-example)

message("Build type: ${CMAKE_BUILD_TYPE}")

target_sources(
rectpack2D-example
PUBLIC
Expand All @@ -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
Expand All @@ -34,24 +36,30 @@ 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(
rectpack2D-example
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
Expand All @@ -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
)
24 changes: 24 additions & 0 deletions tests/example_expected_output.txt
Original file line number Diff line number Diff line change
@@ -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