Skip to content

Commit

Permalink
Add doc to describe building with cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Nov 17, 2024
1 parent 39f642d commit be1a953
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [MIDI 2 in](./midi-2-in.md)
- [MIDI 2 out](./midi-2-out.md)
- [MIDI file support](./file.md)
- [Adding libremidi in a project](./cmake.md)

# Advanced features
- [MIDI 2 integrations](./midi-2-integrations.md)
Expand Down
86 changes: 86 additions & 0 deletions book/src/cmake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Adding libremidi to your project

## Through CMake

Consider the following existing CMake project for you application:

```cmake
project(my_app)
add_executable(my_app src/main.cpp)
```

Then you can add libremidi either directly for instance through a git submodule:

```cmake
project(my_app)
# example of folder structure
add_subdirectory(3rdparty/libremidi)
add_executable(my_app src/main.cpp)
target_link_libraries(my_app PRIVATE libremidi)
```

Or through FetchContent:

```cmake
project(my_app)
FetchContent_Declare(
libremidi
GIT_REPOSITORY https://github.com/celtera/libremidi
GIT_TAG main
)
FetchContent_MakeAvailable(libremidi)
add_executable(my_app src/main.cpp)
target_link_libraries(my_app PRIVATE libremidi)
```

## Through a custom build-system

If using a custom build-system, the main thing to be aware of that
CMake does automatically for you is passing the relevant flags which will enable each backend
and linking with the correct libraries.

For instance on Linux with ALSA:

```sh
$ g++ \
main.cpp \
-std=c++20 \
-I3rdparty/libremidi/include \
-DLIBREMIDI_ALSA=1 \
-DLIBREMIDI_HAS_UDEV=1
-ldl
```

or on macOS with CoreMIDI:

```sh
$ clang++ \
main.cpp \
-std=c++20 \
-I3rdparty/libremidi/include \
-DLIBREMIDI_COREMIDI=1 \
-framework CoreFoundation \
-framework CoreAudio \
-framework CoreMIDI
```

or on Win32 with WinMM:

```batch
> cl.exe ^
main.cpp ^
/std:c++latest ^
/I c:\libs\3rdparty\libremidi\include ^
/DLIBREMIDI_WINMM=1 ^
/DUNICODE=1 ^
/D_UNICODE=1 ^
path/to/winmm.lib
```

0 comments on commit be1a953

Please sign in to comment.