diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 5cc35b531bb23..1a175a208e413 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -120,6 +120,9 @@ if (GO_EXECUTABLE AND GO_VERSION_OK) add_custom_command( OUTPUT ${OCI_LIB} ${OCI_HEADER} COMMAND ${GO_EXECUTABLE} build -buildmode=c-archive -o ${OCI_LIB} ${OCI_GO_DIR}/oci.go + # Patch the generated header to fix clang compatibility on Windows + COMMAND ${CMAKE_COMMAND} -E echo "Patching liboci.h for clang compatibility" + COMMAND ${CMAKE_COMMAND} -DHEADER_FILE=${OCI_HEADER} -P ${CMAKE_CURRENT_SOURCE_DIR}/patch_liboci_header.cmake WORKING_DIRECTORY ${OCI_GO_DIR} DEPENDS ${OCI_GO_DIR}/oci.go ${OCI_GO_DIR}/go.mod COMMENT "Building OCI Go library" diff --git a/common/patch_liboci_header.cmake b/common/patch_liboci_header.cmake new file mode 100644 index 0000000000000..5c88b4ae7737f --- /dev/null +++ b/common/patch_liboci_header.cmake @@ -0,0 +1,29 @@ +# Patch liboci.h to fix clang compatibility on Windows +# This script is called by CMakeLists.txt after Go generates the header + +if(NOT DEFINED HEADER_FILE) + message(FATAL_ERROR "HEADER_FILE not defined") +endif() + +if(NOT EXISTS "${HEADER_FILE}") + message(FATAL_ERROR "Header file does not exist: ${HEADER_FILE}") +endif() + +# Read the header file +file(READ "${HEADER_FILE}" HEADER_CONTENT) + +# Replace the problematic section +# The issue is that clang on Windows defines _MSC_VER but doesn't support _Fcomplex/_Dcomplex +# We need to check for __clang__ and use C++ complex types in that case + +string(REPLACE + "#ifdef _MSC_VER\n#if !defined(__cplusplus) || _MSVC_LANG <= 201402L\n#include \ntypedef _Fcomplex GoComplex64;\ntypedef _Dcomplex GoComplex128;\n#else\n#include \ntypedef std::complex GoComplex64;\ntypedef std::complex GoComplex128;\n#endif" + "#ifdef _MSC_VER\n#if defined(__clang__) || (defined(__cplusplus) && _MSVC_LANG > 201402L)\n#include \ntypedef std::complex GoComplex64;\ntypedef std::complex GoComplex128;\n#elif !defined(__cplusplus) || _MSVC_LANG <= 201402L\n#include \ntypedef _Fcomplex GoComplex64;\ntypedef _Dcomplex GoComplex128;\n#else\n#include \ntypedef std::complex GoComplex64;\ntypedef std::complex GoComplex128;\n#endif" + HEADER_CONTENT + "${HEADER_CONTENT}" +) + +# Write the patched header back +file(WRITE "${HEADER_FILE}" "${HEADER_CONTENT}") + +message(STATUS "Successfully patched ${HEADER_FILE}")