2013-12-29 06:27:36 +00:00
|
|
|
# This directory contains Lean builtin libraries and Lua scripts
|
|
|
|
# needed to run Lean. The builtin Lean libraries are compiled
|
|
|
|
# using ${LEAN_BINARY_DIR}/shell/lean
|
|
|
|
# The library builtin is not a real library.
|
|
|
|
# It is just a hack to force CMake to consider our custom targets
|
2013-12-29 06:06:11 +00:00
|
|
|
add_library(builtin builtin.cpp)
|
|
|
|
|
2013-12-29 06:27:36 +00:00
|
|
|
# We copy files to the shell directory, to make sure we can test lean
|
|
|
|
# without installing it.
|
|
|
|
set(SHELL_DIR ${LEAN_BINARY_DIR}/shell)
|
|
|
|
|
2013-12-29 19:19:17 +00:00
|
|
|
file(GLOB LEANLIB "*.lua")
|
|
|
|
FOREACH(FILE ${LEANLIB})
|
|
|
|
get_filename_component(FNAME ${FILE} NAME)
|
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FNAME}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${FILE} ${CMAKE_CURRENT_BINARY_DIR}/${FNAME}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${FILE} ${SHELL_DIR}/${FNAME}
|
|
|
|
DEPENDS ${FILE})
|
|
|
|
add_custom_target("${FNAME}_builtin" DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FNAME})
|
|
|
|
add_dependencies(builtin "${FNAME}_builtin")
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} DESTINATION library)
|
|
|
|
ENDFOREACH(FILE)
|
|
|
|
|
2013-12-29 19:58:55 +00:00
|
|
|
# The following command invokes the lean binary.
|
|
|
|
# So, it CANNOT be executed if we are cross-compiling.
|
2014-01-31 07:15:44 +00:00
|
|
|
function(add_theory_core FILE ARG)
|
|
|
|
set(EXTRA_DEPS ${ARGN})
|
2013-12-29 06:06:11 +00:00
|
|
|
get_filename_component(BASENAME ${FILE} NAME_WE)
|
|
|
|
set(FNAME "${BASENAME}.olean")
|
2013-12-29 06:27:36 +00:00
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FNAME}
|
2014-01-10 18:58:35 +00:00
|
|
|
COMMAND ${SHELL_DIR}/lean.sh ${ARG} -q -o ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
|
2013-12-29 06:27:36 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} ${SHELL_DIR}/${FNAME}
|
2013-12-30 21:46:39 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} ${CMAKE_CURRENT_SOURCE_DIR}/obj/${FNAME}
|
2014-01-11 03:06:15 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} lean_sh ${EXTRA_DEPS})
|
2013-12-30 20:40:42 +00:00
|
|
|
add_custom_target("${BASENAME}_builtin" DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} ${EXTRA_DEPS})
|
2013-12-30 11:29:20 +00:00
|
|
|
add_dependencies(builtin ${BASENAME}_builtin)
|
2013-12-29 06:27:36 +00:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} DESTINATION library)
|
2014-01-07 22:34:21 +00:00
|
|
|
add_test("${BASENAME}_builtin_test" ${SHELL_DIR}/lean -o ${CMAKE_CURRENT_BINARY_DIR}/${FNAME}_test ${ARG} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
|
2013-12-29 10:44:49 +00:00
|
|
|
endfunction()
|
|
|
|
|
2013-12-29 19:58:55 +00:00
|
|
|
# When cross compiling, we cannot execute lean during the build.
|
|
|
|
# So, we just copy the precompiled .olean files.
|
|
|
|
function(copy_olean FILE)
|
|
|
|
get_filename_component(BASENAME ${FILE} NAME_WE)
|
|
|
|
set(FNAME "${BASENAME}.olean")
|
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FNAME}
|
2013-12-30 21:46:39 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/obj/${FNAME} ${CMAKE_CURRENT_BINARY_DIR}/${FNAME}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/obj/${FNAME} ${SHELL_DIR}/${FNAME}
|
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/obj/${FNAME})
|
2013-12-30 11:29:20 +00:00
|
|
|
add_custom_target("${BASENAME}_builtin" DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FNAME})
|
|
|
|
add_dependencies(builtin ${BASENAME}_builtin)
|
2013-12-29 19:58:55 +00:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} DESTINATION library)
|
|
|
|
endfunction()
|
|
|
|
|
2014-01-31 07:15:44 +00:00
|
|
|
function(add_kernel_theory FILE)
|
2013-12-29 19:58:55 +00:00
|
|
|
if(CMAKE_CROSSCOMPILING)
|
|
|
|
copy_olean(${FILE})
|
|
|
|
else()
|
2014-01-31 07:15:44 +00:00
|
|
|
add_theory_core(${FILE} "-n" ${ARGN})
|
2013-12-29 19:58:55 +00:00
|
|
|
endif()
|
2013-12-29 10:44:49 +00:00
|
|
|
endfunction()
|
|
|
|
|
2014-01-31 07:15:44 +00:00
|
|
|
function(add_theory FILE)
|
2013-12-29 19:58:55 +00:00
|
|
|
if(CMAKE_CROSSCOMPILING)
|
|
|
|
copy_olean(${FILE})
|
|
|
|
else()
|
2014-01-31 07:15:44 +00:00
|
|
|
add_theory_core(${FILE} "" ${ARGN})
|
2013-12-29 19:58:55 +00:00
|
|
|
endif()
|
2013-12-29 10:44:49 +00:00
|
|
|
endfunction()
|
|
|
|
|
2014-01-10 02:09:53 +00:00
|
|
|
# The following command invokes the lean binary to update .cpp/.h interface files
|
|
|
|
# associated with a .lean file.
|
|
|
|
function(update_interface FILE DEST ARG)
|
|
|
|
get_filename_component(BASENAME ${FILE} NAME_WE)
|
|
|
|
set(CPPFILE "${LEAN_SOURCE_DIR}/${DEST}/${BASENAME}_decls.cpp")
|
|
|
|
set(HFILE "${LEAN_SOURCE_DIR}/${DEST}/${BASENAME}_decls.h")
|
2014-01-10 18:58:35 +00:00
|
|
|
# We also create a fake .h file, it serves as the output for the following
|
|
|
|
# custom command. We don't use CPPFILE and HFILE as the output to avoid
|
|
|
|
# a cyclic dependency.
|
|
|
|
set(HFILE_fake "${LEAN_BINARY_DIR}/${DEST}/${BASENAME}_fake.h")
|
|
|
|
add_custom_command(OUTPUT ${HFILE_fake}
|
|
|
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lean2cpp.sh "${SHELL_DIR}/lean.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${FILE}" "${CPPFILE}" "${ARG}$"
|
|
|
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lean2h.sh "${SHELL_DIR}/lean.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${FILE}" "${HFILE}" "${ARG}$"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${HFILE} ${HFILE_fake}
|
2014-01-11 03:06:15 +00:00
|
|
|
DEPENDS ${FILE} lean_sh)
|
2014-01-10 18:58:35 +00:00
|
|
|
add_custom_target("${BASENAME}_decls" DEPENDS ${HFILE_fake})
|
2014-01-10 02:09:53 +00:00
|
|
|
add_dependencies(builtin ${BASENAME}_decls)
|
|
|
|
endfunction()
|
|
|
|
|
2014-01-31 07:15:44 +00:00
|
|
|
add_kernel_theory("kernel.lean" ${CMAKE_CURRENT_BINARY_DIR}/macros.lua ${CMAKE_CURRENT_BINARY_DIR}/tactic.lua)
|
|
|
|
add_kernel_theory("Nat.lean" ${CMAKE_CURRENT_BINARY_DIR}/kernel.olean)
|
2013-12-30 20:40:42 +00:00
|
|
|
|
2014-01-31 03:11:58 +00:00
|
|
|
add_theory("Int.lean" "${CMAKE_CURRENT_BINARY_DIR}/Nat.olean")
|
2014-01-09 22:06:23 +00:00
|
|
|
add_theory("Real.lean" "${CMAKE_CURRENT_BINARY_DIR}/Int.olean")
|
|
|
|
add_theory("specialfn.lean" "${CMAKE_CURRENT_BINARY_DIR}/Real.olean")
|
2014-02-06 01:33:06 +00:00
|
|
|
add_theory("subtype.lean" "${CMAKE_CURRENT_BINARY_DIR}/kernel.olean")
|
|
|
|
add_theory("optional.lean" "${CMAKE_CURRENT_BINARY_DIR}/subtype.olean")
|
2014-02-06 07:04:44 +00:00
|
|
|
add_theory("sum.lean" "${CMAKE_CURRENT_BINARY_DIR}/optional.olean")
|
2014-01-10 02:09:53 +00:00
|
|
|
|
2014-01-15 00:10:49 +00:00
|
|
|
update_interface("kernel.olean" "kernel" "-n")
|
|
|
|
update_interface("Nat.olean" "library/arith" "-n")
|
|
|
|
update_interface("Int.olean" "library/arith" "")
|
|
|
|
update_interface("Real.olean" "library/arith" "")
|