CMakeCXXInformation.cmake 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # This file sets the basic flags for the C++ language in CMake.
  2. # It also loads the available platform file for the system-compiler
  3. # if it exists.
  4. GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_CXX_COMPILER} NAME_WE)
  5. # since the gnu compiler has several names force g++
  6. IF(CMAKE_COMPILER_IS_GNUCXX)
  7. SET(CMAKE_BASE_NAME g++)
  8. ENDIF(CMAKE_COMPILER_IS_GNUCXX)
  9. SET(CMAKE_SYSTEM_AND_CXX_COMPILER_INFO_FILE
  10. ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
  11. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
  12. # This should be included before the _INIT variables are
  13. # used to initialize the cache. Since the rule variables
  14. # have if blocks on them, users can still define them here.
  15. # But, it should still be after the platform file so changes can
  16. # be made to those values.
  17. IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  18. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
  19. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  20. IF(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
  21. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX})
  22. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
  23. # for most systems a module is the same as a shared library
  24. # so unless the variable CMAKE_MODULE_EXISTS is set just
  25. # copy the values from the LIBRARY variables
  26. IF(NOT CMAKE_MODULE_EXISTS)
  27. SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS})
  28. ENDIF(NOT CMAKE_MODULE_EXISTS)
  29. # Create a set of shared library variable specific to C++
  30. # For 90% of the systems, these are the same flags as the C versions
  31. # so if these are not set just copy the flags from the c version
  32. IF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
  33. SET(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  34. ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
  35. IF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
  36. SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  37. ENDIF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
  38. IF(NOT CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
  39. SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
  40. ENDIF(NOT CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
  41. IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
  42. SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  43. ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
  44. IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
  45. SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  46. ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
  47. IF(NOT CMAKE_INCLUDE_FLAG_CXX)
  48. SET(CMAKE_INCLUDE_FLAG_CXX ${CMAKE_INCLUDE_FLAG_C})
  49. ENDIF(NOT CMAKE_INCLUDE_FLAG_CXX)
  50. IF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
  51. SET(CMAKE_INCLUDE_FLAG_SEP_CXX ${CMAKE_INCLUDE_FLAG_SEP_C})
  52. ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
  53. # repeat for modules
  54. IF(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
  55. SET(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
  56. ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
  57. IF(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
  58. SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
  59. ENDIF(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
  60. IF(NOT CMAKE_SHARED_MODULE_LINK_CXX_FLAGS)
  61. SET(CMAKE_SHARED_MODULE_LINK_CXX_FLAGS ${CMAKE_SHARED_MODULE_LINK_C_FLAGS})
  62. ENDIF(NOT CMAKE_SHARED_MODULE_LINK_CXX_FLAGS)
  63. IF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG)
  64. SET(CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_FLAG})
  65. ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG)
  66. IF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP)
  67. SET(CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_FLAG_SEP})
  68. ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP)
  69. # add the flags to the cache based
  70. # on the initial values computed in the platform/*.cmake files
  71. # use _INIT variables so that this only happens the first time
  72. # and you can set these flags in the cmake cache
  73. SET (CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}" CACHE STRING
  74. "Flags used by the compiler during all build types.")
  75. IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  76. SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING
  77. "Flags used by the compiler during debug builds.")
  78. SET (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}" CACHE STRING
  79. "Flags used by the compiler during release minsize builds.")
  80. SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT}" CACHE STRING
  81. "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
  82. SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
  83. "Flags used by the compiler during Release with Debug Info builds.")
  84. ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  85. IF(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
  86. SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES_INIT}"
  87. CACHE STRING "Libraries linked by defalut with all C++ applications.")
  88. MARK_AS_ADVANCED(CMAKE_CXX_STANDARD_LIBRARIES)
  89. ENDIF(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
  90. INCLUDE(CMakeCommonLanguageInclude)
  91. # now define the following rules:
  92. # CMAKE_CXX_CREATE_SHARED_LIBRARY
  93. # CMAKE_CXX_CREATE_SHARED_MODULE
  94. # CMAKE_CXX_CREATE_STATIC_LIBRARY
  95. # CMAKE_CXX_COMPILE_OBJECT
  96. # CMAKE_CXX_LINK_EXECUTABLE
  97. # variables supplied by the generator at use time
  98. # <TARGET>
  99. # <TARGET_BASE> the target without the suffix
  100. # <OBJECTS>
  101. # <OBJECT>
  102. # <LINK_LIBRARIES>
  103. # <FLAGS>
  104. # <LINK_FLAGS>
  105. # CXX compiler information
  106. # <CMAKE_CXX_COMPILER>
  107. # <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>
  108. # <CMAKE_CXX_SHARED_MODULE_CREATE_FLAGS>
  109. # <CMAKE_CXX_LINK_FLAGS>
  110. # Static library tools
  111. # <CMAKE_AR>
  112. # <CMAKE_RANLIB>
  113. # create a shared C++ library
  114. IF(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
  115. SET(CMAKE_CXX_CREATE_SHARED_LIBRARY
  116. "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  117. ENDIF(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
  118. # create a c++ shared module copy the shared library rule by default
  119. IF(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
  120. SET(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
  121. ENDIF(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
  122. # create a C++ static library
  123. IF(NOT CMAKE_CXX_CREATE_STATIC_LIBRARY)
  124. SET(CMAKE_CXX_CREATE_STATIC_LIBRARY
  125. "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
  126. "<CMAKE_RANLIB> <TARGET> ")
  127. ENDIF(NOT CMAKE_CXX_CREATE_STATIC_LIBRARY)
  128. # compile a C++ file into an object file
  129. IF(NOT CMAKE_CXX_COMPILE_OBJECT)
  130. SET(CMAKE_CXX_COMPILE_OBJECT
  131. "<CMAKE_CXX_COMPILER> <FLAGS> -o <OBJECT> -c <SOURCE>")
  132. ENDIF(NOT CMAKE_CXX_COMPILE_OBJECT)
  133. IF(NOT CMAKE_CXX_LINK_EXECUTABLE)
  134. SET(CMAKE_CXX_LINK_EXECUTABLE
  135. "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  136. ENDIF(NOT CMAKE_CXX_LINK_EXECUTABLE)
  137. MARK_AS_ADVANCED(
  138. CMAKE_BUILD_TOOL
  139. CMAKE_VERBOSE_MAKEFILE
  140. CMAKE_CXX_FLAGS
  141. CMAKE_CXX_FLAGS_RELEASE
  142. CMAKE_CXX_FLAGS_RELWITHDEBINFO
  143. CMAKE_CXX_FLAGS_MINSIZEREL
  144. CMAKE_CXX_FLAGS_DEBUG)
  145. SET(CMAKE_CXX_INFORMATION_LOADED 1)