From be1a953a4d65dafc31be5d66ccc3f20ad9b791e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sat, 16 Nov 2024 19:25:59 -0500 Subject: [PATCH] Add doc to describe building with cmake --- book/src/SUMMARY.md | 1 + book/src/cmake.md | 86 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 book/src/cmake.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index ab96fa7..6ab6882 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -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) diff --git a/book/src/cmake.md b/book/src/cmake.md new file mode 100644 index 0000000..6713075 --- /dev/null +++ b/book/src/cmake.md @@ -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 +``` \ No newline at end of file