The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.3KB

  1. # ==============================================================================
  2. #
  3. # This file is part of the JUCE library.
  4. # Copyright (c) 2022 - Raw Material Software Limited
  5. #
  6. # JUCE is an open source library subject to commercial or open-source
  7. # licensing.
  8. #
  9. # By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  10. # Agreement and JUCE Privacy Policy.
  11. #
  12. # End User License Agreement: www.juce.com/juce-7-licence
  13. # Privacy Policy: www.juce.com/juce-privacy-policy
  14. #
  15. # Or: You may also use this code under the terms of the GPL v3 (see
  16. # www.gnu.org/licenses).
  17. #
  18. # JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  19. # EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  20. # DISCLAIMED.
  21. #
  22. # ==============================================================================
  23. function(_juce_create_atomic_target target_name)
  24. add_library("${target_name}" INTERFACE)
  25. add_library("juce::${target_name}" ALIAS "${target_name}")
  26. if(NOT ((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD")))
  27. return()
  28. endif()
  29. set(test_atomic_with_is_lock_free_file_contents
  30. [[
  31. #include <atomic>
  32. int main (int argc, char** argv)
  33. {
  34. std::atomic<long long> ll { static_cast<long long> (argc) };
  35. ll ^= static_cast<long long> (ll.is_lock_free());
  36. return static_cast<int> (ll);
  37. }
  38. ]])
  39. set(test_simple_atomic_file_contents
  40. [[
  41. #include <atomic>
  42. int main (int argc, char** argv)
  43. {
  44. std::atomic<long long> ll { static_cast<long long> (argc) };
  45. ll ^= 1;
  46. return static_cast<int> (ll);
  47. }
  48. ]])
  49. string(RANDOM LENGTH 16 random_file_string)
  50. set(test_file_name "${CMAKE_CURRENT_BINARY_DIR}/check_atomic_${random_file_string}.cpp")
  51. string(RANDOM LENGTH 16 random_dir_string)
  52. set(test_bindir "${CMAKE_CURRENT_BINARY_DIR}/check_atomic_dir_${random_dir_string}")
  53. file(WRITE "${test_file_name}" "${test_atomic_with_is_lock_free_file_contents}")
  54. try_compile(compile_result "${test_bindir}" "${test_file_name}"
  55. OUTPUT_VARIABLE test_build_output_0
  56. CXX_STANDARD 17
  57. CXX_STANDARD_REQUIRED TRUE
  58. CXX_EXTENSIONS FALSE)
  59. if(NOT compile_result)
  60. try_compile(compile_result "${test_bindir}" "${test_file_name}"
  61. OUTPUT_VARIABLE test_build_output_1
  62. LINK_LIBRARIES atomic
  63. CXX_STANDARD 17
  64. CXX_STANDARD_REQUIRED TRUE
  65. CXX_EXTENSIONS FALSE)
  66. if (NOT compile_result)
  67. file(WRITE "${test_file_name}" "${test_simple_atomic_file_contents}")
  68. try_compile(compile_result "${test_bindir}" "${test_file_name}"
  69. OUTPUT_VARIABLE test_build_output_2
  70. LINK_LIBRARIES atomic
  71. CXX_STANDARD 17
  72. CXX_STANDARD_REQUIRED TRUE
  73. CXX_EXTENSIONS FALSE)
  74. if (NOT compile_result)
  75. message(FATAL_ERROR
  76. "First build output:\n"
  77. "${test_build_output_0}"
  78. "\n\nSecond build output:\n"
  79. "${test_build_output_1}"
  80. "\n\nThird build output:\n"
  81. "${test_build_output_2}"
  82. "\n\nJUCE requires support for std::atomic, but this system cannot "
  83. "successfully compile a program which uses std::atomic. "
  84. "You may need to install a dedicated libatomic package using your "
  85. "system's package manager.")
  86. else()
  87. message(WARNING
  88. "First build output:\n"
  89. "${test_build_output_0}"
  90. "\n\nSecond build output:\n"
  91. "${test_build_output_1}"
  92. "\n\nIf you are seeing this warning it means that the libatomic library"
  93. "on this system doesn't support is_lock_free."
  94. "Please let the JUCE team know.")
  95. endif()
  96. endif()
  97. target_link_libraries("${target_name}" INTERFACE atomic)
  98. endif()
  99. file(REMOVE "${test_file_name}")
  100. file(REMOVE_RECURSE "${test_bindir}")
  101. endfunction()
  102. _juce_create_atomic_target(juce_atomic_wrapper)