Skip to content

Commit

Permalink
Make building of the runtime library optional
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Aug 16, 2021
1 parent 462d705 commit f3368ac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ set(LFORTRAN_STATIC_BIN no CACHE BOOL "Build LFortran as a static binary")
set(WITH_LFORTRAN_BINARY_MODFILES YES
CACHE BOOL "Use binary modfiles")

set(WITH_RUNTIME_LIBRARY YES
CACHE BOOL "Compile and install the runtime library")

# Find ZLIB with our custom finder before including LLVM since the finder for LLVM
# might search for ZLIB again and find the shared libraries instead of the static ones
find_package(StaticZLIB REQUIRED)
Expand Down Expand Up @@ -231,6 +234,7 @@ message("WITH_XEUS: ${WITH_XEUS}")
message("WITH_JSON: ${WITH_JSON}")
message("WITH_FMT: ${WITH_FMT}")
message("WITH_LFORTRAN_BINARY_MODFILES: ${WITH_LFORTRAN_BINARY_MODFILES}")
message("WITH_RUNTIME_LIBRARY: ${WITH_RUNTIME_LIBRARY}")


add_subdirectory(src)
87 changes: 45 additions & 42 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,53 +37,56 @@ if (WITH_STACKTRACE AND APPLE AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
endif()
endif()

add_custom_command(
TARGET lfortran
POST_BUILD
COMMAND cmake -E remove -f ${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_*.mod
)

macro(LFORTRAN_COMPILE_RUNTIME name dir)
if (WITH_RUNTIME_LIBRARY)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../runtime/${name}.mod
COMMAND lfortran
ARGS --backend=cpp -c ${CMAKE_CURRENT_SOURCE_DIR}/../runtime/${dir}/${name}.f90 -o ${name}.o
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../runtime
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../runtime/${dir}/${name}.f90 ${ARGN}
COMMENT "LFortran Compiling ${dir}/${name}.f90")
endmacro(LFORTRAN_COMPILE_RUNTIME)
TARGET lfortran
POST_BUILD
COMMAND cmake -E remove -f ${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_*.mod
)

LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_array builtin)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_kind pure)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_iso_fortran_env pure)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_iso_c_binding pure)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_math2 pure
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_trig pure
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
)
macro(LFORTRAN_COMPILE_RUNTIME name dir)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../runtime/${name}.mod
COMMAND lfortran
ARGS --backend=cpp -c ${CMAKE_CURRENT_SOURCE_DIR}/../runtime/${dir}/${name}.f90 -o ${name}.o
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../runtime
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../runtime/${dir}/${name}.f90 ${ARGN}
COMMENT "LFortran Compiling ${dir}/${name}.f90")
endmacro(LFORTRAN_COMPILE_RUNTIME)

add_custom_target(lfortran2
ALL
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_array.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_kind.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_c_binding.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_math2.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_trig.mod
)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_array builtin)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_kind pure)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_iso_fortran_env pure)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_iso_c_binding pure)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_math2 pure
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
)
LFORTRAN_COMPILE_RUNTIME(lfortran_intrinsic_trig pure
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_array.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_kind.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_c_binding.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_math2.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_trig.mod
DESTINATION share/lfortran/lib
)
add_custom_target(lfortran2
ALL
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_array.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_kind.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_c_binding.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_math2.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_trig.mod
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_array.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_kind.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_fortran_env.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_iso_c_binding.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_math2.mod
${CMAKE_CURRENT_BINARY_DIR}/../runtime/lfortran_intrinsic_trig.mod
DESTINATION share/lfortran/lib
)
endif()

# Ensure "Release" is not appended to the path on Windows:
# https://stackoverflow.com/a/56201564/479532
Expand Down

0 comments on commit f3368ac

Please sign in to comment.