Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for macOS #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ fabric.properties

# End of https://www.gitignore.io/api/clion

/build
/build

.DS_Store
81 changes: 51 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,62 @@ set(SOURCES
src/custom.cpp
src/types.h
src/util.cpp
src/platform.h
)

interop/Linux/include/DeckLinkAPI.h
# interop/Linux/include/DeckLinkAPI_v7_1.h
# interop/Linux/include/DeckLinkAPI_v7_3.h
# interop/Linux/include/DeckLinkAPI_v7_6.h
# interop/Linux/include/DeckLinkAPI_v7_9.h
# interop/Linux/include/DeckLinkAPI_v8_0.h
# interop/Linux/include/DeckLinkAPI_v8_1.h
# interop/Linux/include/DeckLinkAPI_v9_2.h
# interop/Linux/include/DeckLinkAPI_v9_9.h
# interop/Linux/include/DeckLinkAPI_v10_2.h
# interop/Linux/include/DeckLinkAPI_v10_4.h
# interop/Linux/include/DeckLinkAPI_v10_5.h
# interop/Linux/include/DeckLinkAPI_v10_6.h
# interop/Linux/include/DeckLinkAPI_v10_9.h
# interop/Linux/include/DeckLinkAPI_v10_11.h
interop/Linux/include/DeckLinkAPIConfiguration.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_2.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_4.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_5.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_9.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_11.h
interop/Linux/include/DeckLinkAPIDeckControl.h
interop/Linux/include/DeckLinkAPIDiscovery.h
interop/Linux/include/DeckLinkAPIDispatch.cpp
interop/Linux/include/DeckLinkAPIModes.h
interop/Linux/include/DeckLinkAPITypes.h
interop/Linux/include/DeckLinkAPIVersion.h
interop/Linux/include/LinuxCOM.h
if(APPLE)
set(PLATFORM_SOURCES
interop/Mac/include/DeckLinkAPI.h
interop/Mac/include/DeckLinkAPIConfiguration.h
interop/Mac/include/DeckLinkAPIDeckControl.h
interop/Mac/include/DeckLinkAPIDiscovery.h
interop/Mac/include/DeckLinkAPIDispatch.cpp
interop/Mac/include/DeckLinkAPIModes.h
interop/Mac/include/DeckLinkAPITypes.h
interop/Mac/include/DeckLinkAPIVersion.h
)
elseif(UNIX)
set(PLATFORM_SOURCES
interop/Linux/include/DeckLinkAPI.h
# interop/Linux/include/DeckLinkAPI_v7_1.h
# interop/Linux/include/DeckLinkAPI_v7_3.h
# interop/Linux/include/DeckLinkAPI_v7_6.h
# interop/Linux/include/DeckLinkAPI_v7_9.h
# interop/Linux/include/DeckLinkAPI_v8_0.h
# interop/Linux/include/DeckLinkAPI_v8_1.h
# interop/Linux/include/DeckLinkAPI_v9_2.h
# interop/Linux/include/DeckLinkAPI_v9_9.h
# interop/Linux/include/DeckLinkAPI_v10_2.h
# interop/Linux/include/DeckLinkAPI_v10_4.h
# interop/Linux/include/DeckLinkAPI_v10_5.h
# interop/Linux/include/DeckLinkAPI_v10_6.h
# interop/Linux/include/DeckLinkAPI_v10_9.h
# interop/Linux/include/DeckLinkAPI_v10_11.h
interop/Linux/include/DeckLinkAPIConfiguration.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_2.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_4.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_5.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_9.h
# interop/Linux/include/DeckLinkAPIConfiguration_v10_11.h
interop/Linux/include/DeckLinkAPIDeckControl.h
interop/Linux/include/DeckLinkAPIDiscovery.h
interop/Linux/include/DeckLinkAPIDispatch.cpp
interop/Linux/include/DeckLinkAPIModes.h
interop/Linux/include/DeckLinkAPITypes.h
interop/Linux/include/DeckLinkAPIVersion.h
interop/Linux/include/LinuxCOM.h
)
endif()

include_directories(.)
add_library(decklink_c STATIC ${SOURCES})
add_library(decklink_c STATIC ${SOURCES} ${PLATFORM_SOURCES})

target_link_libraries(decklink_c dl pthread)
if(APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
target_link_libraries(decklink_c ${COREFOUNDATION_LIBRARY})
elseif (UNIX)
target_link_libraries(decklink_c dl pthread)
endif()

add_subdirectory(examples)

Expand Down
21 changes: 20 additions & 1 deletion generator/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn process_normal_class(
let name = func.get_name().unwrap();
// println!(" field: {:?} (offset: {} bits)", name, 0);

let (args, arg_names, callback_class) = ctx.parse_args(&func, &struct_name);
let (args, mut arg_names, callback_class) = ctx.parse_args(&func, &struct_name);
let ret_name = ctx.convert_type(&func.get_result_type().unwrap());

let func_name = format!("{}_{}", prefix, name.to_snake_case());
Expand Down Expand Up @@ -291,6 +291,25 @@ fn process_normal_class(
file_c,
format!("\treturn obj->{}({});\n", name, exec_params.join(", ")),
);
} else if name.starts_with("Get") && args.iter().any(|arg| arg.contains("const char **")) {
let char_pos = args.iter().position(|arg: &String| arg.contains("const char **")).unwrap() -1;
let char_arg_name = arg_names[char_pos].clone();
let dl_string_name = format!("{}String", char_arg_name);
arg_names[char_pos] = format!("&{}", dl_string_name);
write_str(file_c, format!("\tdlstring_t {};\n", dl_string_name));
write_str(
file_c,
format!("\tHRESULT result = obj->{}({});\n", name, arg_names.join(", ")),
);
write_str(file_c, format!("\tDlToConstChar({}, {});\n", dl_string_name, char_arg_name));
write_byte(file_c, b"\treturn result;\n");
} else if name.starts_with("SetString") {
let pos = arg_names.len() - 1;
arg_names[pos] = format!("ConstCharToDl({})", arg_names[pos]);
write_str(
file_c,
format!("\treturn obj->{}({});\n", name, arg_names.join(", ")),
);
} else {
write_str(
file_c,
Expand Down
1 change: 1 addition & 0 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn main() {
write_byte(&mut file_c, b"#include \"types.h\"\n");
write_byte(&mut file_c, b"#include \"../include/api.h\"\n");
write_byte(&mut file_c, b"#include \"callbacks.h\"\n");
write_byte(&mut file_c, b"#include \"platform.h\"\n");
write_byte(&mut file_c, b"\n");

write_byte(&mut file, b"#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
Expand Down
3 changes: 2 additions & 1 deletion generator/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn generate_types_files(
write_byte(file_cpp, b"#define DECKLINK_C_TYPES_H\n\n");
write_byte(
file_cpp,
b"#include \"../interop/Linux/include/DeckLinkAPI.h\"\n\n",
b"#include \"decklink_api.h\"\n\n",
);

let class_names: Vec<clang::Entity> = tu
Expand All @@ -42,6 +42,7 @@ pub fn generate_types_files(
}
}
}
write_byte(file_cpp, b"\nclass CustomDecklinkFrame;\ntypedef CustomDecklinkFrame cdecklink_custom_video_frame_t;\n");

write_byte(file_c, b"\n#endif //DECKLINK_C_TYPES_H\n");
// write_byte(file_cpp, b"\n#endif //DECKLINK_C_TYPES_H\n");
Expand Down
Loading