CrayLinuxEnvironment.cmake 4.7 KB

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