Skip to content
Draft
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
3 changes: 3 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions common/patch_liboci_header.cmake
Original file line number Diff line number Diff line change
@@ -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 <complex.h>\ntypedef _Fcomplex GoComplex64;\ntypedef _Dcomplex GoComplex128;\n#else\n#include <complex>\ntypedef std::complex<float> GoComplex64;\ntypedef std::complex<double> GoComplex128;\n#endif"
"#ifdef _MSC_VER\n#if defined(__clang__) || (defined(__cplusplus) && _MSVC_LANG > 201402L)\n#include <complex>\ntypedef std::complex<float> GoComplex64;\ntypedef std::complex<double> GoComplex128;\n#elif !defined(__cplusplus) || _MSVC_LANG <= 201402L\n#include <complex.h>\ntypedef _Fcomplex GoComplex64;\ntypedef _Dcomplex GoComplex128;\n#else\n#include <complex>\ntypedef std::complex<float> GoComplex64;\ntypedef std::complex<double> GoComplex128;\n#endif"
HEADER_CONTENT
"${HEADER_CONTENT}"
)

# Write the patched header back
file(WRITE "${HEADER_FILE}" "${HEADER_CONTENT}")

message(STATUS "Successfully patched ${HEADER_FILE}")