Commit f2ea4433 authored by Thomas Friedrichsmeier's avatar Thomas Friedrichsmeier Committed by Alexander Semke
Browse files

Allow building R backend with MSVC

parent 250ee36a
Pipeline #243036 passed with stage
in 6 minutes and 8 seconds
......@@ -31,6 +31,13 @@ add_backend(rbackend ${RBackend_SRCS})
set_target_properties( cantor_rbackend PROPERTIES INSTALL_RPATH_USE_LINK_PATH false)
target_link_libraries( cantor_rbackend cantor_help ${R_USED_LIBS} KF5::SyntaxHighlighting)
if(MSVC)
# When compiling with MSVC, we have to create a .lib file for R.dll, first
find_package(Python3 COMPONENTS Interpreter REQUIRED)
add_custom_target(R_lib COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/GenLibFile.py ${R_R_LIBRARY} ${CMAKE_BINARY_DIR} ${CMAKE_SYSTEM_PROCESSOR}
COMMENT "Generate .lib file for R.dll")
add_dependencies(cantor_rbackend R_lib)
endif(MSVC)
if(BUILD_TESTING)
add_executable( testr testr.cpp)
......
import subprocess
import os
import sys
# Generate a .lib file for a given .dll
# This assumed dumpbin and lib to be in the path, which they should be, when compiling with MSVC (and that's what this is needed for)
#
# Usage: python3 GenLibFile.py XYZ.dll output_directory architecture
dllfile = sys.argv[1]
workdir = sys.argv[2]
arch = sys.argv[3]
base = os.path.basename(dllfile).replace(".dll", "")
deffile = base + ".def"
libfile = base + ".lib"
dump = subprocess.check_output(["dumpbin", "/exports", dllfile]).decode("latin1").splitlines()
exports = []
for line in dump:
fields = line.split()
if len(fields) != 4:
continue
exports.append(fields[3])
os.chdir(workdir)
with open(os.path.join(workdir, deffile), "wt+") as outdef:
outdef.write("EXPORTS\n")
outdef.write("\n".join(exports))
subprocess.call(["lib", f"/def:{deffile}", f"/out:{libfile}", f"/machine:{arch}"])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment