Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support in CMakeLists.txt for lfortran #260

Open
dhermes opened this issue May 15, 2021 · 3 comments
Open

Add support in CMakeLists.txt for lfortran #260

dhermes opened this issue May 15, 2021 · 3 comments

Comments

@dhermes
Copy link
Owner

dhermes commented May 15, 2021

@dhermes
Copy link
Owner Author

dhermes commented May 15, 2021

To build:

HERE="$(git rev-parse --show-toplevel)"
SRC_DIR="${HERE}/src/fortran"
BUILD_DIR="${HERE}/build-lfortran/build"
INSTALL_PREFIX="${HERE}/build-lfortran/usr"
LFORTRAN_BIN="$(pyenv which lfortran)"
echo "LFORTRAN_BIN=${LFORTRAN_BIN}"
rm -fr "${HERE}/build-lfortran"
mkdir -p "${BUILD_DIR}"
cmake \
    -DCMAKE_Fortran_COMPILER="${LFORTRAN_BIN}" \
    -DCMAKE_Fortran_COMPILER_ID=LFort \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}" \
    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
    -S "${SRC_DIR}" \
    -B "${BUILD_DIR}"

cmake \
    --build "${BUILD_DIR}" \
    --config Debug \
    --target install

cmake -L "${BUILD_DIR}"

Note that -DCMAKE_Fortran_COMPILER_ID=LFort is necessary because of https://gitlab.kitware.com/cmake/cmake/-/issues/17440 / https://gitlab.com/lfortran/lfortran/-/issues/261

@dhermes
Copy link
Owner Author

dhermes commented May 15, 2021

Using this as a starting point:

diff --git a/src/fortran/CMakeLists.txt b/src/fortran/CMakeLists.txt
index c2d5088..fab229b 100644
--- a/src/fortran/CMakeLists.txt
+++ b/src/fortran/CMakeLists.txt
@@ -11,8 +11,8 @@ set(DESCRIPTION "Library for Bezier curves and triangles.")
 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
 option(TARGET_NATIVE_ARCH "Optimize build for host (native) architecture" ON)
 
-if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|Intel)$")
-  message(FATAL_ERROR "gfortran and ifort are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
+if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|Intel|LFort)$")
+  message(FATAL_ERROR "gfortran, ifort and lfortran are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
 endif()
 
 if(NOT CMAKE_BUILD_TYPE)
@@ -77,7 +77,7 @@ endif()
 
 target_include_directories(bezier PUBLIC $<INSTALL_INTERFACE:include>)
 
-if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
+if(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|LFort)$")
   # ``-Wextra`` includes ``no-compare-reals``, but we have comparisons like
   # ``value == 0.0_dp``.
   target_compile_options(
@@ -109,7 +109,7 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
     target_compile_options(quadpack PUBLIC -fast)
   endif()
 else()
-  message(FATAL_ERROR "gfortran and ifort are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
+  message(FATAL_ERROR "gfortran, ifort and lfortran are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
 endif()
 
 include(GNUInstallDirs)
diff --git a/src/fortran/quadpack/CMakeLists.txt b/src/fortran/quadpack/CMakeLists.txt
index 02e242e..23e5dec 100644
--- a/src/fortran/quadpack/CMakeLists.txt
+++ b/src/fortran/quadpack/CMakeLists.txt
@@ -5,8 +5,8 @@ project(
   DESCRIPTION "Library for numerical integration of one-dimensional functions."
   LANGUAGES Fortran)
 
-if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|Intel)$")
-  message(FATAL_ERROR "gfortran and lfortran are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
+if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|Intel|LFort)$")
+  message(FATAL_ERROR "gfortran, ifort and lfortran are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
 endif()
 
 if(NOT CMAKE_BUILD_TYPE)
@@ -34,7 +34,7 @@ if(${BUILD_SHARED_LIBS})
   set_target_properties(quadpack PROPERTIES POSITION_INDEPENDENT_CODE ON)
 endif()
 
-if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
+if(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|LFort)$")
   # ``-Wextra`` includes ``no-compare-reals``, but we have comparisons like
   # ``value == 0.0_dp``.
   target_compile_options(
@@ -64,7 +64,7 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
     target_compile_options(quadpack PUBLIC -fast)
   endif()
 else()
-  message(FATAL_ERROR "gfortran and lfortran are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
+  message(FATAL_ERROR "gfortran, ifort and lfortran are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})")
 endif()
 
 # Restore all Fortran flags.

As mentioned compiling F77 / .f files fails. Also some of the gfortran flags don't carry over so I'll need to refine this a bit more.

@dhermes
Copy link
Owner Author

dhermes commented Aug 2, 2023

norm2() also a problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant