CMake/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt
Saurabh Kumar daf6cc89ee LFortran: Remove hard-coded --generate-object-code flag
This was added in commit 98d0f918ba (LFortran: Add support for this
compiler, 2024-01-25, v3.31.0-rc1~303^2~2) because it is needed for
cases covered by CMake's Fortran tests.  However, it does not work
with Fortran modules and breaks lfortran's own `examples/project1`.
Move the flag to the test cases that need it, just as the original
commit did with `--implicit-interface`.

Fixes: #26597
Co-authored-by: Brad King <brad.king@kitware.com>
2025-01-09 14:49:39 -05:00

56 lines
1.9 KiB
CMake

cmake_minimum_required(VERSION 3.10)
project(FortranHello Fortran C)
# add a function to test for -lsunquad on sunpro sun systems.
function(test_sunquad result)
set( TEST_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/sunq")
file(WRITE "${TEST_DIR}/testsunq.f" "
PROGRAM TEST
END
")
file(WRITE ${TEST_DIR}/CMakeLists.txt "
project(sunq Fortran)
add_library(sunq SHARED testsunq.f)
target_link_libraries(sunq sunquad)
")
message(STATUS "looking for -lsunquad")
try_compile(RESULT "${TEST_DIR}" "${TEST_DIR}" sunq OUTPUT_VARIABLE OUT)
if("${RESULT}")
message(STATUS "-lsunquad found")
else()
message(STATUS "-lsunquad not found")
endif()
message(STATUS
"looking for sunquad:\nRESULT=[${RESULT}]\nOUTPUT=[\n${OUT}\n]")
set(${result} "${RESULT}" PARENT_SCOPE)
endfunction()
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LFortran")
add_compile_options(--implicit-interface --generate-object-code)
endif()
# check for the fortran c interface mangling
include(FortranCInterface)
FortranCInterface_HEADER(HelloWorldFCMangle.h
MACRO_NAMESPACE "FC_"
SYMBOL_NAMESPACE "FC_"
SYMBOLS hello world)
add_library(hello SHARED hello.f)
add_library(world SHARED world.f)
target_link_libraries(hello PRIVATE world)
if(CMAKE_Fortran_COMPILER_ID MATCHES SunPro)
target_link_libraries(hello PRIVATE fsu)
if(CMAKE_Fortran_PLATFORM_ID MATCHES SunOS)
target_link_libraries(hello PRIVATE sunmath m)
test_sunquad(CMAKE_HAS_SUNQUAD)
if(CMAKE_HAS_SUNQUAD)
target_link_libraries(hello PRIVATE sunquad)
endif()
endif()
elseif(CMAKE_Fortran_COMPILER_ID MATCHES Fujitsu)
# Fujitsu Fortran doesn't automatically link its runtime libraries into
# SOs
target_link_libraries(world PRIVATE fj90i fj90f fjsrcinfo)
target_link_libraries(hello PRIVATE fj90i fj90f fjsrcinfo)
endif()