@@ -25,7 +25,10 @@ endif()
2525# We are using Fortran driver to build this library with fresh compiler
2626# components, so point its binary directory to the build directory to pick up
2727# flang* executables
28- SET (CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS} -no-flang-libs" )
28+ SET (CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS} " )
29+
30+ # flang runtime libraries are being built here. Don't link them
31+ SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -no-flang-libs" )
2932
3033SET (FTN_INTRINSICS
3134 abort3f.c
@@ -270,7 +273,7 @@ SET(FTN_INTRINSICS
270273 wait3f.c
271274 )
272275
273- SET (FTN_SUPPORT
276+ SET (FTN_SUPPORT_COMMON
274277 bcopy.c
275278 bcopys.c
276279 buffer.c
@@ -335,12 +338,9 @@ SET(FTN_SUPPORT
335338 descIntrins.c
336339 descFioUtil.c
337340 descRW.c
338- ieee_arithmetic.F95
339- ieee_exceptions.F95
340341 ieee_features.F95
341342 initpar.c
342343 inquire.c
343- iso_c_bind.F95
344344 iso_fortran_env.f90
345345 ldread.c
346346 ldwrite.c
@@ -477,18 +477,32 @@ SET(FTN_SUPPORT
477477 xfer_rpm1.c
478478 )
479479
480- add_library (iso_c_bind OBJECT
481- iso_c_bind .F95
482- )
480+ foreach (FTN_FILE ieee_arithmetic ieee_exceptions iso_c_bind)
481+ configure_file ( ${FTN_FILE} .F95 ${FTN_FILE} _static.F95 COPYONLY )
482+ endforeach ( )
483483
484- add_library (ieee_arithmetic OBJECT
484+ SET (FTN_SUPPORT_SHARED
485485 ieee_arithmetic.F95
486486 ieee_exceptions.F95
487+ iso_c_bind.F95
488+ )
489+
490+ SET (FTN_SUPPORT_STATIC
491+ ieee_arithmetic_static.F95
492+ ieee_exceptions_static.F95
493+ iso_c_bind_static.F95
494+ )
495+
496+ SET (FTN_SUPPORT
497+ ${FTN_SUPPORT_STATIC}
498+ ${FTN_SUPPORT_SHARED}
499+ ${FTN_SUPPORT_COMMON}
487500)
488501
489502add_flang_library(flang_static
490503 ${FTN_INTRINSICS}
491- ${FTN_SUPPORT}
504+ ${FTN_SUPPORT_COMMON}
505+ ${FTN_SUPPORT_STATIC}
492506 ${SHARED_SOURCES}
493507 )
494508
@@ -498,21 +512,81 @@ else()
498512 set_property (TARGET flang_static PROPERTY OUTPUT_NAME flang)
499513endif ()
500514
515+ set_target_properties (flang_static PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_STATIC} )
516+
517+ if (NOT "${CMAKE_GENERATOR} " STREQUAL "Ninja" )
518+ # State the module that the source is producing
519+ set_source_files_properties (
520+ iso_c_bind_static.F95
521+ PROPERTIES
522+ OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_STATIC} /iso_c_binding.mod
523+ )
524+
525+ # State a dependency on the module
526+ set_source_files_properties (
527+ ieee_arithmetic_static.F95
528+ ieee_exceptions_static.F95
529+ PROPERTIES
530+ OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_STATIC} /iso_c_binding.mod
531+ )
532+ else ()
533+ add_library (iso_c_bind OBJECT
534+ iso_c_bind.F95
535+ )
536+ add_library (ieee_arithmetic OBJECT
537+ ieee_arithmetic.F95
538+ ieee_exceptions.F95
539+ )
540+ add_dependencies (iso_c_bind
541+ flang1
542+ flang2
543+ )
544+ add_dependencies (ieee_arithmetic
545+ iso_c_bind
546+ )
547+ add_dependencies (flang_static
548+ ieee_arithmetic
549+ )
550+ endif ()
551+
501552set (SHARED_LIBRARY TRUE )
553+
502554add_flang_library(flang_shared
503555 ${FTN_INTRINSICS}
504- ${FTN_SUPPORT}
556+ ${FTN_SUPPORT_COMMON}
557+ ${FTN_SUPPORT_SHARED}
505558 ${SHARED_SOURCES}
506559 )
507560set_property (TARGET flang_shared PROPERTY OUTPUT_NAME flang)
508561target_link_libraries (flang_shared flangrti_shared)
509562# Resolve symbols against libm and librt
510563if (NOT MSVC )
511- target_link_libraries (flang_shared rt m)
564+ target_link_libraries (flang_shared rt m)
512565else ()
513566 set_target_properties (flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE )
514567endif ()
568+ set_target_properties (flang_shared PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_SHARED} )
569+
570+ if (NOT "${CMAKE_GENERATOR} " STREQUAL "Ninja" )
571+ # State the module that the source is producing
572+ set_source_files_properties (
573+ iso_c_bind.F95
574+ PROPERTIES
575+ OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_SHARED} /iso_c_binding.mod
576+ )
515577
578+ # State a dependency on the module
579+ set_source_files_properties (
580+ ieee_arithmetic.F95
581+ ieee_exceptions.F95
582+ PROPERTIES
583+ OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_SHARED} /iso_c_binding.mod
584+ )
585+ else ()
586+ add_dependencies (flang_shared
587+ ieee_arithmetic
588+ )
589+ endif ()
516590set (SHARED_LIBRARY FALSE )
517591
518592set_property (
@@ -576,25 +650,14 @@ target_include_directories(flang_shared
576650add_dependencies (flang_static
577651 flang1
578652 flang2
579- ieee_arithmetic
580653 )
581654
582655# Make sure the compiler is built before we bootstrap
583656add_dependencies (flang_shared
584657 flang1
585658 flang2
586- ieee_arithmetic
587659 )
588660
589- add_dependencies (iso_c_bind
590- flang1
591- flang2
592- )
593-
594- add_dependencies (ieee_arithmetic
595- iso_c_bind
596- )
597-
598661if (NOT MSVC )
599662 target_compile_options (flang_static PRIVATE -fPIC)
600663 target_compile_options (flang_shared PRIVATE -fPIC)
0 commit comments