CrayLinuxEnvironment.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Compute Node Linux doesn't quite work the same as native Linux so all of this
  2. # needs to be custom. We use the variables defined through Cray's environment
  3. # modules to set up the right paths for things.
  4. set(UNIX 1)
  5. if(DEFINED ENV{CRAYOS_VERSION})
  6. set(CMAKE_SYSTEM_VERSION "$ENV{CRAYOS_VERSION}")
  7. elseif(DEFINED ENV{XTOS_VERSION})
  8. set(CMAKE_SYSTEM_VERSION "$ENV{XTOS_VERSION}")
  9. elseif(EXISTS /etc/opt/cray/release/cle-release)
  10. file(STRINGS /etc/opt/cray/release/cle-release release REGEX "^RELEASE=.*")
  11. string(REGEX REPLACE "^RELEASE=(.*)$" "\\1" CMAKE_SYSTEM_VERSION "${release}")
  12. unset(release)
  13. elseif(EXISTS /etc/opt/cray/release/clerelease)
  14. file(READ /etc/opt/cray/release/clerelease CMAKE_SYSTEM_VERSION)
  15. endif()
  16. # Guard against multiple messages
  17. if(NOT __CrayLinuxEnvironment_message)
  18. set(__CrayLinuxEnvironment_message 1 CACHE INTERNAL "")
  19. if(NOT CMAKE_SYSTEM_VERSION)
  20. message(STATUS "CrayLinuxEnvironment: Unable to determine CLE version. This platform file should only be used from inside the Cray Linux Environment for targeting compute nodes (NIDs).")
  21. else()
  22. message(STATUS "Cray Linux Environment ${CMAKE_SYSTEM_VERSION}")
  23. endif()
  24. endif()
  25. # All cray systems are x86 CPUs and have been for quite some time
  26. # Note: this may need to change in the future with 64-bit ARM
  27. set(CMAKE_SYSTEM_PROCESSOR "x86_64")
  28. set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
  29. set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
  30. set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
  31. set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
  32. set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
  33. # Don't override shared lib support if it's already been set and possibly
  34. # overridden elsewhere by the CrayPrgEnv module
  35. if(NOT CMAKE_FIND_LIBRARY_SUFFIXES)
  36. set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
  37. set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  38. endif()
  39. set(CMAKE_DL_LIBS dl)
  40. # Note: Much of this is pulled from UnixPaths.cmake but adjusted to the Cray
  41. # environment accordingly
  42. # Get the install directory of the running cmake to the search directories
  43. # CMAKE_ROOT is CMAKE_INSTALL_PREFIX/share/cmake, so we need to go two levels up
  44. get_filename_component(__cmake_install_dir "${CMAKE_ROOT}" PATH)
  45. get_filename_component(__cmake_install_dir "${__cmake_install_dir}" PATH)
  46. # Note: Some Cray's have the SYSROOT_DIR variable defined, pointing to a copy
  47. # of the NIDs userland. If so, then we'll use it. Otherwise, just assume
  48. # the userland from the login node is ok
  49. # List common installation prefixes. These will be used for all
  50. # search types.
  51. list(APPEND CMAKE_SYSTEM_PREFIX_PATH
  52. # Standard
  53. $ENV{SYSROOT_DIR}/usr/local $ENV{SYSROOT_DIR}/usr $ENV{SYSROOT_DIR}/
  54. # CMake install location
  55. "${__cmake_install_dir}"
  56. )
  57. if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
  58. list(APPEND CMAKE_SYSTEM_PREFIX_PATH
  59. # Project install destination.
  60. "${CMAKE_INSTALL_PREFIX}"
  61. )
  62. if(CMAKE_STAGING_PREFIX)
  63. list(APPEND CMAKE_SYSTEM_PREFIX_PATH
  64. # User-supplied staging prefix.
  65. "${CMAKE_STAGING_PREFIX}"
  66. )
  67. endif()
  68. endif()
  69. list(APPEND CMAKE_SYSTEM_INCLUDE_PATH
  70. $ENV{SYSROOT_DIR}/usr/include
  71. $ENV{SYSROOT_DIR}/usr/include/X11
  72. )
  73. list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
  74. $ENV{SYSROOT_DIR}/usr/local/lib64
  75. $ENV{SYSROOT_DIR}/usr/lib64
  76. $ENV{SYSROOT_DIR}/lib64
  77. )
  78. list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
  79. $ENV{SYSROOT_DIR}/usr/local/lib64
  80. $ENV{SYSROOT_DIR}/usr/lib64
  81. $ENV{SYSROOT_DIR}/lib64
  82. )
  83. # Compute the intersection of several lists
  84. function(__cray_list_intersect OUTPUT INPUT0)
  85. if(ARGC EQUAL 2)
  86. list(APPEND ${OUTPUT} ${${INPUT0}})
  87. else()
  88. foreach(I IN LISTS ${INPUT0})
  89. set(__is_common 1)
  90. foreach(L IN LISTS ARGN)
  91. list(FIND ${L} "${I}" __idx)
  92. if(__idx EQUAL -1)
  93. set(__is_common 0)
  94. break()
  95. endif()
  96. endforeach()
  97. if(__is_common)
  98. list(APPEND ${OUTPUT} "${I}")
  99. endif()
  100. endforeach()
  101. endif()
  102. set(${OUTPUT} ${${OUTPUT}} PARENT_SCOPE)
  103. endfunction()
  104. macro(__list_clean_dupes var)
  105. if(${var})
  106. list(REMOVE_DUPLICATES ${var})
  107. endif()
  108. endmacro()
  109. get_property(__langs GLOBAL PROPERTY ENABLED_LANGUAGES)
  110. set(__cray_inc_path_vars)
  111. set(__cray_lib_path_vars)
  112. foreach(__lang IN LISTS __langs)
  113. list(APPEND __cray_inc_path_vars CMAKE_${__lang}_IMPLICIT_INCLUDE_DIRECTORIES)
  114. list(APPEND __cray_lib_path_vars CMAKE_${__lang}_IMPLICIT_LINK_DIRECTORIES)
  115. endforeach()
  116. if(__cray_inc_path_vars)
  117. __cray_list_intersect(__cray_implicit_include_dirs ${__cray_inc_path_vars})
  118. if(__cray_implicit_include_dirs)
  119. list(INSERT CMAKE_SYSTEM_INCLUDE_PATH 0 ${__cray_implicit_include_dirs})
  120. endif()
  121. endif()
  122. if(__cray_lib_path_vars)
  123. __cray_list_intersect(__cray_implicit_library_dirs ${__cray_lib_path_vars})
  124. if(__cray_implicit_library_dirs)
  125. list(INSERT CMAKE_SYSTEM_LIBRARY_PATH 0 ${__cray_implicit_library_dirs})
  126. endif()
  127. endif()
  128. __list_clean_dupes(CMAKE_SYSTEM_PREFIX_PATH)
  129. __list_clean_dupes(CMAKE_SYSTEM_INCLUDE_PATH)
  130. __list_clean_dupes(CMAKE_SYSTEM_LIBRARY_PATH)
  131. __list_clean_dupes(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
  132. # Enable use of lib64 search path variants by default.
  133. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)