Skip to content

Commit

Permalink
build ODE from source if the package is not found, even if flag is no…
Browse files Browse the repository at this point in the history
…t set
  • Loading branch information
Michel Schmid authored and g3force committed Feb 24, 2024
1 parent 89860fa commit aed1509
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: "Build"
# for some reason qt5 is not correctly in the path and this will break whenever the location of it changes
# 5.15.11 is for macos-12 and 5.15.12 is for macos-13
run: PATH=/usr/local/Cellar/qt@5/5.15.11/lib/cmake/Qt5:/usr/local/Cellar/qt@5/5.15.12/lib/cmake/Qt5:$PATH && make BUILD_ODE=ON
run: PATH=/usr/local/Cellar/qt@5/5.15.11/lib/cmake/Qt5:/usr/local/Cellar/qt@5/5.15.12/lib/cmake/Qt5:$PATH && make

build-windows:
runs-on: windows-latest
Expand Down
56 changes: 16 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,48 +83,24 @@ list(APPEND libs Qt5::Core Qt5::Widgets Qt5::OpenGL Qt5::Network)

# ODE
if(BUILD_ODE)
# build ODE, because some versions of it cause grSim to segfault somewhere
# could be because in some packages the double precision is turned off
include(ExternalProject)

ExternalProject_Add(ode_external
GIT_REPOSITORY https://bitbucket.org/odedevs/ode.git
GIT_TAG 0.16.4
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_C_COMPILER:PATH=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER}
-DCMAKE_MAKE_PROGRAM:PATH=${CMAKE_MAKE_PROGRAM}
# necessary, because it does not build the static libs if this is ON
-DBUILD_SHARED_LIBS=OFF
# if this is OFF grSim just dies instantly and INSTALL.md says it should be ON
-DODE_DOUBLE_PRECISION=ON
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
STEP_TARGETS install
)

set(ODE_LIB_SUBPATH "${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ode${CMAKE_STATIC_LIBRARY_SUFFIX}")

# the byproducts are available after the install step
ExternalProject_Add_Step(ode_external out
DEPENDEES install
BYPRODUCTS
"<INSTALL_DIR>/${ODE_LIB_SUBPATH}"
)

ExternalProject_Get_Property(ode_external install_dir)
set(ODE_LIBRARY "${install_dir}/${ODE_LIB_SUBPATH}")
list(APPEND libs ${ODE_LIBRARY})
target_include_directories(${app} PRIVATE "${install_dir}/include")

include(BuildODE)
add_dependencies(${app} ode_external)
elseif(WIN32)
find_package(ODE CONFIG REQUIRED)
list(APPEND libs ODE::ODE)
else()
find_package(ODE REQUIRED)
list(APPEND libs ode::ode)
if(WIN32)
find_package(ODE CONFIG)
set(ODE_LIB_NAME ODE::ODE)
else()
find_package(ODE)
set(ODE_LIB_NAME ode::ode)
endif()

if(ODE_FOUND)
list(APPEND libs ${ODE_LIB_NAME})
else()
# if ODE could not be found just build it
include(BuildODE)
add_dependencies(${app} ode_external)
endif()
endif()

# VarTypes
Expand Down
34 changes: 34 additions & 0 deletions cmake/modules/BuildODE.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# build ODE, because some versions of it cause grSim to segfault somewhere
# could be because in some packages the double precision is turned off
include(ExternalProject)

ExternalProject_Add(ode_external
GIT_REPOSITORY https://bitbucket.org/odedevs/ode.git
GIT_TAG 0.16.4
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_C_COMPILER:PATH=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER}
-DCMAKE_MAKE_PROGRAM:PATH=${CMAKE_MAKE_PROGRAM}
# necessary, because it does not build the static libs if this is ON
-DBUILD_SHARED_LIBS=OFF
# if this is OFF grSim just dies instantly and INSTALL.md says it should be ON
-DODE_DOUBLE_PRECISION=ON
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
STEP_TARGETS install
)

set(ODE_LIB_SUBPATH "${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ode${CMAKE_STATIC_LIBRARY_SUFFIX}")

# the byproducts are available after the install step
ExternalProject_Add_Step(ode_external out
DEPENDEES install
BYPRODUCTS
"<INSTALL_DIR>/${ODE_LIB_SUBPATH}"
)

ExternalProject_Get_Property(ode_external install_dir)
set(ODE_LIBRARY "${install_dir}/${ODE_LIB_SUBPATH}")
list(APPEND libs ${ODE_LIBRARY})
target_include_directories(${app} PRIVATE "${install_dir}/include")

0 comments on commit aed1509

Please sign in to comment.