TriBITSPub / TriBITS

TriBITS: Tribal Build, Integrate, and Test System,
http://tribits.org
Other
36 stars 45 forks source link

Get TriBITS to automatically install generated Fortran module (*.mod) files by default #241

Open bartlettroscoe opened 7 years ago

bartlettroscoe commented 7 years ago

Description

Currently, a TriBITS package will not install Fortran generated *.mod module files when it installs the Fortran libraries that have modules. This makes Fortran packages that use modules basically broken when installed.

This Issue is to see about updating TriBITS to automatically install the Fortran-generated "*.mod" module files.

Possible implementations:

One approach for doing that is explained in:

that is advocated by a Kitware CMake expert (Brad King). Basically, the approach is to run the commands:

set(CMAKE_Fortran_MODULE_DIRECTORY $(CMAKE_BINARY_DIR}/mod_files)
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ DESTINATION include)

For TriBITS, it might make sense to set the CMAKE_Fortran_MODULE_DIRECTORY variable independently for each TriBITS package. The problem is where to put the module files? Also, I think that we would need to make sure and add an INCLUDE_DIRECTORIES() command for that directory. It would be nice to set CMAKE_Fortran_MODULE_DIRECTORY to the same directory where all of the object files are generated. To make this explicit, it might be good for each TriBITS package and subpackage to have to call a command like:

TRIBITS_SET_FORTRAN_MODULEs_DIRECTORY_AND_INSTALL(${CMAKE_CURRENT_BINARY_DIR})

somewhere in each TriBITS package. That would run three commands:

FUNCTION(TRIBITS_SET_FORTRAN_MODULE_DIRECTORY_AND_INSTALL  MODULE_FILES_DIR)
  SET(CMAKE_Fortran_MODULE_DIRECTORY ${MODULE_FILES_DIR}
  INCLUDE_DIRECTORIES(${MODULE_FILES_DIR})
  INSTALL(DIRECTORY ${MODULE_FILES_DIR}
    DESTINATION ???
    FILES_MATCHING PATTERN "*.mod")
END_FUNCTION()

Another approach is to just add that above INSTALL() command to TRIBITS_ADD_LIBRARY(). It seems that CMake runs the Fortran compiler in the same CMAKE_CURRENT_BINARY_DIR where TRIBITS_ADD_LIBRARY() is called, so if Fortran is enabled, that function might just call:

  INSTALL(DIRECTORY ${CURRENT_CMAKE_BINARY_DIR}
    DESTINATION ???
    FILES_MATCHING PATTERN "*.mod")

but only if header files are requested to be installed. That would be seamless and should do the right thing.

bartlettroscoe commented 7 years ago

The hard part for this will be writing portable automated tests. The most portable test might be to just build and install the TribitsExampleProject package MixedLang and then create a downstream TriBITS project/pacakge with Fortran that reads in MixedLangConfig.cmake and then uses some Fortran modules. Just a simple test package that duplicates the MixedLang tests might do the trick.