1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

CMake: Enable support for clang with gnu-like cmdline on Windows

This commit is contained in:
reuk 2021-06-02 15:35:15 +01:00
parent 17d967551c
commit db2a809832
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
3 changed files with 20 additions and 4 deletions

View file

@ -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 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"`. 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 ### A note about compile definitions
Module options and plugin options that would previously have been set in the Projucer can be set on Module options and plugin options that would previously have been set in the Projucer can be set on

View file

@ -1,7 +1,7 @@
add_library(juce_recommended_warning_flags INTERFACE) add_library(juce_recommended_warning_flags INTERFACE)
add_library(juce::juce_recommended_warning_flags ALIAS juce_recommended_warning_flags) 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") target_compile_options(juce_recommended_warning_flags INTERFACE "/W4")
elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")) elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
target_compile_options(juce_recommended_warning_flags INTERFACE target_compile_options(juce_recommended_warning_flags INTERFACE
@ -33,7 +33,7 @@ endif()
add_library(juce_recommended_config_flags INTERFACE) add_library(juce_recommended_config_flags INTERFACE)
add_library(juce::juce_recommended_config_flags ALIAS juce_recommended_config_flags) 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 target_compile_options(juce_recommended_config_flags INTERFACE
$<IF:$<CONFIG:Debug>,/Od,/Ox> $<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">:/MP> /EHsc) $<IF:$<CONFIG:Debug>,/Od,/Ox> $<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">:/MP> /EHsc)
elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
@ -49,7 +49,7 @@ endif()
add_library(juce_recommended_lto_flags INTERFACE) add_library(juce_recommended_lto_flags INTERFACE)
add_library(juce::juce_recommended_lto_flags ALIAS juce_recommended_lto_flags) 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 target_compile_options(juce_recommended_lto_flags INTERFACE
$<$<CONFIG:Release>:$<IF:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">,-GL,-flto>>) $<$<CONFIG:Release>:$<IF:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">,-GL,-flto>>)
target_link_libraries(juce_recommended_lto_flags INTERFACE target_link_libraries(juce_recommended_lto_flags INTERFACE

View file

@ -670,7 +670,7 @@ function(juce_add_module module_path)
_juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" linuxLibs) _juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" linuxLibs)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") 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") if(module_name STREQUAL "juce_gui_basics")
target_compile_options(${module_name} INTERFACE /bigobj) target_compile_options(${module_name} INTERFACE /bigobj)
endif() endif()