Skip to content

Commit

Permalink
Merge pull request #9676 from NREL/9303_Fortran_UtilitiesLinking
Browse files Browse the repository at this point in the history
#9303 - Effectively static link fortran utilities (and make them work on M1)
  • Loading branch information
Myoldmopar authored Sep 28, 2022
2 parents 04b8489 + 860fd63 commit c249759
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
40 changes: 40 additions & 0 deletions cmake/Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,47 @@ if(APPLE)
if(NOT "Ninja" STREQUAL ${CMAKE_GENERATOR})
target_compile_options(fortran_project_options INTERFACE -cpp)
endif()

# `-static` isn't possible on mac. From gcc man page:
# > This option will not work on Mac OS X unless all libraries (including libgcc.a) have also been compiled with -static.
# > Since neither a static version of libSystem.dylib nor crt0.o are provided, this option is not useful to most people.

# master of gcc has a fix via a new `-static-libquadmath` but it's not even in gcc 12.2.0. So instead we have to do all kinds of shenanigans

enable_language(Fortran) # Needed to populate ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}
# Debug:
# set(Fortran_VERBOSE "-v")
# Find the static libquadmath maually
find_library(static-libquadmath NAMES quadmath.a libquadmath.a REQUIRED PATHS ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES})
message(STATUS "Found static-libquadmath at ${static-libquadmath} by searching in CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES=${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}")
target_compile_options(fortran_project_options INTERFACE
${Fortran_VERBOSE}
)
target_link_options(fortran_project_options INTERFACE
${Fortran_VERBOSE}
-nodefaultlibs
-static-libgfortran
-lgfortran
-static-libgcc
-lgcc
-lemutls_w
${static-libquadmath}
-lSystem
)

message(DEBUG "CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES-${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
# => CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES-gfortran;emutls_w;gcc;quadmath;emutls_w;gcc;gcc
list(REMOVE_DUPLICATES CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES)
list(TRANSFORM CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES REPLACE "quadmath" " ${static-libquadmath}")
message(DEBUG "CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES-${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")

# We unset this so that CMake doesn't try to read -lquadmath etc
unset(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES)

# We could technically just set it to TRUE here. But it shouldn't do anything anyways, and it's a fallback
# set(FORTRAN_STATIC_EXE TRUE)
endif()

elseif(UNIX)
set(FORTRAN_SKIP_RPATH TRUE)
if(CMAKE_Fortran_COMPILER MATCHES "ifort")
Expand Down
3 changes: 2 additions & 1 deletion cmake/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ if(APPLE)

# You need at least one "install(..." command for it to be registered as a component
install(CODE "MESSAGE(\"Creating symlinks.\")" COMPONENT Symlinks)
install(FILES "${PROJECT_SOURCE_DIR}/doc/man/energyplus.1" DESTINATION "./" COMPONENT Symlinks)

# Custom installer icon. Has to be .icns on mac, .ico on windows, not supported on Unix
set(CPACK_IFW_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/release/ep.icns")
Expand Down Expand Up @@ -602,7 +603,7 @@ elseif(UNIX)

# You need at least one "install(..." command for it to be registered as a component
install(CODE "MESSAGE(\"Creating symlinks.\")" COMPONENT Symlinks)
install(FILES doc/man/energyplus.1 DESTINATION "./")
install(FILES "${PROJECT_SOURCE_DIR}/doc/man/energyplus.1" DESTINATION "./" COMPONENT Symlinks)
endif()

# TODO: Unused now
Expand Down
4 changes: 3 additions & 1 deletion cmake/qtifw/install_unix_createsymlinks.qs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function Component()

// man page:
linktarget = "/usr/local/share/man/man1";
component.addElevatedOperation("Execute", "ln", "-sf", "@TargetDir@/energyplus.1", linktarget,
component.addElevatedOperation("Execute", "mkdir", "-p", linktarget);

component.addElevatedOperation("Execute", "ln", "-sf", "@TargetDir@/energyplus.1", linktarget + "/energyplus.1",
"UNDOEXECUTE", "rm", linktarget + "/energyplus.1");

}
Expand Down

5 comments on commit c249759

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (2597 of 2597 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-MacOS-10.17-clang-13.0.0: OK (2576 of 2576 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1809 of 1809 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (770 of 770 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2575 of 2575 tests passed, 0 test warnings)

Build Badge Test Badge

Please sign in to comment.