Skip to content

Commit b3d25dc

Browse files
committed
Fix LLVM build on Windows: conditional compilation and improved detection
1 parent e442db3 commit b3d25dc

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ if(WIN32)
9393

9494
set(LLVM_FOUND TRUE)
9595
set(LLVM_VERSION ${LLVM_PACKAGE_VERSION})
96-
# Note: llvm_map_components_to_libnames will still fail if not found.
97-
# We'll handle that below by providing a simplified list if needed.
9896
endif()
9997
endif()
10098
else()
@@ -109,11 +107,15 @@ if(NOT LLVM_FOUND)
109107
message(FATAL_ERROR "LLVM not found! Please install LLVM and set LLVM_DIR.")
110108
endif()
111109
else()
110+
# Ensure LLVM_INCLUDE_DIRS is set (sometimes it's LLVM_INCLUDE_DIR)
111+
if(NOT LLVM_INCLUDE_DIRS AND LLVM_INCLUDE_DIR)
112+
set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIR})
113+
endif()
114+
112115
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
113116
message(STATUS "LLVM Include Dirs: ${LLVM_INCLUDE_DIRS}")
114117
message(STATUS "LLVM Library Dirs: ${LLVM_LIBRARY_DIRS}")
115118
message(STATUS "LLVM Definitions: ${LLVM_DEFINITIONS}")
116-
add_definitions(-DUSE_LLVM_BACKEND)
117119
endif()
118120

119121
# --- LibFFI Configuration ---
@@ -139,10 +141,6 @@ else()
139141
endif()
140142

141143
if(LLVM_FOUND)
142-
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
143-
add_definitions(${LLVM_DEFINITIONS})
144-
link_directories(${LLVM_LIBRARY_DIRS})
145-
146144
if(COMMAND llvm_map_components_to_libnames)
147145
llvm_map_components_to_libnames(llvm_libs core support executionengine native ipo analysis transformutils bitwriter)
148146
elseif(LLVM_CONFIG_EXE)
@@ -164,10 +162,18 @@ include_directories(include)
164162
include_directories(src)
165163

166164
# List of all C/C++ source files for the library, excluding those with a 'main' function
167-
file(GLOB_RECURSE LIB_SOURCES
168-
"src/*.c"
169-
"src/*.cpp"
170-
)
165+
file(GLOB_RECURSE LIB_SOURCES "src/*.c")
166+
file(GLOB_RECURSE LIB_SOURCES_CPP "src/*.cpp")
167+
168+
# Handle LLVM Backend Source: Only include if LLVM was found
169+
if(LLVM_FOUND)
170+
message(STATUS "LLVM backend enabled - including backend_llvm.cpp")
171+
else()
172+
message(STATUS "LLVM backend disabled - excluding backend_llvm.cpp")
173+
list(REMOVE_ITEM LIB_SOURCES_CPP "${CMAKE_CURRENT_SOURCE_DIR}/src/compiler/backend_llvm.cpp")
174+
endif()
175+
176+
list(APPEND LIB_SOURCES ${LIB_SOURCES_CPP})
171177

172178
# Explicitly exclude files that contain a 'main()' function or are specific VM implementations
173179
list(REMOVE_ITEM LIB_SOURCES
@@ -185,6 +191,10 @@ add_library(prox_core STATIC ${LIB_SOURCES})
185191
target_include_directories(prox_core PUBLIC include src)
186192

187193
if (LLVM_FOUND)
194+
target_include_directories(prox_core PRIVATE ${LLVM_INCLUDE_DIRS})
195+
target_compile_definitions(prox_core PRIVATE USE_LLVM_BACKEND)
196+
# Apply LLVM compile definitions globally as some headers might need them
197+
add_definitions(${LLVM_DEFINITIONS})
188198
target_link_libraries(prox_core PUBLIC ${llvm_libs})
189199
endif()
190200
if (LIBFFI_FOUND)

src/compiler/backend_llvm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifdef USE_LLVM_BACKEND
2+
13
#include <llvm/IR/IRBuilder.h>
24
#include <llvm/IR/LLVMContext.h>
35
#include <llvm/IR/Module.h>
@@ -11,6 +13,8 @@
1113
#include "../../include/backend_llvm.h"
1214
#include "../../include/object.h"
1315

16+
// ... [rest of the file as before]
17+
1418
// Do NOT use 'using namespace llvm;' due to clash with our 'Value' type.
1519

1620
class LLVMEmitter {
@@ -527,3 +531,4 @@ extern "C" void emitLLVM(IRModule* module) {
527531
emitter.emitModule(module);
528532
}
529533

534+
#endif // USE_LLVM_BACKEND

tmp_closes.txt

-11 KB
Binary file not shown.

tmp_opens.txt

-25.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)