Include dirs from dependencies

351 views
Skip to first unread message

Chris....@awe.co.uk

unread,
Mar 13, 2017, 7:51:40 AM3/13/17
to sp...@googlegroups.com

Hi All,

 

We’re currently converting a series of our in-house Fortran libraries to build with Spack, via CMake, and I’m having some issues with finding include directories from dependencies.  So I have a few questions for you –

 

1)  When I create a CMakeLists.txt file (for Library A), assuming that I install the *.mod files to a $<prefix>/include directory, do I need to export this include directory in some way so that Spack can ‘see’ it?

 

2)  Library B then requires access to the *.mod files created in Library A to be able to compile.  In the package.py file, I’ve currently got a depends_on(‘libA’).  Do I need to do something else like create a cmake module so that one can use the find_package command in cmake.  Or does Spack need something else?

 

Thanks,

 

Chris.

 

The information in this email and in any attachment(s) is commercial in confidence. If you are not the named addressee(s) or if you receive this email in error then any distribution, copying or use of this communication or the information in it is strictly prohibited. Please notify us immediately by email at admin.internet(at)awe.co.uk, and then delete this message from your computer. While attachments are virus checked, AWE plc does not accept any liability in respect of any virus which is not detected. AWE Plc Registered in England and Wales Registration No 02763902 AWE, Aldermaston, Reading, RG7 4PR

Elizabeth A. Fischer

unread,
Mar 13, 2017, 11:08:52 AM3/13/17
to Chris....@awe.co.uk, Spack
On Mon, Mar 13, 2017 at 7:51 AM, <Chris....@awe.co.uk> wrote:

Hi All,

 

We’re currently converting a series of our in-house Fortran libraries to build with Spack, via CMake, and I’m having some issues with finding include directories from dependencies.


Can you be more explicit about the troubles?
 

1)  When I create a CMakeLists.txt file (for Library A), assuming that I install the *.mod files to a $<prefix>/include directory, do I need to export this include directory in some way so that Spack can ‘see’ it?


No, nothing special is needed.  In my case, my Library A extends Python; so I have to make sure the $PATH env var is added to the generated module's environment.  I did this with the following in Library A's package:

    def setup_environment(self, spack_env, env):
        """Add <prefix>/bin to the module; this is not the default if we
        extend python."""
        env.prepend_path('PATH', join_path(self.prefix, 'bin'))


See here for tips from the CMakeLists.txt for Library A (my Fortran project providing the .mod files and a shared lib and an executable...)

```
# include containers
include_directories(${PROJECT_SOURCE_DIR}/model/shared)

# include generated rundeck_opts
#include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
include(${CMAKE_CURRENT_BINARY_DIR}/modele_SOURCES.cmake)

# Specify TARGETS. 
add_library(modele SHARED ${modele_SOURCES} ${EVERYTRACE_cf_mpi_REFADDR})
target_link_libraries(modele   ${EXTERNAL_LIBS}  )

# Set RPATH in the installed library
# (although we are unlikely to ever install here)

set_target_properties(modele PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

install(TARGETS modele DESTINATION lib)

# modelE executable
add_executable(modelexe main.F90)

# Set additional link library dependencies
target_link_libraries(modelexe modele ${EXTERNAL_LIBS})

install(TARGETS modelexe DESTINATION bin)

if (INSTALL_MODS)
    install(DIRECTORY ${PROJECT_BINARY_DIR}/model/ DESTINATION include
          FILES_MATCHING PATTERN "*.mod")
endif()
```
 

 

2)  Library B then requires access to the *.mod files created in Library A to be able to compile.  In the package.py file, I’ve currently got a depends_on(‘libA’).  Do I need to do something else?


That is exactly correct for `libraryb/package.py`.

 

Do I need something else... like create a cmake module so that one can use the find_package command in cmake.


That's what I did.  See here for `libraryb/cmake/FindLibraryA.cmake`:

# Input Variables
#    MODELE_ROOT
# Produces:
#    MODELE_LIBRARY
#    MODELE_INCLUDE_DIR


FIND_PATH(MODELE_INCLUDE_DIR diag_zonal.mod
HINTS ${MODELE_ROOT}/include)

FIND_LIBRARY(MODELE_LIBRARY NAMES modele
HINTS ${MODELE_ROOT}/lib)

IF (MODELE_INCLUDE_DIR AND MODELE_LIBRARY)
   SET(MODELE_FOUND TRUE)
ENDIF (MODELE_INCLUDE_DIR AND MODELE_LIBRARY)

IF (MODELE_FOUND)
   IF (NOT MODELE_FIND_QUIETLY)
      MESSAGE(STATUS "Found  xxx MODELE_LIBRARY: ${MODELE_LIBRARY}")
      MESSAGE(STATUS "Found  xxx MODELE_INCLUDE_DIR: ${MODELE_INCLUDE_DIR}")
   ENDIF (NOT MODELE_FIND_QUIETLY)
ELSE (MODELE_FOUND)
   IF (MODELE_FIND_REQUIRED)
      MESSAGE(FATAL_ERROR "Could not find MODELE")
   ENDIF (MODELE_FIND_REQUIRED)
ENDIF (MODELE_FOUND)

 

  Or does Spack need something else?


Nope.  In general, you should set up your CMake in a standard way that can work without Spack.

And... once you're finished converting your stuff to Spack + CMake, you might find that `spack setup` is useful for you while developing those packages (see the docs).

-- Elizabeth

Chris....@awe.co.uk

unread,
Mar 13, 2017, 12:58:16 PM3/13/17
to elizabet...@columbia.edu, sp...@googlegroups.com

Thanks for all of that Elizabeth,

 

I’m now currently in the process of creating some FindLibrary files as recommended – I’m still bit of a newbie to both CMake and Spack.

 

Thanks again,

Regards,

Chris.

--
You received this message because you are subscribed to the Google Groups "Spack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spack+un...@googlegroups.com.
To post to this group, send email to sp...@googlegroups.com.
Visit this group at https://groups.google.com/group/spack.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages