BlueGeneQ-base.cmake 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #
  4. # Blue Gene/Q base platform file.
  5. #
  6. # NOTE: Do not set your platform to "BlueGeneQ-base". This file is
  7. # included by the real platform files. Use one of these two platforms
  8. # instead:
  9. #
  10. # BlueGeneQ-dynamic For dynamically linked executables
  11. # BlueGeneQ-static For statically linked executables
  12. #
  13. # The platform you choose doesn't affect whether or not you can build
  14. # shared or static libraries -- it ONLY changs whether exeuatbles are linked
  15. # statically or dynamically.
  16. #
  17. # This platform file tries its best to adhere to the behavior of the MPI
  18. # compiler wrappers included with the latest BG/P drivers.
  19. #
  20. #
  21. # This adds directories that find commands should specifically ignore
  22. # for cross compiles. Most of these directories are the includeand
  23. # lib directories for the frontend on BG/P systems. Not ignoring
  24. # these can cause things like FindX11 to find a frontend PPC version
  25. # mistakenly. We use this on BG instead of re-rooting because backend
  26. # libraries are typically strewn about the filesystem, and we can't
  27. # re-root ALL backend libraries to a single place.
  28. #
  29. set(CMAKE_SYSTEM_IGNORE_PATH
  30. /lib /lib64 /include
  31. /usr/lib /usr/lib64 /usr/include
  32. /usr/local/lib /usr/local/lib64 /usr/local/include
  33. /usr/X11/lib /usr/X11/lib64 /usr/X11/include
  34. /usr/lib/X11 /usr/lib64/X11 /usr/include/X11
  35. /usr/X11R6/lib /usr/X11R6/lib64 /usr/X11R6/include
  36. /usr/X11R7/lib /usr/X11R7/lib64 /usr/X11R7/include
  37. )
  38. #
  39. # Indicate that this is a unix-like system
  40. #
  41. set(UNIX 1)
  42. #
  43. # Library prefixes, suffixes, extra libs.
  44. #
  45. set(CMAKE_LINK_LIBRARY_SUFFIX "")
  46. set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # lib
  47. set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") # .a
  48. set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
  49. set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") # .so
  50. set(CMAKE_EXECUTABLE_SUFFIX "") # .exe
  51. set(CMAKE_DL_LIBS "dl")
  52. #
  53. # BG/Q supports dynamic libraries regardless of whether we're building
  54. # static or dynamic *executables*.
  55. #
  56. set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  57. set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
  58. #
  59. # For BGQ builds, we're cross compiling, but we don't want to re-root things
  60. # (e.g. with CMAKE_FIND_ROOT_PATH) because users may have libraries anywhere on
  61. # the shared filesystems, and this may lie outside the root. Instead, we set the
  62. # system directories so that the various system BG CNK library locations are
  63. # searched first. This is not the clearest thing in the world, given IBM's driver
  64. # layout, but this should cover all the standard ones.
  65. #
  66. macro(__BlueGeneQ_common_setup compiler_id lang)
  67. # Need to use the version of the comm lib compiled with the right compiler.
  68. set(__BlueGeneQ_commlib_dir gcc)
  69. if (${compiler_id} STREQUAL XL)
  70. set(__BlueGeneQ_commlib_dir xl)
  71. endif()
  72. set(CMAKE_SYSTEM_LIBRARY_PATH
  73. /bgsys/drivers/ppcfloor/comm/default/lib # default comm layer (used by mpi compiler wrappers)
  74. /bgsys/drivers/ppcfloor/comm/${__BlueGeneQ_commlib_dir}/lib # PAMI, other lower-level comm libraries
  75. /bgsys/drivers/ppcfloor/gnu-linux/lib # CNK python installation directory
  76. /bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/lib # CNK Linux image -- standard runtime libs, pthread, etc.
  77. )
  78. # Add all the system include paths.
  79. set(CMAKE_SYSTEM_INCLUDE_PATH
  80. /bgsys/drivers/ppcfloor/comm/sys/include
  81. /bgsys/drivers/ppcfloor/
  82. /bgsys/drivers/ppcfloor/spi/include
  83. /bgsys/drivers/ppcfloor/spi/include/kernel/cnk
  84. /bgsys/drivers/ppcfloor/comm/${__BlueGeneQ_commlib_dir}/include
  85. )
  86. # Ensure that the system directories are included with the regular compilers, as users will expect this
  87. # to do the same thing as the MPI compilers, which add these flags.
  88. set(BGQ_SYSTEM_INCLUDES "")
  89. foreach(dir ${CMAKE_SYSTEM_INCLUDE_PATH})
  90. string(APPEND BGQ_SYSTEM_INCLUDES " -I${dir}")
  91. endforeach()
  92. set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${BGQ_SYSTEM_INCLUDES} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
  93. set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${BGQ_SYSTEM_INCLUDES} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
  94. #
  95. # Code below does setup for shared libraries. That this is done
  96. # regardless of whether the platform is static or dynamic -- you can make
  97. # shared libraries even if you intend to make static executables, you just
  98. # can't make a dynamic executable if you use the static platform file.
  99. #
  100. if (${compiler_id} STREQUAL XL)
  101. # Flags for XL compilers if we explicitly detected XL
  102. set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-qpic")
  103. set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-qmkshrobj -qnostaticlink")
  104. else()
  105. # Assume flags for GNU compilers (if the ID is GNU *or* anything else).
  106. set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
  107. set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
  108. endif()
  109. # Both toolchains use the GNU linker on BG/P, so these options are shared.
  110. set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-rpath,")
  111. set(CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG "-Wl,-rpath-link,")
  112. set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-soname,")
  113. set(CMAKE_EXE_EXPORTS_${lang}_FLAG "-Wl,--export-dynamic")
  114. set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "") # +s, flag for exe link to use shared lib
  115. set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":") # : or empty
  116. endmacro()
  117. #
  118. # This macro needs to be called for dynamic library support. Unfortunately on BG,
  119. # We can't support both static and dynamic links in the same platform file. The
  120. # dynamic link platform file needs to call this explicitly to set up dynamic linking.
  121. #
  122. macro(__BlueGeneQ_setup_dynamic compiler_id lang)
  123. __BlueGeneQ_common_setup(${compiler_id} ${lang})
  124. if (${compiler_id} STREQUAL XL)
  125. set(BGQ_${lang}_DYNAMIC_EXE_FLAGS "-qnostaticlink -qnostaticlink=libgcc")
  126. else()
  127. set(BGQ_${lang}_DYNAMIC_EXE_FLAGS "-dynamic")
  128. endif()
  129. # For dynamic executables, need to provide special BG/Q arguments.
  130. set(BGQ_${lang}_DEFAULT_EXE_FLAGS
  131. "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  132. set(CMAKE_${lang}_LINK_EXECUTABLE
  133. "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGQ_${lang}_DYNAMIC_EXE_FLAGS} ${BGQ_${lang}_DEFAULT_EXE_FLAGS}")
  134. endmacro()
  135. #
  136. # This macro needs to be called for static builds. Right now it just adds -Wl,-relax
  137. # to the link line.
  138. #
  139. macro(__BlueGeneQ_setup_static compiler_id lang)
  140. __BlueGeneQ_common_setup(${compiler_id} ${lang})
  141. # For static executables, use default link settings.
  142. set(BGQ_${lang}_DEFAULT_EXE_FLAGS
  143. "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  144. set(CMAKE_${lang}_LINK_EXECUTABLE
  145. "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGQ_${lang}_DEFAULT_EXE_FLAGS}")
  146. endmacro()