diff --git a/docs/CMake API.md b/docs/CMake API.md index 943c28ecaf..d087725631 100644 --- a/docs/CMake API.md +++ b/docs/CMake API.md @@ -137,6 +137,22 @@ Note that the static library produced by `juce_add_binary_data` automatically se Building universal binaries that will run on both arm64 and x86_64 can be achieved by configuring the CMake project with `"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64"`. +### Building with Clang on Windows + +Clang-cl (Clang with MSVC-like command-line) should work by default. If you are generating a Visual +Studio project, and have installed the LLVM package which is distributed with Visual Studio, then +you can configure a Clang-cl build by passing "-T ClangCL" on your configuration commandline. + +If you wish to use Clang with GNU-like command-line instead, you can pass +`-DCMAKE_CXX_COMPILER=clang++` and `-DCMAKE_C_COMPILER=clang` on your configuration commandline. +clang++ and clang must be on your `PATH` for this to work. Only more recent versions of CMake +support Clang's GNU-like command-line on Windows. CMake 3.12 is not supported, CMake 3.15 has +support, CMake 3.20 or higher is recommended. Note that CMake doesn't seem to automatically link a +runtime library when building in this configuration, but this can be remedied by setting the +`MSVC_RUNTIME_LIBRARY` property. See the [official +documentation](https://cmake.org/cmake/help/v3.15/prop_tgt/MSVC_RUNTIME_LIBRARY.html) of this +property for usage recommendations. + ### A note about compile definitions Module options and plugin options that would previously have been set in the Projucer can be set on diff --git a/extras/Build/CMake/JUCEHelperTargets.cmake b/extras/Build/CMake/JUCEHelperTargets.cmake index 97e4194dc3..3ef8f34dac 100644 --- a/extras/Build/CMake/JUCEHelperTargets.cmake +++ b/extras/Build/CMake/JUCEHelperTargets.cmake @@ -1,7 +1,7 @@ add_library(juce_recommended_warning_flags INTERFACE) add_library(juce::juce_recommended_warning_flags ALIAS juce_recommended_warning_flags) -if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) +if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")) target_compile_options(juce_recommended_warning_flags INTERFACE "/W4") elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")) target_compile_options(juce_recommended_warning_flags INTERFACE @@ -33,7 +33,7 @@ endif() add_library(juce_recommended_config_flags INTERFACE) add_library(juce::juce_recommended_config_flags ALIAS juce_recommended_config_flags) -if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) +if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")) target_compile_options(juce_recommended_config_flags INTERFACE $,/Od,/Ox> $<$:/MP> /EHsc) elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -49,7 +49,7 @@ endif() add_library(juce_recommended_lto_flags INTERFACE) add_library(juce::juce_recommended_lto_flags ALIAS juce_recommended_lto_flags) -if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) +if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")) target_compile_options(juce_recommended_lto_flags INTERFACE $<$:$,-GL,-flto>>) target_link_libraries(juce_recommended_lto_flags INTERFACE diff --git a/extras/Build/CMake/JUCEUtils.cmake b/extras/Build/CMake/JUCEUtils.cmake index 1b7720d75c..ef323b56ee 100644 --- a/extras/Build/CMake/JUCEUtils.cmake +++ b/extras/Build/CMake/JUCEUtils.cmake @@ -670,7 +670,7 @@ function(juce_add_module module_path) _juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" linuxLibs) elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") - if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) + if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")) if(module_name STREQUAL "juce_gui_basics") target_compile_options(${module_name} INTERFACE /bigobj) endif()