Skip to content

Commit

Permalink
Sling osim into tree
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Oct 15, 2024
1 parent 2fcc4aa commit c221a0f
Show file tree
Hide file tree
Showing 11 changed files with 752 additions and 32 deletions.
15 changes: 12 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
[submodule "third_party/tomlplusplus"]
path = third_party/tomlplusplus
url = https://github.com/ComputationalBiomechanicsLab/tomlplusplus
[submodule "third_party/opensim-core"]
path = third_party/opensim-core
url = https://github.com/ComputationalBiomechanicsLab/opensim-core
[submodule "third_party/lunasvg"]
path = third_party/lunasvg
url = https://github.com/ComputationalBiomechanicsLab/lunasvg
Expand All @@ -34,3 +31,15 @@
[submodule "third_party/ImGuiColorTextEdit"]
path = third_party/ImGuiColorTextEdit
url = https://github.com/ComputationalBiomechanicsLab/ImGuiColorTextEdit.git
[submodule "third_party/OpenBLAS"]
path = third_party/OpenBLAS
url = https://github.com/OpenMathLib/OpenBLAS
[submodule "ak"]
path = third_party/opensim-core
url = https://github.com/adamkewley/opensim-core
[submodule "third_party/simbody"]
path = third_party/simbody
url = https://github.com/adamkewley/simbody
[submodule "third_party/spdlog"]
path = third_party/spdlog
url = https://github.com/gabime/spdlog
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(osc VERSION 0.5.15 LANGUAGES CXX)
project(osc VERSION 0.5.15 LANGUAGES C CXX)


# -------------- gather user-facing build cache vars ---------------- #
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_subdirectory(oscar_compiler_configuration)
add_subdirectory(oscar)
add_subdirectory(oscar_demos)
if (${OSC_BUILD_OPENSIMCREATOR})
add_subdirectory(osim)
add_subdirectory(oscar_simbody)
add_subdirectory(OpenSimThirdPartyPlugins)
add_subdirectory(OpenSimCreator)
Expand Down
2 changes: 0 additions & 2 deletions src/OpenSimThirdPartyPlugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
find_package(OpenSim REQUIRED CONFIG)

add_library(OpenSimThirdPartyPlugins STATIC

opensim-jam-org/jam-plugin/Smith2018ArticularContactForce.cpp
Expand Down
646 changes: 646 additions & 0 deletions src/osim/CMakeLists.txt

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions src/osim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# `osim.{a,lib}`

> A hack to make using/building OpenSim easier.
`osim` attempts to provide a build(system) for OpenSim where:

- All of its dependencies *may* be built as static libraries from source
using only Cmake and a C/C++ compiler, with the ability to choose where
to source `libBLAS` and `libLACK` via cmake's `find_package`'s customization
points.

- Simbody and OpenSim are unified into a single `CMakeLists.txt` file
that produces a single statically-linkable target: `osim.{a,lib}`

- No compiler flags are performed by the build, so that downstream code
can easily modify the build with the appropriate environment variables
(e.g. `CXXFLAGS`)

- The `CMakeLists.txt` file is compatible with downstream projects building
it via `add_subdirectory` (+`target_link_libraries(... osim)`), which
is useful for downstream developers that want to modify Simbody/OpenSim
in-place while building their project.

Secondarily, the longer-term goal of this project would be to provide simplified
CPython bindings to OpenSim that are compatible with numpy, pandas, and matplotlib,
because I know the researchers <3 that.

# Differences from OpenSim

- **Moco is not supported**. It pulls in a bunch of additional third-party code,
which makes building OpenSim much more complicated than necessary. [OpenSim Creator](https://github.com/ComputationalBiomechanicsLab/opensim-creator)
doesn't use Moco, so it was dropped entirely.

- **The API must be manually initialized**. OpenSim's library initialization code now
no longer automatically runs during static initialization. It is incompatible
with static linking, which can muddle up static initialization order. Instead,
downstream code should manually call the `RegisterTypes_` when the application
starts. See `src/example_app.cpp` for an example of this.


# Building

```bash
# get simbody, opensim, OpenBLAS (optional), and spdlog sources
git submodule update --init --recursive

# configure third-party dependencies build
cmake -S third_party -B deps-build -DCMAKE_INSTALL_PREFIX=${PWD}/deps-install
# optional: use `-DOSIMDEPS_GET_OPENBLAS=OFF` to skip OpenBLAS if you're
# planning on using an OS-provided BLAS+LAPACK

# build + install third-party dependencies
cmake --build deps-build

# configure osim (Simbody + OpenSim) build
cmake -S . -B build -DCMAKE_PREFIX_PATH=${PWD}/deps-install

# build osim
cmake --build build

# e.g.: this is why it's handy to build OpenBLAS /w static linking etc.
lddtree build/example_app
```

49 changes: 24 additions & 25 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ set(OSCDEPS_GET_IMGUI ON CACHE BOOL "enable getting imgui")
set(OSCDEPS_GET_IMGUICOLORTEXTEDIT ON CACHE BOOL "enable getting ImGuiColorTextEdit")
set(OSCDEPS_GET_IMPLOT ON CACHE BOOL "enable gettting implot")
set(OSCDEPS_GET_LUA ON CACHE BOOL "enable getting lua scripting language library")
set(OSCDEPS_GET_OPENSIM ON CACHE BOOL "enable getting OpenSim (+its dependencies)")
set(OSCDEPS_GET_OPENBLAS ON CACHE BOOL "enable getting OpenBLAS")
set(OSCDEPS_GET_SPDLOG ON CACHE BOOL "enable getting spdlog")
set(OSCDEPS_BUILD_ALWAYS OFF CACHE BOOL "set BUILD_ALWAYS on all dependency targets, useful when editing dependencies")
# note: no `OSCDEPS_GET_SIMBODY`, because it's built in-tree by `src/osim`
# note: no `OSCDEPS_GET_OPENSIM`, because it's built in-tree by `src/osim`

include(ExternalProject) # ExternalProject_Add
include(GNUInstallDirs) # CMAKE_INSTALL_LIBDIR
Expand Down Expand Up @@ -193,37 +196,33 @@ if(${OSCDEPS_GET_LUA})
)
endif()

if(${OSCDEPS_GET_OPENSIM})
ExternalProject_Add(opensim-core-dependencies
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/opensim-core/dependencies
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/opensim-core-dependencies-install
INSTALL_COMMAND "" # OpenSim's dependency build installs during its build step
if(${OSCDEPS_GET_OPENBLAS})
ExternalProject_Add(OpenBLAS
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/OpenBLAS
BUILD_ALWAYS ${OSCDEPS_BUILD_ALWAYS}
CMAKE_CACHE_ARGS
${OSCDEPS_DEPENDENCY_CMAKE_ARGS}
-DOPENSIM_WITH_CASADI:BOOL=OFF
-DOPENSIM_WITH_TROPTER:BOOL=OFF
-DCMAKE_INSTALL_PREFIX:STRING=<INSTALL_DIR>
"-DSIMBODY_EXTRA_CMAKE_ARGS:STRING=-DBUILD_VISUALIZER:BOOL=OFF"
-DC_LAPACK:BOOL=ON
-DBUILD_STATIC_LIBS:BOOL=ON
)
endif()

ExternalProject_Add(opensim-core
DEPENDS opensim-core-dependencies
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/opensim-core
TEST_EXCLUDE_FROM_MAIN ON
if(${OSCDEPS_GET_SPDLOG})
set(OSCDEPS_SPDLOG_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if(MSVC)
# `spdlog` transitively uses a deprecated `stdext::checked_array_iterator`
set(OSCDEPS_SPDLOG_CXX_FLAGS "${OSCDEPS_SPDLOG_CXX_FLAGS} /D_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING")
endif()
ExternalProject_Add(spdlog
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/spdlog
BUILD_ALWAYS ${OSCDEPS_BUILD_ALWAYS}
CMAKE_CACHE_ARGS
${OSCDEPS_DEPENDENCY_CMAKE_ARGS}
-DOPENSIM_WITH_CASADI:BOOL=OFF
-DOPENSIM_WITH_TROPTER:BOOL=OFF
-DBUILD_API_ONLY:BOOL=ON
-DOPENSIM_DISABLE_LOG_FILE:BOOL=ON
-DOPENSIM_BUILD_INDIVIDUAL_APPS:BOOL=OFF
-DOPENSIM_DEPENDENCIES_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/opensim-core-dependencies-install
-DBUILD_JAVA_WRAPPING:BOOL=OFF
-DOPENSIM_INSTALL_UNIX_FHS:BOOL=ON
-DOPENSIM_BUILD_INDIVIDUAL_APPS_DEFAULT:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DBUILD_API_EXAMPLES:BOOL=OFF
-DSPDLOG_BUILD_BENCH:BOOL=OFF
-DSPDLOG_BUILD_TESTS:BOOL=OFF
-DSPDLOG_BUILD_EXAMPLE:BOOL=OFF
-DSPDLOG_BUILD_SHARED:BOOL=OFF
-DCMAKE_CXX_FLAGS:STRING=${OSCDEPS_SPDLOG_CXX_FLAGS}
)
endif()

1 change: 1 addition & 0 deletions third_party/OpenBLAS
Submodule OpenBLAS added at 5ef8b1
2 changes: 1 addition & 1 deletion third_party/opensim-core
1 change: 1 addition & 0 deletions third_party/simbody
Submodule simbody added at b5d626
1 change: 1 addition & 0 deletions third_party/spdlog
Submodule spdlog added at 453be2

0 comments on commit c221a0f

Please sign in to comment.