Skip to content

Instantly share code, notes, and snippets.

@adamkewley
Created January 21, 2026 08:55
Show Gist options
  • Select an option

  • Save adamkewley/558203accb25e011dabd9a50c4487dd3 to your computer and use it in GitHub Desktop.

Select an option

Save adamkewley/558203accb25e011dabd9a50c4487dd3 to your computer and use it in GitHub Desktop.
Build OPynSim into an install root for throwaway C++ projects
# !!!! WARNING: THIS ISN'T OFFICIAL IN ANY WAY: DON'T COME CRYING TO ME IF YOUR C++ BREAKS !!!!
# # Before: get source code and enter directory:
# git clone https://github.com/opynsim/opynsim
# cd opynsim
build_type=Release
build_dir=${PWD}/build
install_dir=${PWD}/install
# Build + install dependency libraries + headers
cmake -G Ninja -S third_party/ -B ${build_dir}/third_party -DCMAKE_BUILD_TYPE=${build_type} -DCMAKE_INSTALL_PREFIX=${install_dir}
cmake --build ${build_dir}/third_party
# Build + install libopynsim library + headers
#
# Alternatively: you should now be able to open the opynsim directory in a C++ IDE and use
# one of the preconfigured CMakePresets.json
cmake -G Ninja -S . -B ${build_dir} -DCMAKE_BUILD_TYPE=${build_type} -DCMAKE_PREFIX_PATH=${install_dir} -DCMAKE_INSTALL_PREFIX=${install_dir} -DBUILD_TESTING=OFF -DOPYN_BUILD_PYTHON_BINDINGS=OFF
cmake --build ${build_dir} --target install
# # Cleanup (optional)
# rm -rf ${build_dir}
# Usage in downstream projects:
#
# In your downstream CMakeLists.txt:
#
# find_package(opynsim REQUIRED)
# # (other stuff)
# target_link_libraries(downstream_project PRIVATE opynsim) # link to it
#
# In your build script, depending on how/where you installed it:
#
# cmake -S downstream_project -B build_dir -DCMAKE_PREFIX_PATH=${install_dir}
# # (i.e. tell cmake where to find the install directory)
#
# In your C++:
#
# #include <libopynsim/SOME_HEADER>
# #include <OpenSim/Simulation/Model/Model.h> // opynsim's build also build OpenSim/Simbody
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment