Major changes: build static and dyn library. the first is for C example, the latter for CS example. The CS example is also ran in the action

fixes-turtlebasket
Mattia Montanari 2023-02-14 17:16:19 +01:00
parent 1282d6a222
commit aa4d543e99
4 changed files with 50 additions and 28 deletions

View File

@ -13,6 +13,26 @@ jobs:
- run: cmake --build build - run: cmake --build build
- run: cmake -E chdir build/examples/c/ ./example_lib_opengjk_ce - run: cmake -E chdir build/examples/c/ ./example_lib_opengjk_ce
Cython:
runs-on: ubuntu-latest
container: mmontanari/devenv:buildenv-ubuntu
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: cd examples/cython/ && python3 setup.py build_ext --inplace && python3 pygjk_trial.py
- run: cd examples/cython/ && pytest test.py
CSharp:
runs-on: ubuntu-latest
container: mmontanari/devenv:mono:latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: apt-get update && apt-get install gcc cmake -y
- run: cmake -E make_directory build
- run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON ..
- run: cd examples/cs/ && mcs -out:main.exe main.cs && mono main.exe
GO: GO:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: mmontanari/devenv:buildenv-fedora container: mmontanari/devenv:buildenv-fedora
@ -31,12 +51,3 @@ jobs:
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@v3 uses: actions/checkout@v3
- run: cd examples/matlab/; octave runme.m - run: cd examples/matlab/; octave runme.m
Cython:
runs-on: ubuntu-latest
container: mmontanari/devenv:buildenv-ubuntu
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: cd examples/cython/ && python3 setup.py build_ext --inplace && python3 pygjk_trial.py
- run: cd examples/cython/ && pytest test.py

View File

@ -21,15 +21,16 @@
# FOR A PARTICULAR PURPOSE. See GNU General Public License for details. # # FOR A PARTICULAR PURPOSE. See GNU General Public License for details. #
# User options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # User options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
option(BUILD_EXAMPLE "Build demo" ON) option(BUILD_EXAMPLE "Build demo" ON )
option(BUILD_MONO "Build C# example" OFF)
# CMake setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # CMake setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cmake_minimum_required(VERSION 3.0) # You can downgrade to 2.8, but I don't maintain it anymore cmake_minimum_required(VERSION 3.0) # You can downgrade to 2.8, but I don't maintain it anymore
cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0063 NEW) # Visibility of preset and hidden lines on shared libs cmake_policy(SET CMP0063 NEW) # Visibility of preset and hidden lines on shared libs
set( CMAKE_C_VISIBILITY_PRESET hidden) # set( CMAKE_C_VISIBILITY_PRESET hidden)
set( CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) set( CMAKE_VISIBILITY_INLINES_HIDDEN FALSE)
set( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Project setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # Project setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@ -58,26 +59,34 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
endif() endif()
# Target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # Target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
add_library( ${PROJECT_NAME}
STATIC if(BUILD_MONO)
add_compile_definitions(CS_MONO_BUILD)
endif(BUILD_MONO)
add_library( obj_openGJK
OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/openGJK.c ${CMAKE_CURRENT_SOURCE_DIR}/openGJK.c
${CMAKE_CURRENT_SOURCE_DIR}/include/openGJK/openGJK.h ${CMAKE_CURRENT_SOURCE_DIR}/include/openGJK/openGJK.h
) )
target_include_directories( ${PROJECT_NAME} target_include_directories( obj_openGJK
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
target_link_libraries(${PROJECT_NAME} PRIVATE m) target_link_libraries(obj_openGJK PRIVATE m)
set_target_properties(${PROJECT_NAME} set_target_properties(obj_openGJK
PROPERTIES PROPERTIES
C_STANDARD 11 C_STANDARD 11
PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/openGJK/openGJK.h PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/openGJK/openGJK.h
POSITION_INDEPENDENT_CODE 1
) )
add_library(opengjk_ce SHARED $<TARGET_OBJECTS:obj_openGJK>)
# Build demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # Build demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
if(BUILD_EXAMPLE) if(BUILD_EXAMPLE)
add_subdirectory(examples/c) add_subdirectory(examples/c)
@ -85,11 +94,11 @@ endif(BUILD_EXAMPLE)
# Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
if (UNIX) if (UNIX)
install(TARGETS ${PROJECT_NAME} PERMISSIONS WORLD_WRITE )
set(DESTDIR "/usr") set(DESTDIR "/usr")
INSTALL(TARGETS ${PROJECT_NAME} INSTALL(TARGETS opengjk_ce
LIBRARY DESTINATION "${DESTDIR}/lib" LIBRARY DESTINATION "${DESTDIR}/lib"
PUBLIC_HEADER DESTINATION "${DESTDIR}/include" PUBLIC_HEADER DESTINATION "${DESTDIR}/include"
PERMISSIONS WORLD_WRITE
) )
endif (UNIX) endif (UNIX)

View File

@ -25,12 +25,12 @@ project(example_lib_opengjk_ce
VERSION 1.0.0 VERSION 1.0.0
) )
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.c) add_executable(example_lib_opengjk_ce ${CMAKE_CURRENT_SOURCE_DIR}/main.c)
target_link_libraries(${PROJECT_NAME} lib_opengjk_ce) target_link_libraries(example_lib_opengjk_ce obj_openGJK m)
# Copy input files for this example after build # Copy input files for this example after build
add_custom_command( add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD TARGET example_lib_opengjk_ce POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/userP.dat ${CMAKE_CURRENT_SOURCE_DIR}/userP.dat
${CMAKE_CURRENT_BINARY_DIR}/userP.dat ${CMAKE_CURRENT_BINARY_DIR}/userP.dat

View File

@ -34,10 +34,13 @@ using System.Runtime.InteropServices;
public class Tester public class Tester
{ {
#if UNIX
[DllImport("libopengjk_ce.so", EntryPoint="csFunction", CallingConvention = CallingConvention.StdCall)]
#else
[DllImport("libopengjk_ce", EntryPoint = "csFunction", CallingConvention = CallingConvention.StdCall)]
#endif
[DllImport("libopenGJKlib", EntryPoint="csFunction", CallingConvention = CallingConvention.StdCall)] static extern double compute_minimum_distance(int na, double [,] ia, int nb, double [,] ib);
static extern double gjk(int na, double [,] ia, int nb, double [,] ib);
public static void Main(string[] args) public static void Main(string[] args)
{ {
@ -51,13 +54,12 @@ public class Tester
var inCoordsB = new double[3,9] { {-0.0 , -2.3 , -8.1 , -4.3 ,-2.5 , -7.1 , -1.0 , -3.3 , -6.0} , { -5.5 , -1.0 ,- 4.0 ,- 5.0 ,-1.0, -1.0, -1.5, -0.5 , -1.4} ,{ -0.0 , 2.0, -2.4, -2.2, -2.3 , -2.4 , -0.3 , -0.3 , -0.2} }; var inCoordsB = new double[3,9] { {-0.0 , -2.3 , -8.1 , -4.3 ,-2.5 , -7.1 , -1.0 , -3.3 , -6.0} , { -5.5 , -1.0 ,- 4.0 ,- 5.0 ,-1.0, -1.0, -1.5, -0.5 , -1.4} ,{ -0.0 , 2.0, -2.4, -2.2, -2.3 , -2.4 , -0.3 , -0.3 , -0.2} };
// Invoke GJK to compute distance // Invoke GJK to compute distance
dist = gjk( nCoordsA, inCoordsA, nCoordsB, inCoordsB ); dist = compute_minimum_distance( nCoordsA, inCoordsA, nCoordsB, inCoordsB );
// Output results // Output results
var s = string.Format("{0:0.##}", dist); var s = string.Format("{0:0.##}", dist);
var message = string.Format("The distance between {0} is {1}","A and B",s); var message = string.Format("The distance between {0} is {1}","A and B",s);
Console.WriteLine(message); Console.WriteLine(message);
Console.WriteLine("Press any key to exit");
Console.ReadLine();
} }
} }