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.

80 lines
2.7KB

  1. # ==============================================================================
  2. #
  3. # This file is part of the JUCE 7 technical preview.
  4. # Copyright (c) 2022 - Raw Material Software Limited
  5. #
  6. # You may use this code under the terms of the GPL v3
  7. # (see www.gnu.org/licenses).
  8. #
  9. # For the technical preview this file cannot be licensed commercially.
  10. #
  11. # JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  12. # EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  13. # DISCLAIMED.
  14. #
  15. # ==============================================================================
  16. function(_juce_create_atomic_target target_name)
  17. add_library("${target_name}" INTERFACE)
  18. add_library("juce::${target_name}" ALIAS "${target_name}")
  19. if(NOT ((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD")))
  20. return()
  21. endif()
  22. set(test_file_contents
  23. [[
  24. #include <atomic>
  25. int main (int argc, char** argv)
  26. {
  27. std::atomic<long long> ll { static_cast<long long> (argc) };
  28. ll ^= 1;
  29. return static_cast<int> (ll);
  30. }
  31. ]])
  32. string(RANDOM LENGTH 16 random_file_string)
  33. set(test_file_name "${CMAKE_CURRENT_BINARY_DIR}/check_atomic_${random_file_string}.cpp")
  34. string(RANDOM LENGTH 16 random_dir_string)
  35. set(test_bindir "${CMAKE_CURRENT_BINARY_DIR}/check_atomic_dir_${random_dir_string}")
  36. file(WRITE "${test_file_name}" "${test_file_contents}")
  37. try_compile(compile_result "${test_bindir}" "${test_file_name}"
  38. OUTPUT_VARIABLE test_build_output_0
  39. CXX_STANDARD 14
  40. CXX_STANDARD_REQUIRED TRUE
  41. CXX_EXTENSIONS FALSE)
  42. if(NOT compile_result)
  43. try_compile(compile_result "${test_bindir}" "${test_file_name}"
  44. OUTPUT_VARIABLE test_build_output_1
  45. LINK_LIBRARIES atomic
  46. CXX_STANDARD 14
  47. CXX_STANDARD_REQUIRED TRUE
  48. CXX_EXTENSIONS FALSE)
  49. if (NOT compile_result)
  50. message(FATAL_ERROR
  51. "First build output:\n"
  52. "${test_build_output_0}"
  53. "\n\nSecond build output:\n"
  54. "${test_build_output_1}"
  55. "\n\nJUCE requires support for std::atomic, but this system cannot "
  56. "successfully compile a program which uses std::atomic. "
  57. "You may need to install a dedicated libatomic package using your "
  58. "system's package manager.")
  59. endif()
  60. target_link_libraries("${target_name}" INTERFACE atomic)
  61. endif()
  62. file(REMOVE "${test_file_name}")
  63. file(REMOVE_RECURSE "${test_bindir}")
  64. endfunction()
  65. _juce_create_atomic_target(juce_atomic_wrapper)