Skip to content

Instantly share code, notes, and snippets.

@adamkewley
Last active January 18, 2023 09:17
Show Gist options
  • Save adamkewley/8dae579b28442dded15a4f6ffaff47f6 to your computer and use it in GitHub Desktop.
Save adamkewley/8dae579b28442dded15a4f6ffaff47f6 to your computer and use it in GitHub Desktop.
A simplified version of the opensim-core build instructions, for C++ developers.
# this is a semi-manual guide for setting up a Visual Studio 2022-based
# development environment for opensim-core
#
# you can run the script, but it only builds OpenSim's dependencies - you
# have to manually set up Visual Studio because it has in-built CMake support
#
# before doing this you need to install:
#
# - CMake (https://cmake.org/download/)
# - Git (https://git-scm.com/downloads)
# - Visual Studio Community 2022 (https://visualstudio.microsoft.com/vs/)
# - be sure to select C/C++ development, if it asks
#
# they should all be added to the PATH, such that (e.g.) `cmake` and `git` can be ran
# from a terminal (google: "add CMake to PATH Windows" etc. if you run into problems)
# 1. open a terminal by Shift+Right-Clicking on your desktop then "Open Powershell window here"
#
# - the rest of this file is powershell/terminal commands that you can either run manually by
# copy+pasting things, or you can run this script by running `simplified_opensim_build_guide.ps1`
# 2. clone opensim-core source somewhere (in this example: opensim-checkout)
git clone https://github.com/opensim-org/opensim-core opensim-checkout
# 3. step into the source directory
cd opensim-checkout
# 4. configure + build OpenSim's dependencies (requires CMake + Visual Studio is installed)
mkdir opensim-core-dependencies-build
cd opensim-core-dependencies-build
cmake -G"Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="../opensim-core-dependencies-install" -DSUPERBUILD_ezc3d:BOOL=off -DOPENSIM_WITH_CASADI:BOOL=off -DOPENSIM_WITH_TROPTER:BOOL=off ../dependencies/
cmake --build . --config RelWithDebInfo -j4 # change this number to change parallelism
cd ..
# 5. setup Visual Studio (manual)
#
# a. open Visual Studio 2022
# b. open the checkout dir (opensim-checkout) as a folder
#
# c. configure CMake settings (e.g. via "Open CMake Settings Editor")
#
# - open the CMake settings editor by pressing "Open CMake Settings Editor",
# if it pops up, or right-clicking the `CMakeLists.txt` file and Clicking
# `CMake Settings` - this should open the `CMakeSettings.json` editor
# - set "Configuration type:" to "RelWithDebInfo"
# - in "CMake Variables and Cache" set "OPENSIM_DEPENDENCIES_DIR" to
# the "opensim-core-dependencies-install" dir created above
# - in "CMake Variables and Cache" turn off "OPENSIM_WITH_CASADI"
# (we disabled building the dependency above - to help build speeds)
# - in "CMake Variables and Cache" turn off "OPENSIM_WITH_TROPTER"
# (we disabled building the dependency above - to help build speeds)
#
# d. with the above settings, saving the CMake configuration (CMakeSettings.json)
# should sucessfully configure the opensim-core project. You can also manually
# trigger configuration through the `Project -> Configure Cache` button at the
# top of the Visual Studio UI. Sucessful configuration usually prints something
# like "CMake generation finished" to the output window.
#
# e. set the "startup project" (i.e. what runs when the play button is pressed):
#
# - in the solution explorer (left-hand side, usually), there is a button for
# "Switch between available views" at the top. Click that button until the
# solution explorer presents `CMake Targets View`
# - find the target you want to run (e.g. OpenSim Project\Examples\exampleHopperDevice (executable))
# - right-click it and select "Set as Startup Item"
# - (optional) once the startup project is set, you can switch back to the folder view,
# if you prefer working from there - you can also just expand the chosen target to see all cpp
# files for it
#
# f. build+run the "startup project" by pressing the green arrow at the top, or F5
#
# - note: building opensim may take a long time
#
# g. now, whenever you edit a source file (e.g. OpenSim\Examples\ExampleHopperDevice\exampleHopperDevice.cpp)
# and then re-press the run button (or press F5), the code will automatically re-compile and re-run
#
# h. have fun ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment