diff --git a/ScenariumEditor.QML/CMakeLists.txt b/ScenariumEditor.QML/CMakeLists.txt index 2111b81..e1c6bae 100644 --- a/ScenariumEditor.QML/CMakeLists.txt +++ b/ScenariumEditor.QML/CMakeLists.txt @@ -62,32 +62,43 @@ target_compile_options(scenarium_editor PRIVATE -Wno-unused-const-variable ) -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - target_link_libraries(scenarium_editor - PUBLIC - ${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/debug/libcs_interop.dll.a - ) -else () - target_link_libraries(scenarium_editor - PUBLIC - ${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/release/libcs_interop.dll.a - ) -endif () - -target_include_directories(scenarium_editor PUBLIC lib) if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") target_link_options(scenarium_editor PUBLIC -static -static-libgcc -static-libstdc++ ) + + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(LIBB_CS_INTEROP_FILE "${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/debug/libcs_interop.dll.a") + set(LIBB_CS_INTEROP_DYLIB_FILE "${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/debug/cs_interop.dll") + else () + set(LIBB_CS_INTEROP_FILE "${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/release/libcs_interop.dll.a") + set(LIBB_CS_INTEROP_DYLIB_FILE "${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/release/cs_interop.dll") + endif () +elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(LIBB_CS_INTEROP_FILE "${CMAKE_SOURCE_DIR}/../target/debug/libcs_interop.dylib") + set(LIBB_CS_INTEROP_DYLIB_FILE "${CMAKE_SOURCE_DIR}/../target/debug/libcs_interop.dylib") + else () + set(LIBB_CS_INTEROP_FILE "${CMAKE_SOURCE_DIR}/../target/release/libcs_interop.dylib") + set(LIBB_CS_INTEROP_DYLIB_FILE "${CMAKE_SOURCE_DIR}/../target/release/libcs_interop.dylib") + endif () endif () +target_link_libraries(scenarium_editor + PUBLIC + ${LIBB_CS_INTEROP_FILE} +) + +target_include_directories(scenarium_editor PUBLIC lib) + + add_custom_command( TARGET scenarium_editor POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/debug/cs_interop.dll + ${LIBB_CS_INTEROP_DYLIB_FILE} $ COMMENT "Copying DLL file to build directory" ) @@ -107,7 +118,6 @@ install(TARGETS scenarium_editor ) - # Tests include(FetchContent) FetchContent_Declare( @@ -121,7 +131,7 @@ file(GLOB_RECURSE TEST_SRC_FILES "tests/*.cpp") add_executable(tests ${SRC_FILES} ${TEST_SRC_FILES}) target_link_libraries(tests PRIVATE Catch2::Catch2WithMain - ${CMAKE_SOURCE_DIR}/../target/x86_64-pc-windows-gnu/debug/libcs_interop.dll.a + ${LIBB_CS_INTEROP_FILE} ) #list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) include(CTest) diff --git a/ScenariumEditor.QML/src/CoreContext.cpp b/ScenariumEditor.QML/src/CoreContext.cpp index 2c50503..333cf23 100644 --- a/ScenariumEditor.QML/src/CoreContext.cpp +++ b/ScenariumEditor.QML/src/CoreContext.cpp @@ -29,12 +29,12 @@ struct FfiNode { FfiBuf outputs; }; -__declspec(dllimport) void *create_context(); -__declspec(dllimport) void destroy_context(void *ctx); +DLL_IMPORT void *create_context(); +DLL_IMPORT void destroy_context(void *ctx); -__declspec(dllimport) FfiBuf get_funcs(void *ctx); -__declspec(dllimport) FfiBuf get_nodes(void *ctx); -__declspec(dllimport) FfiNode new_node(void *ctx, FfiUuid func_id); +DLL_IMPORT FfiBuf get_funcs(void *ctx); +DLL_IMPORT FfiBuf get_nodes(void *ctx); +DLL_IMPORT FfiNode new_node(void *ctx, FfiUuid func_id); } diff --git a/ScenariumEditor.QML/src/utils/interop.cpp b/ScenariumEditor.QML/src/utils/interop.cpp index 36e494f..8ad7fa9 100644 --- a/ScenariumEditor.QML/src/utils/interop.cpp +++ b/ScenariumEditor.QML/src/utils/interop.cpp @@ -2,7 +2,7 @@ extern "C" { -__declspec(dllimport) void destroy_ffi_buf(FfiBuf buf); +DLL_IMPORT void destroy_ffi_buf(FfiBuf buf); } diff --git a/ScenariumEditor.QML/src/utils/interop.hpp b/ScenariumEditor.QML/src/utils/interop.hpp index 12f6368..0a6ea71 100644 --- a/ScenariumEditor.QML/src/utils/interop.hpp +++ b/ScenariumEditor.QML/src/utils/interop.hpp @@ -8,6 +8,12 @@ #include #include +#ifdef _WIN32 +#define DLL_IMPORT __declspec(dllimport) +#else +#define DLL_IMPORT +#endif + extern "C" { struct FfiBuf { void *data; diff --git a/ScenariumEditor.QML/src/utils/uuid.cpp b/ScenariumEditor.QML/src/utils/uuid.cpp index 1260508..4174e9e 100644 --- a/ScenariumEditor.QML/src/utils/uuid.cpp +++ b/ScenariumEditor.QML/src/utils/uuid.cpp @@ -3,9 +3,9 @@ #include "interop.hpp" extern "C" { -__declspec(dllimport) FfiUuid uuid_new_v4_extern(); -__declspec(dllimport) FfiUuid uuid_from_string_extern(FfiBuf str); -__declspec(dllimport) FfiBuf uuid_to_string_extern(FfiUuid uuid); +DLL_IMPORT FfiUuid uuid_new_v4_extern(); +DLL_IMPORT FfiUuid uuid_from_string_extern(FfiBuf str); +DLL_IMPORT FfiBuf uuid_to_string_extern(FfiUuid uuid); } uuid uuid::new_v4() {