From aa4d543e99f8eee63a4264f39ef3ad1ddf9d7611 Mon Sep 17 00:00:00 2001 From: Mattia Montanari Date: Tue, 14 Feb 2023 17:16:19 +0100 Subject: [PATCH] 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 --- .github/workflows/github-opengjk-examples.yml | 29 +++++++++++++------ CMakeLists.txt | 29 ++++++++++++------- examples/c/CMakeLists.txt | 6 ++-- examples/cs/main.cs | 14 +++++---- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/.github/workflows/github-opengjk-examples.yml b/.github/workflows/github-opengjk-examples.yml index a6ced2d..d3bcc71 100644 --- a/.github/workflows/github-opengjk-examples.yml +++ b/.github/workflows/github-opengjk-examples.yml @@ -13,6 +13,26 @@ jobs: - run: cmake --build build - 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: runs-on: ubuntu-latest container: mmontanari/devenv:buildenv-fedora @@ -31,12 +51,3 @@ jobs: - name: Check out repository code uses: actions/checkout@v3 - 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index b243977..8c5e8d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,15 +21,16 @@ # FOR A PARTICULAR PURPOSE. See GNU General Public License for details. # # User options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -option(BUILD_EXAMPLE "Build demo" ON) +option(BUILD_EXAMPLE "Build demo" ON ) +option(BUILD_MONO "Build C# example" OFF) # CMake setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 CMP0063 NEW) # Visibility of preset and hidden lines on shared libs -set( CMAKE_C_VISIBILITY_PRESET hidden) -set( CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) +# set( CMAKE_C_VISIBILITY_PRESET hidden) +set( CMAKE_VISIBILITY_INLINES_HIDDEN FALSE) set( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # Project setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -58,26 +59,34 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") endif() # 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}/include/openGJK/openGJK.h ) -target_include_directories( ${PROJECT_NAME} +target_include_directories( obj_openGJK PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${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 C_STANDARD 11 PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/openGJK/openGJK.h + POSITION_INDEPENDENT_CODE 1 ) +add_library(opengjk_ce SHARED $) + # Build demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if(BUILD_EXAMPLE) add_subdirectory(examples/c) @@ -85,11 +94,11 @@ endif(BUILD_EXAMPLE) # Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if (UNIX) - install(TARGETS ${PROJECT_NAME} PERMISSIONS WORLD_WRITE ) set(DESTDIR "/usr") - INSTALL(TARGETS ${PROJECT_NAME} + INSTALL(TARGETS opengjk_ce LIBRARY DESTINATION "${DESTDIR}/lib" PUBLIC_HEADER DESTINATION "${DESTDIR}/include" + PERMISSIONS WORLD_WRITE ) endif (UNIX) diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index c599e74..10fac5a 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -25,12 +25,12 @@ project(example_lib_opengjk_ce VERSION 1.0.0 ) -add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.c) -target_link_libraries(${PROJECT_NAME} lib_opengjk_ce) +add_executable(example_lib_opengjk_ce ${CMAKE_CURRENT_SOURCE_DIR}/main.c) +target_link_libraries(example_lib_opengjk_ce obj_openGJK m) # Copy input files for this example after build add_custom_command( - TARGET ${PROJECT_NAME} POST_BUILD + TARGET example_lib_opengjk_ce POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/userP.dat ${CMAKE_CURRENT_BINARY_DIR}/userP.dat diff --git a/examples/cs/main.cs b/examples/cs/main.cs index 8be1370..5cb1023 100644 --- a/examples/cs/main.cs +++ b/examples/cs/main.cs @@ -34,10 +34,13 @@ using System.Runtime.InteropServices; public class Tester { - - [DllImport("libopenGJKlib", EntryPoint="csFunction", CallingConvention = CallingConvention.StdCall)] +#if UNIX + [DllImport("libopengjk_ce.so", EntryPoint="csFunction", CallingConvention = CallingConvention.StdCall)] +#else + [DllImport("libopengjk_ce", EntryPoint = "csFunction", CallingConvention = CallingConvention.StdCall)] +#endif - static extern double gjk(int na, double [,] ia, int nb, double [,] ib); + static extern double compute_minimum_distance(int na, double [,] ia, int nb, double [,] ib); 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} }; // Invoke GJK to compute distance - dist = gjk( nCoordsA, inCoordsA, nCoordsB, inCoordsB ); + dist = compute_minimum_distance( nCoordsA, inCoordsA, nCoordsB, inCoordsB ); // Output results var s = string.Format("{0:0.##}", dist); var message = string.Format("The distance between {0} is {1}","A and B",s); Console.WriteLine(message); - Console.WriteLine("Press any key to exit"); - Console.ReadLine(); + } }