gnu.toolchain.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. cmake_minimum_required(VERSION 3.5)
  2. # load settings in case of "try compile"
  3. set(TOOLCHAIN_CONFIG_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain.config.cmake")
  4. get_property(__IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
  5. if(__IN_TRY_COMPILE)
  6. include("${CMAKE_CURRENT_SOURCE_DIR}/../toolchain.config.cmake" OPTIONAL) # CMAKE_BINARY_DIR is different
  7. macro(toolchain_save_config)
  8. # nothing
  9. endmacro()
  10. else()
  11. macro(toolchain_save_config)
  12. set(__config "#message(\"Load TOOLCHAIN config...\")\n")
  13. get_cmake_property(__variableNames VARIABLES)
  14. set(__vars_list ${ARGN})
  15. list(APPEND __vars_list
  16. ${TOOLCHAIN_CONFIG_VARS}
  17. CMAKE_SYSTEM_NAME
  18. CMAKE_SYSTEM_VERSION
  19. CMAKE_SYSTEM_PROCESSOR
  20. CMAKE_C_COMPILER
  21. CMAKE_CXX_COMPILER
  22. CMAKE_C_FLAGS
  23. CMAKE_CXX_FLAGS
  24. CMAKE_SHARED_LINKER_FLAGS
  25. CMAKE_MODULE_LINKER_FLAGS
  26. CMAKE_EXE_LINKER_FLAGS
  27. CMAKE_SKIP_RPATH
  28. CMAKE_FIND_ROOT_PATH
  29. GCC_COMPILER_VERSION
  30. )
  31. foreach(__var ${__variableNames})
  32. foreach(_v ${__vars_list})
  33. if("x${__var}" STREQUAL "x${_v}")
  34. if(${__var} MATCHES " ")
  35. set(__config "${__config}set(${__var} \"${${__var}}\")\n")
  36. else()
  37. set(__config "${__config}set(${__var} ${${__var}})\n")
  38. endif()
  39. endif()
  40. endforeach()
  41. endforeach()
  42. if(EXISTS "${TOOLCHAIN_CONFIG_FILE}")
  43. file(READ "${TOOLCHAIN_CONFIG_FILE}" __config_old)
  44. endif()
  45. if("${__config_old}" STREQUAL "${__config}")
  46. # nothing
  47. else()
  48. #message("Update TOOLCHAIN config: ${__config}")
  49. file(WRITE "${TOOLCHAIN_CONFIG_FILE}" "${__config}")
  50. endif()
  51. unset(__config)
  52. unset(__config_old)
  53. unset(__vars_list)
  54. unset(__variableNames)
  55. endmacro()
  56. endif() # IN_TRY_COMPILE
  57. if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
  58. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  59. endif()
  60. if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
  61. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  62. endif()
  63. if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
  64. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  65. endif()
  66. if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
  67. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  68. endif()
  69. macro(__cmake_find_root_save_and_reset)
  70. foreach(v
  71. CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
  72. CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
  73. CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
  74. CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
  75. )
  76. set(__save_${v} ${${v}})
  77. set(${v} NEVER)
  78. endforeach()
  79. endmacro()
  80. macro(__cmake_find_root_restore)
  81. foreach(v
  82. CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
  83. CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
  84. CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
  85. CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
  86. )
  87. set(${v} ${__save_${v}})
  88. unset(__save_${v})
  89. endforeach()
  90. endmacro()
  91. # macro to find programs on the host OS
  92. macro(find_host_program)
  93. __cmake_find_root_save_and_reset()
  94. if(CMAKE_HOST_WIN32)
  95. SET(WIN32 1)
  96. SET(UNIX)
  97. elseif(CMAKE_HOST_APPLE)
  98. SET(APPLE 1)
  99. SET(UNIX)
  100. endif()
  101. find_program(${ARGN})
  102. SET(WIN32)
  103. SET(APPLE)
  104. SET(UNIX 1)
  105. __cmake_find_root_restore()
  106. endmacro()
  107. # macro to find packages on the host OS
  108. macro(find_host_package)
  109. __cmake_find_root_save_and_reset()
  110. if(CMAKE_HOST_WIN32)
  111. SET(WIN32 1)
  112. SET(UNIX)
  113. elseif(CMAKE_HOST_APPLE)
  114. SET(APPLE 1)
  115. SET(UNIX)
  116. endif()
  117. find_package(${ARGN})
  118. SET(WIN32)
  119. SET(APPLE)
  120. SET(UNIX 1)
  121. __cmake_find_root_restore()
  122. endmacro()
  123. set(CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries.")