@@ -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 ()
10098else ()
@@ -109,11 +107,15 @@ if(NOT LLVM_FOUND)
109107 message (FATAL_ERROR "LLVM not found! Please install LLVM and set LLVM_DIR." )
110108 endif ()
111109else ()
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 )
117119endif ()
118120
119121# --- LibFFI Configuration ---
@@ -139,10 +141,6 @@ else()
139141endif ()
140142
141143if (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)
164162include_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
173179list (REMOVE_ITEM LIB_SOURCES
@@ -185,6 +191,10 @@ add_library(prox_core STATIC ${LIB_SOURCES})
185191target_include_directories (prox_core PUBLIC include src )
186192
187193if (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} )
189199endif ()
190200if (LIBFFI_FOUND)
0 commit comments