Skip to content

Commit 5a98df9

Browse files
committed
c++: first try to get a C++ modules build rolling
1 parent 9123385 commit 5a98df9

159 files changed

Lines changed: 833 additions & 515 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.22..4.2.0 FATAL_ERROR)
22
project(libremidi
33
VERSION 5.3.1
44
DESCRIPTION "A cross-platform MIDI library"
@@ -17,6 +17,7 @@ include(FetchContent)
1717
include(GNUInstallDirs)
1818

1919
### Options ###
20+
option(LIBREMIDI_MODULE_BUILD "C++ module mode" OFF)
2021
option(LIBREMIDI_HEADER_ONLY "Header-only mode" OFF)
2122

2223
cmake_dependent_option(LIBREMIDI_NO_COREMIDI "Disable CoreMidi back-end" OFF "APPLE" OFF)

cmake/libremidi.cppwinrt.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ if(CPPWINRT_TOOL)
9393
COMMAND "${CPPWINRT_TOOL}"
9494
"@${CMAKE_BINARY_DIR}/cppwinrt-src/cppwinrt.rsp"
9595
-output "${CMAKE_BINARY_DIR}/cppwinrt"
96-
-verbose
9796
)
9897
endif()
9998

cmake/libremidi.examples.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,14 @@ if(Boost_cobalt_FOUND)
110110
target_link_libraries(coroutines PRIVATE Boost::cobalt)
111111
endif()
112112

113-
add_executable(libremidi_c_api examples/c_api.c)
114-
target_link_libraries(libremidi_c_api PRIVATE libremidi)
115-
if(LIBREMIDI_HEADER_ONLY)
116-
target_sources(libremidi_c_api PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/libremidi/libremidi-c.cpp")
113+
if(NOT LIBREMIDI_MODULES_BUILD)
114+
add_executable(libremidi_c_api examples/c_api.c)
115+
target_link_libraries(libremidi_c_api PRIVATE libremidi)
116+
if(LIBREMIDI_HEADER_ONLY)
117+
target_sources(libremidi_c_api PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/libremidi/libremidi-c.cpp")
118+
endif()
117119
endif()
120+
121+
122+
add_executable(libremidi_modules examples/modules.cppm)
123+
target_link_libraries(libremidi_modules PRIVATE libremidi)

cmake/libremidi.install.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
if(NOT LIBREMIDI_HEADER_ONLY)
1+
if(LIBREMIDI_MODULE_BUILD)
2+
message("Install not supported yet as of CMake 4.2")
3+
return()
4+
elseif(NOT LIBREMIDI_HEADER_ONLY)
25
install(TARGETS libremidi
36
EXPORT libremidi-targets
47
ARCHIVE
58
RUNTIME
69
LIBRARY
710
)
11+
install(EXPORT libremidi-targets
12+
DESTINATION lib/cmake/libremidi)
813
else()
914
install(TARGETS libremidi
1015
EXPORT libremidi-targets
1116
)
17+
install(EXPORT libremidi-targets
18+
DESTINATION lib/cmake/libremidi)
1219
endif()
13-
install(EXPORT libremidi-targets
14-
DESTINATION lib/cmake/libremidi)
1520
install(DIRECTORY include
1621
DESTINATION .)
1722

cmake/libremidi.library.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
### Create the library ###
2-
if(LIBREMIDI_HEADER_ONLY)
2+
if(LIBREMIDI_MODULE_BUILD)
3+
add_library(libremidi STATIC)
4+
set(_public PUBLIC)
5+
set(_private PRIVATE)
6+
target_sources(libremidi
7+
PUBLIC
8+
FILE_SET CXX_MODULES
9+
FILES
10+
"src/libremidi.ixx"
11+
)
12+
elseif(LIBREMIDI_HEADER_ONLY)
313
add_library(libremidi INTERFACE)
414
set(_public INTERFACE)
515
set(_private INTERFACE)

cmake/libremidi.winmidi.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ if(CPPWINRT_TOOL)
4646
COMMAND "${CPPWINRT_TOOL}"
4747
"@${CMAKE_BINARY_DIR}/cppwinrt-src/cppwinrt-winmidi.rsp"
4848
-output "${CMAKE_BINARY_DIR}/cppwinrt-winmidi"
49-
-verbose
5049
)
5150

5251
file(

examples/modules.cppm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import libremidi;
2+
3+
#include "utils.hpp"
4+
5+
#include <cstdlib>
6+
#include <iostream>
7+
8+
int main()
9+
{
10+
libremidi::observer observer;
11+
if (observer.get_input_ports().empty())
12+
return 1;
13+
if (observer.get_output_ports().empty())
14+
return 1;
15+
16+
libremidi::midi_in midi_in{{.on_message = [](const libremidi::message& message) {
17+
std::cout << message << std::endl;
18+
}}};
19+
20+
if (auto err = midi_in.open_port(observer.get_input_ports()[0]); err != stdx::error{})
21+
err.throw_exception();
22+
23+
libremidi::midi_out midi_out;
24+
if (auto err = midi_out.open_port(observer.get_output_ports()[0]); err != stdx::error{})
25+
err.throw_exception();
26+
27+
midi_out.send_message(176, 7, 100);
28+
29+
int c;
30+
while ((c = getchar()) != '\n' && c != EOF)
31+
;
32+
return 0;
33+
}

include/libremidi/api-c.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#pragma once
2+
#ifndef LIBREMIDI_API_C_H
3+
#define LIBREMIDI_API_C_H
24

3-
#if __cplusplus
5+
#if __cplusplus && !defined(LIBREMIDI_MODULE_BUILD)
46
extern "C" {
57
#endif
68

79
//! MIDI API specifier arguments.
810
//! To get information on which feature is supported by each back-end, check their backend file
911
//! in e.g. backends/winmm.hpp, etc.
10-
typedef enum libremidi_api
12+
enum libremidi_api
1113
{
1214
UNSPECIFIED = 0x0, /*!< Search for a working compiled API. */
1315

@@ -36,8 +38,11 @@ typedef enum libremidi_api
3638
PIPEWIRE_UMP, /*!< MIDI2 over PipeWire. Requires v1.4+. */
3739

3840
DUMMY = 0xFFFF /*!< A compilable but non-functional API. */
39-
} libremidi_api;
41+
};
4042

41-
#if __cplusplus
43+
typedef enum libremidi_api libremidi_api;
44+
45+
#if __cplusplus && !defined(LIBREMIDI_MODULE_BUILD)
4246
}
4347
#endif
48+
#endif

include/libremidi/api.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <string_view>
66
#include <vector>
77

8-
namespace libremidi
8+
NAMESPACE_LIBREMIDI
99
{
1010
//! MIDI API specifier arguments.
1111
//! To get information on which feature is supported by each back-end, check their backend file

include/libremidi/backends.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
#include <libremidi/backends/android/android.hpp>
8282
#endif
8383

84-
namespace libremidi
84+
NAMESPACE_LIBREMIDI
8585
{
8686
// The order here will control the order of the API search in
8787
// the constructor.
@@ -93,7 +93,7 @@ constexpr auto make_tl(unused, Args...)
9393

9494
namespace midi1
9595
{
96-
static constexpr auto available_backends = make_tl(
96+
LIBREMIDI_STATIC constexpr auto available_backends = make_tl(
9797
0
9898
#if defined(LIBREMIDI_ALSA)
9999
,
@@ -167,7 +167,7 @@ auto for_backend(libremidi::API api, F&& f)
167167

168168
namespace midi2
169169
{
170-
static constexpr auto available_backends = make_tl(
170+
LIBREMIDI_STATIC constexpr auto available_backends = make_tl(
171171
0
172172
#if defined(LIBREMIDI_ALSA) && LIBREMIDI_ALSA_HAS_UMP
173173
,

0 commit comments

Comments
 (0)