BlueGeneQ-base.cmake 7.4 KB

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