From aed1509b15ade3016151185113299a7eaea28bc8 Mon Sep 17 00:00:00 2001 From: Michel Schmid Date: Thu, 15 Feb 2024 17:14:34 +0100 Subject: [PATCH] build ODE from source if the package is not found, even if flag is not set --- .github/workflows/build.yaml | 2 +- CMakeLists.txt | 56 +++++++++++------------------------- cmake/modules/BuildODE.cmake | 34 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 cmake/modules/BuildODE.cmake diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index aa0989d..74ee364 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index a2a84dd..f9ffc9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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= - -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= - 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 - "/${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 diff --git a/cmake/modules/BuildODE.cmake b/cmake/modules/BuildODE.cmake new file mode 100644 index 0000000..41aa54f --- /dev/null +++ b/cmake/modules/BuildODE.cmake @@ -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= + -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= + 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 + "/${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")