Skip to content

Commit

Permalink
fix: LLVM setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kha committed Jun 18, 2021
1 parent 720954d commit b3535e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ if(LLVM)
include_directories(${LLVM_INCLUDE_DIRS})
set(LEAN_EXTRA_CXX_FLAGS "${LEAN_EXTRA_CXX_FLAGS} -D LEAN_LLVM")
set(LEANC_EXTRA_FLAGS "${LEANC_EXTRA_FLAGS} -D LEAN_LLVM")

# Find the libraries that correspond to the LLVM components
# that we wish to use and define llvm_libs
llvm_map_components_to_libnames(llvm_libs nativecodegen)
else()
#message(WARNING "Disabling LLVM support. JIT compilation will not be available")
endif()
Expand Down Expand Up @@ -471,9 +467,6 @@ if(PREV_STAGE)
endif()

target_link_libraries(leancpp INTERFACE ${EXTRA_LIBS})
if(LLVM)
target_link_libraries(leancpp INTERFACE ${llvm_libs})
endif()

configure_file("${LEAN_SOURCE_DIR}/bin/leanc.in" "${CMAKE_BINARY_DIR}/bin/leanc" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/bin/leanc"
Expand Down
26 changes: 25 additions & 1 deletion src/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
add_library(shell OBJECT lean.cpp)

if(LLVM)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LLVM_SYSTEM_LIBS "-lz -ltinfo")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
# macOS doesn't have -Bstatic, so let cmake search for the libraries
find_library(LIBZ NAMES z REQUIRED)
find_library(NCURSES NAMES ncurses REQUIRED)
set(LLVM_SYSTEM_LIBS "${LIBZ} ${NCURSES}")
else()
set(LLVM_SYSTEM_LIBS "-lz")
endif()
if(${STATIC} AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin"))
set(LEAN_EXE_LINKER_FLAGS "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --link-static --ldflags --libs nativecodegen` -Wl,-Bstatic ${LLVM_SYSTEM_LIBS} -Wl,-Bdynamic")
else()
set(LEAN_EXE_LINKER_FLAGS "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --ldflags --libs nativecodegen` ${LLVM_SYSTEM_LIBS}")
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(LEAN_EXE_LINKER_FLAGS "${LEAN_EXE_LINKER_FLAGS} -lole32 -luuid")
endif()
else()
set(LEAN_EXE_LINKER_FLAGS "")
endif()

string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/lean${CMAKE_EXECUTABLE_SUFFIX}
COMMAND sh -c "LEANC_GMP=${GMP_LIBRARIES} LEAN_CXX='${CMAKE_CXX_COMPILER_LAUNCHER} ${CMAKE_CXX_COMPILER}' ${CMAKE_BINARY_DIR}/bin/leanc ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} $<TARGET_OBJECTS:shell> -o ${CMAKE_BINARY_DIR}/bin/lean${CMAKE_EXECUTABLE_SUFFIX}"
COMMAND sh -c "LEANC_GMP=${GMP_LIBRARIES} LEAN_CXX='${CMAKE_CXX_COMPILER_LAUNCHER} ${CMAKE_CXX_COMPILER}' ${CMAKE_BINARY_DIR}/bin/leanc $<TARGET_OBJECTS:shell> ${CMAKE_EXE_LINKER_FLAGS} ${LEAN_EXE_LINKER_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} -o ${CMAKE_BINARY_DIR}/bin/lean${CMAKE_EXECUTABLE_SUFFIX}"
VERBATIM
DEPENDS Init Std Lean leancpp shell)

add_custom_target(lean ALL
Expand Down

0 comments on commit b3535e4

Please sign in to comment.