Skip to content

Commit 2c34050

Browse files
author
Mattia Montanari
committed
build: integrate examples into CMake and fix CI paths
- Add BUILD_EXAMPLES option to root CMakeLists.txt - Add examples/c subdirectory to scalar with BUILD_EXAMPLES guard - Fix examples/c/CMakeLists.txt to use opengjk_scalar_static target - Update ci-examples.yml paths for scalar/ directory structure - All example paths updated: C, Cython, Python, CSharp, Go, Octave, Zig
1 parent 466c4d0 commit 2c34050

4 files changed

Lines changed: 33 additions & 27 deletions

File tree

.github/workflows/ci-examples.yml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- run: cmake -E make_directory build
1515
- run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SIMD=OFF ..
1616
- run: cmake --build build
17-
- run: cmake -E chdir build/examples/c/ ./example_lib_opengjk_ce
17+
- run: cmake -E chdir build/scalar/examples/c/ ./example_lib_opengjk_ce
1818

1919
C_GCC_CXX:
2020
runs-on: ubuntu-latest
@@ -25,7 +25,7 @@ jobs:
2525
- run: cmake -E make_directory build
2626
- run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DFORCE_CXX_COMPILER=ON -DBUILD_SIMD=OFF ..
2727
- run: cmake --build build
28-
- run: cmake -E chdir build/examples/c/ ./example_lib_opengjk_ce
28+
- run: cmake -E chdir build/scalar/examples/c/ ./example_lib_opengjk_ce
2929

3030
C_msvs:
3131
runs-on: windows-latest
@@ -44,8 +44,8 @@ jobs:
4444
- run: cmake -E make_directory build
4545
- run: cmake -E chdir build cmake -DBUILD_SIMD=OFF ..
4646
- run: cmake --build build
47-
- run: cmake -E copy build/examples/c/Debug/example_lib_opengjk_ce.exe build/examples/c
48-
- run: cmake -E chdir build/examples/c/ ./example_lib_opengjk_ce.exe
47+
- run: cmake -E copy build/scalar/examples/c/Debug/example_lib_opengjk_ce.exe build/scalar/examples/c
48+
- run: cmake -E chdir build/scalar/examples/c/ ./example_lib_opengjk_ce.exe
4949

5050
Cython:
5151
runs-on: ubuntu-latest
@@ -55,8 +55,8 @@ jobs:
5555
uses: actions/checkout@v4
5656
- run: apt-get update -y && apt-get install python3-setuptools python3-pip -y
5757
- run: pip3 install numpy pytest scipy Cython
58-
- run: cd examples/cython/ && python3 setup.py build_ext --inplace && python3 pygjk_trial.py
59-
- run: cd examples/cython/ && pytest test.py
58+
- run: cd scalar/examples/cython/ && python3 setup.py build_ext --inplace && python3 pygjk_trial.py
59+
- run: cd scalar/examples/cython/ && pytest test.py
6060

6161
PythonCTypes:
6262
runs-on: ubuntu-latest
@@ -79,7 +79,6 @@ jobs:
7979
- name: CMake config
8080
run: cmake -B ${{github.workspace}}/build -DBUILD_SIMD=OFF
8181
env:
82-
BUILD_CTYPES: 1
8382
CMAKE_BUILD_TYPE: Release
8483

8584
- name: CMake build
@@ -89,23 +88,23 @@ jobs:
8988
- name: Debug library symbols
9089
run: |
9190
echo "Checking library symbols..."
92-
nm -D ${{github.workspace}}/build/libopengjk_ce.so
91+
nm -D ${{github.workspace}}/build/scalar/libopengjk_scalar.so
9392
echo "Checking library dependencies..."
94-
ldd ${{github.workspace}}/build/libopengjk_ce.so
93+
ldd ${{github.workspace}}/build/scalar/libopengjk_scalar.so
9594
9695
- name: Copy library to module directory
9796
run: |
9897
# Create the destination directory if it doesn't exist
99-
mkdir -p ${{github.workspace}}/examples/python_ctypes/src/pyopengjk/
100-
# Copy the library to the module directory
101-
cp ${{github.workspace}}/build/libopengjk_ce.so ${{github.workspace}}/examples/python_ctypes/src/pyopengjk/
98+
mkdir -p ${{github.workspace}}/scalar/examples/python_ctypes/src/pyopengjk/
99+
# Copy the library to the module directory (renamed for compatibility)
100+
cp ${{github.workspace}}/build/scalar/libopengjk_scalar.so ${{github.workspace}}/scalar/examples/python_ctypes/src/pyopengjk/libopengjk_ce.so
102101
103102
- name: Python build
104-
working-directory: ${{github.workspace}}/examples/python_ctypes/
103+
working-directory: ${{github.workspace}}/scalar/examples/python_ctypes/
105104
run: pip install -e .[test]
106105

107106
- name: Python test
108-
working-directory: ${{github.workspace}}/examples/python_ctypes/
107+
working-directory: ${{github.workspace}}/scalar/examples/python_ctypes/
109108
run: pytest -vv
110109

111110
CSharp:
@@ -121,11 +120,10 @@ jobs:
121120
apt-get install gcc g++ cmake mono-devel -y
122121
- run: cmake -E make_directory build
123122
# Using single precision
124-
- run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON -DSINGLE_PRECISION=ON -DBUILD_SIMD=OFF ..
125-
- run: cmake --build build --target opengjk_ce
126-
- run: cmake -E chdir build make install
127-
- run: cmake -E copy build/*opengjk_ce* examples/cs/
128-
- run: cd examples/cs/ && mcs -out:main.exe main.cs && mono main.exe
123+
- run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DUSE_32BITS=ON -DBUILD_SIMD=OFF ..
124+
- run: cmake --build build --target opengjk_scalar
125+
- run: cmake -E copy build/scalar/*opengjk_scalar* scalar/examples/cs/
126+
- run: cd scalar/examples/cs/ && mcs -out:main.exe main.cs && mono main.exe
129127

130128
GO:
131129
runs-on: ubuntu-latest
@@ -136,15 +134,15 @@ jobs:
136134
uses: actions/setup-go@v3
137135
with:
138136
go-version: 1.15
139-
- run: cd examples/go/openGJK && go build && go test -v
137+
- run: cd scalar/examples/go/openGJK && go build && go test -v
140138

141139
Octave:
142140
runs-on: ubuntu-latest
143141
container: gnuoctave/octave:7.3.0
144142
steps:
145143
- name: Check out repository code
146144
uses: actions/checkout@v4
147-
- run: cd examples/matlab/; octave runme.m
145+
- run: cd scalar/examples/matlab/; octave runme.m
148146

149147
Zig:
150148
runs-on: ubuntu-latest
@@ -155,5 +153,5 @@ jobs:
155153
with:
156154
version: 0.13.0
157155
- name: Build and run
158-
run: cd examples/zig && zig build && zig build run
156+
run: cd scalar/examples/zig && zig build && zig build run
159157

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ endif()
4242
option(BUILD_SCALAR "Build scalar (C) implementation" ON)
4343
option(BUILD_SIMD "Build SIMD (C++ Highway) implementation" ON)
4444
option(BUILD_TESTS "Build unit tests" ON)
45+
option(BUILD_EXAMPLES "Build example applications" ON)
4546
option(USE_32BITS "Use float instead of double" ON)
4647

4748
# Precision definition (shared between scalar and SIMD)
@@ -53,6 +54,7 @@ message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
5354
message(STATUS "Building scalar: ${BUILD_SCALAR}")
5455
message(STATUS "Building SIMD: ${BUILD_SIMD}")
5556
message(STATUS "Building tests: ${BUILD_TESTS}")
57+
message(STATUS "Building examples: ${BUILD_EXAMPLES}")
5658
message(STATUS "Using 32-bit floats: ${USE_32BITS}")
5759

5860
# ============================================================================
@@ -109,5 +111,6 @@ message(STATUS "OpenGJK v${PROJECT_VERSION} Configuration Summary:")
109111
message(STATUS " - Scalar library: ${BUILD_SCALAR}")
110112
message(STATUS " - SIMD library: ${BUILD_SIMD}")
111113
message(STATUS " - Tests: ${BUILD_TESTS}")
114+
message(STATUS " - Examples: ${BUILD_EXAMPLES}")
112115
message(STATUS " - Precision: ${USE_32BITS} (32-bit float)")
113116
message(STATUS "")

scalar/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,8 @@ if(BUILD_TESTS)
117117
add_subdirectory(tests)
118118
endif()
119119

120+
# Examples
121+
if(BUILD_EXAMPLES)
122+
add_subdirectory(examples/c)
123+
endif()
124+

scalar/examples/c/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ endif(FORCE_CXX_COMPILER)
3333

3434
add_executable(example_lib_opengjk_ce ${CMAKE_CURRENT_SOURCE_DIR}/main.c)
3535

36-
IF(WIN32)
37-
target_link_libraries(example_lib_opengjk_ce obj_openGJK)
38-
ELSE()
39-
target_link_libraries(example_lib_opengjk_ce obj_openGJK m)
40-
ENDIF()
36+
if(WIN32)
37+
target_link_libraries(example_lib_opengjk_ce opengjk_scalar_static)
38+
else()
39+
target_link_libraries(example_lib_opengjk_ce opengjk_scalar_static m)
40+
endif()
4141

4242
# Copy input files for this example after build
4343
add_custom_command(

0 commit comments

Comments
 (0)