CrayLinuxEnvironment.cmake 4.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# Compute Node Linux doesn't quite work the same as native Linux so all of this
# needs to be custom.  We use the variables defined through Cray's environment
# modules to set up the right paths for things.

set(UNIX 1)

if(DEFINED ENV{CRAYOS_VERSION})
  set(CMAKE_SYSTEM_VERSION "$ENV{CRAYOS_VERSION}")
elseif(DEFINED ENV{XTOS_VERSION})
  set(CMAKE_SYSTEM_VERSION "$ENV{XTOS_VERSION}")
else()
  message(FATAL_ERROR "Neither the CRAYOS_VERSION or XTOS_VERSION environment variables are defined.  This platform file should be used inside the Cray Linux Environment for targeting compute nodes (NIDs)")
endif()
14 15 16 17 18 19

# Guard against multiple messages
if(NOT __CrayLinuxEnvironment_message)
  set(__CrayLinuxEnvironment_message 1)
  message(STATUS "Cray Linux Environment ${CMAKE_SYSTEM_VERSION}")
endif()
20 21 22 23 24 25 26 27 28 29 30

# All cray systems are x86 CPUs and have been for quite some time
# Note: this may need to change in the future with 64-bit ARM
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")

set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
31 32 33 34 35 36 37

# Don't override shared lib support if it's already been set and possibly
# overridden elsewhere by the CrayPrgEnv module
if(NOT CMAKE_FIND_LIBRARY_SUFFIXES)
  set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
  set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

set(CMAKE_DL_LIBS dl)

# Note: Much of this is pulled from UnixPaths.cmake but adjusted to the Cray
# environment accordingly

# Get the install directory of the running cmake to the search directories
# CMAKE_ROOT is CMAKE_INSTALL_PREFIX/share/cmake, so we need to go two levels up
get_filename_component(__cmake_install_dir "${CMAKE_ROOT}" PATH)
get_filename_component(__cmake_install_dir "${__cmake_install_dir}" PATH)

# Note: Some Cray's have the SYSROOT_DIR variable defined, pointing to a copy
# of the NIDs userland.  If so, then we'll use it.  Otherwise, just assume
# the userland from the login node is ok

# List common installation prefixes.  These will be used for all
# search types.
list(APPEND CMAKE_SYSTEM_PREFIX_PATH
  # Standard
  $ENV{SYSROOT_DIR}/usr/local $ENV{SYSROOT_DIR}/usr $ENV{SYSROOT_DIR}/

  # CMake install location
  "${__cmake_install_dir}"
  )
if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
  list(APPEND CMAKE_SYSTEM_PREFIX_PATH
    # Project install destination.
    "${CMAKE_INSTALL_PREFIX}"
  )
  if(CMAKE_STAGING_PREFIX)
    list(APPEND CMAKE_SYSTEM_PREFIX_PATH
      # User-supplied staging prefix.
      "${CMAKE_STAGING_PREFIX}"
    )
  endif()
endif()

list(APPEND CMAKE_SYSTEM_INCLUDE_PATH
  $ENV{SYSROOT_DIR}/usr/include
  $ENV{SYSROOT_DIR}/usr/include/X11
)
list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
  $ENV{SYSROOT_DIR}/usr/local/lib64
  $ENV{SYSROOT_DIR}/usr/lib64
  $ENV{SYSROOT_DIR}/lib64
)
list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
  $ENV{SYSROOT_DIR}/usr/local/lib64
  $ENV{SYSROOT_DIR}/usr/lib64
  $ENV{SYSROOT_DIR}/lib64
)

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
# Compute the intersection of several lists
function(__cray_list_intersect OUTPUT INPUT0)
  if(ARGC EQUAL 2)
    list(APPEND ${OUTPUT} ${${INPUT0}})
  else()
    foreach(I IN LISTS ${INPUT0})
      set(__is_common 1)
      foreach(L IN LISTS ARGN)
        list(FIND ${L} "${I}" __idx)
        if(__idx EQUAL -1)
          set(__is_common 0)
          break()
        endif()
      endforeach()
      if(__is_common)
        list(APPEND ${OUTPUT}  "${I}")
      endif()
    endforeach()
  endif()
  set(${OUTPUT} ${${OUTPUT}} PARENT_SCOPE)
endfunction()
111

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
macro(__list_clean_dupes var)
  if(${var})
    list(REMOVE_DUPLICATES ${var})
  endif()
endmacro()

get_property(__langs GLOBAL PROPERTY ENABLED_LANGUAGES)
set(__cray_inc_path_vars)
set(__cray_lib_path_vars)
foreach(__lang IN LISTS __langs)
  list(APPEND __cray_inc_path_vars CMAKE_${__lang}_IMPLICIT_INCLUDE_DIRECTORIES)
  list(APPEND __cray_lib_path_vars CMAKE_${__lang}_IMPLICIT_LINK_DIRECTORIES)
endforeach()
if(__cray_inc_path_vars)
  __cray_list_intersect(__cray_implicit_include_dirs ${__cray_inc_path_vars})
  if(__cray_implicit_include_dirs)
    list(INSERT CMAKE_SYSTEM_INCLUDE_PATH 0 ${__cray_implicit_include_dirs})
  endif()
130
endif()
131 132 133 134 135
if(__cray_lib_path_vars)
  __cray_list_intersect(__cray_implicit_library_dirs ${__cray_lib_path_vars})
  if(__cray_implicit_library_dirs)
    list(INSERT CMAKE_SYSTEM_LIBRARY_PATH 0 ${__cray_implicit_library_dirs})
  endif()
136
endif()
137 138 139 140 141 142 143
__list_clean_dupes(CMAKE_SYSTEM_PREFIX_PATH)
__list_clean_dupes(CMAKE_SYSTEM_INCLUDE_PATH)
__list_clean_dupes(CMAKE_SYSTEM_LIBRARY_PATH)
__list_clean_dupes(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)

# Enable use of lib64 search path variants by default.
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)