Cmake_generator_toolset

broken image


  1. Cmake Generator Platform
  2. Cmake Generator Ninja
  3. Cmake Set Default Generator

Native build system toolset name specified by user. Some CMake generators support a toolset name to be given to the native build system to choose a compiler. If the user specifies a toolset name (e.g. Via the cmake(1)-T option) the value will be available in this variable. Nevermind; I guess it should have been 'Unix Makefiles' went back versions and same thing; so checked other projects sorry.

I am proud to announce the first CMake 3.18 release candidate.
https://cmake.org/download/

Documentation is available at:
https://cmake.org/cmake/help/v3.18

Release notes appear below and are also published at
https://cmake.org/cmake/help/v3.18/release/3.18.html

Some of the more significant changes in CMake 3.18 are:

  • The 'CUDA' language can now be compiled using Clang.
    This is experimental and still under development.

  • 'cmake(1)' gained support for profiling of CMake scripts through the
    parameters '–profiling-output' and '–profiling-format'.

  • The 'add_library()' and 'add_executable()' commands learned to
    create Alias Targets referencing non-'GLOBAL' Imported Targets.

  • The 'cmake_language()' command was added for meta-operations on
    scripted or built-in commands, starting with a mode to 'CALL' other
    commands, and 'EVAL CODE' to inplace evaluate a CMake script.

  • The 'file(CONFIGURE)' subcommand was created in order to replicate
    the 'configure_file()' functionality without resorting to a pre-
    existing file on disk as input. The content is instead passed as a
    string.

  • The 'find_program()', 'find_library()', 'find_path()' and
    'find_file()' commands gained a new 'REQUIRED' option that will stop
    processing with an error message if nothing is found.

  • A 'CMAKE_CUDA_ARCHITECTURES' variable was added to specify CUDA
    output architectures. Users are encouraged to use this instead of
    specifying options manually, as this approach is compiler-agnostic.
    The variable is initialized automatically when
    'CMAKE_CUDA_COMPILER_ID' is 'NVIDIA'. The variable is used to
    initialize the new 'CUDA_ARCHITECTURES' target property. See policy
    'CMP0104'.

  • The 'UNITY_BUILD_MODE' target property was added to tell generators
    which algorithm ('BATCH', 'GROUP') to use for grouping included source
    files.

  • The 'CheckLinkerFlag' module has been added to provide a facility to
    check validity of link flags.

  • The '$' and '$' 'generator
    expressions' were added to manage device and host link steps.

  • The '$' and '$' 'generator
    expressions' were added.

  • 'ctest(1)' gained a new 'CTEST_RESOURCE_SPEC_FILE' variable, which
    can be used to specify a resource specification file.

  • 'ccmake(1)' learned to read a 'CCMAKE_COLORS' environment variable
    to customize colors.

  • On Windows, the 'Ninja' and 'Ninja Multi-Config' generators, when a
    compiler is not explicitly specified, now select the first compiler
    (of any name) found in directories listed by the 'PATH' environment
    variable.

Changes made since CMake 3.17 include the following.

New Features

Cmake generator expressions

Languages

  • The 'CUDA' language can now be compiled using Clang.
    This is experimental and still under development.

Command-Line

  • 'cmake(1)' gained support for profiling of CMake scripts through the
    parameters '–profiling-output' and '–profiling-format'.

  • 'cmake(1)' gained a 'cat' command line option that can be used to
    concatenate files and print them on standard output.

Commands

  • The 'add_library()' and 'add_executable()' commands learned to
    create Alias Targets referencing non-'GLOBAL' Imported Targets.

  • The 'cmake_language()' command was added for meta-operations on
    scripted or built-in commands, starting with a mode to 'CALL' other
    commands, and 'EVAL CODE' to inplace evaluate a CMake script.

  • The 'execute_process()' command gained the 'ECHO_OUTPUT_VARIABLE'
    and 'ECHO_ERROR_VARIABLE' options.

  • The 'export()' command now raise an error if used multiple times
    with same 'FILE' without 'APPEND'. See policy 'CMP0103'.

  • The 'file()' command gained the 'ARCHIVE_CREATE' and
    'ARCHIVE_EXTRACT' subcommands to expose the 'cmake(1)' '-E tar'
    functionality to CMake scripting code.

  • The 'file(CONFIGURE)' subcommand was created in order to replicate
    the 'configure_file()' functionality without resorting to a pre-
    existing file on disk as input. The content is instead passed as a
    string.

  • The 'file(UPLOAD)' command gained 'TLS_VERIFY' and 'TLS_CAINFO'
    options to control server certificate verification.

  • The 'find_program()', 'find_library()', 'find_path()' and
    'find_file()' commands gained a new 'REQUIRED' option that will stop
    processing with an error message if nothing is found.

  • The 'get_property()' command with 'SOURCE' scope gained the
    'DIRECTORY' and 'TARGET_DIRECTORY' options to get a property from
    the provided directory scope.

  • The 'get_source_file_property()' command gained the 'DIRECTORY' and
    'TARGET_DIRECTORY' options to get a property from the provided
    directory scope.

  • The 'list()' operation 'SORT' gained the 'NATURAL' sort option to
    sort using natural order (see 'strverscmp(3)' manual).

  • The 'set_property()' command with the 'SOURCE' scope gained the
    'DIRECTORY' and 'TARGET_DIRECTORY' options to set properties in the
    provided directory scopes.

  • The 'set_source_files_properties()' command gained the 'DIRECTORY'
    and 'TARGET_DIRECTORY' options to set properties in the provided
    directory scopes.

  • The 'string()' command learned a new 'HEX' sub-command, which
    converts strings into their hexadecimal representation.

Variables

  • A 'CMAKE_CUDA_ARCHITECTURES' variable was added to specify CUDA
    output architectures. Users are encouraged to use this instead of
    specifying options manually, as this approach is compiler-agnostic.
    The variable is initialized automatically when
    'CMAKE_CUDA_COMPILER_ID' is 'NVIDIA'. The variable is used to
    initialize the new 'CUDA_ARCHITECTURES' target property. See policy
    'CMP0104'.

  • The 'CMAKE_PCH_WARN_INVALID' variable was added to initialize the
    'PCH_WARN_INVALID' target property to allow the removal of the
    precompiled header invalid warning.

Properties

  • The 'CUDA_ARCHITECTURES' target property was added to specify CUDA
    output architectures. Users are encouraged to use this instead of
    specifying options manually, as this approach is compiler-agnostic.
    The property is initialized by the new 'CMAKE_CUDA_ARCHITECTURES'
    variable. See policy 'CMP0104'.

  • The 'Fortran_PREPROCESS' target property and 'Fortran_PREPROCESS'
    source-file property were added to control preprocessing of Fortran
    source files.

  • The 'FRAMEWORK_MULTI_CONFIG_POSTFIX_' target property and
    associated 'CMAKE_FRAMEWORK_MULTI_CONFIG_POSTFIX_' variable
    were created to allow adding a postfix to the name of a framework
    file name when using a multi-config generator.

  • The 'OBJECT_OUTPUTS' source file property now supports 'generator
    expressions'.

  • The 'UNITY_BUILD_MODE' target property was added to tell generators
    which algorithm to use for grouping included source files.

  • The 'VS_SOURCE_SETTINGS_' target property was added to tell
    Visual Studio Generators for VS 2010 and above to add metadata to
    non-built source files using ''.

  • The 'VS_SETTINGS' source file property was added to tell Visual
    Studio Generators for VS 2010 and above to add metadata to a non-
    built source file.

  • The 'VS_PLATFORM_TOOLSET' target property was added to tell Visual
    Studio Generators for VS 2010 and above to override the platform
    toolset.

  • The 'VS_SOLUTION_DEPLOY' target property was added to tell Visual
    Studio Generators for VS 2010 and above to mark a target for
    deployment even when not building for Windows Phone/Store/CE.

Modules

Mingw
  • The 'CheckLinkerFlag' module has been added to provide a facility to
    check validity of link flags.

  • The 'ExternalProject' module 'ExternalProject_Add()' command gained
    a new 'GIT_REMOTE_UPDATE_STRATEGY' keyword. This can be used to
    specify how failed rebase operations during a git update should be
    handled. The 'CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY' variable was also
    added as a global default and is honored by both the
    'ExternalProject' and 'FetchContent' modules.

  • The 'FetchContent' module 'FetchContent_Declare()' command now
    supports a 'SOURCE_SUBDIR' option. It can be used to direct
    'FetchContent_MakeAvailable()' to look in a different location for
    the 'CMakeLists.txt' file.

  • The 'FindBLAS' module now provides an imported target.

  • The 'FindLAPACK' module now provides an imported target.

  • The 'FindPython3', 'FindPython2' and 'FindPython' modules:

    • gained the possibility to create per-artifact cache variables for
      interactive editing in 'cmake-gui(1)' and 'ccmake(1)'.

    • gained sub-components 'Development.Module' and 'Development.Embed'
      under the 'Development' component.

    • gained the capability to specify which Python implementations to
      find, including 'IronPython' and 'PyPy'.

  • The 'FindRuby' module input and output variables were all renamed
    from 'RUBY_' to 'Ruby_' for consistency with other find modules.
    Input variables of the old case will be honored if provided, and
    output variables of the old case are always provided.

  • The 'FindSWIG' module now accepts target languages as 'COMPONENTS'
    and 'OPTIONAL_COMPONENTS' arguments to 'find_package'.

  • The 'GoogleTest' module 'gtest_discover_tests()' command:

    • gained a new 'DISCOVERY_MODE' option to control when the test
      discovery step is run. It offers a new 'PRE_TEST' setting to run
      the discovery at test time instead of build time.

    • gained a new optional parameter 'XML_OUTPUT_DIR'. When set the
      JUnit XML test results are stored in that directory.

  • The 'FindLibXslt' module now provides imported targets.

  • The 'UseSWIG' module now supports Fortran as a target language if
    the 'SWIG_EXECUTABLE' is SWIG-Fortran.

Generator Expressions

  • The '$' and '$' 'generator
    expressions' were added to manage device and host link steps.

  • The '$' and '$' 'generator
    expressions' were added.

Cmake Generator Platform

CTest

  • 'ctest(1)' gained a new 'CTEST_RESOURCE_SPEC_FILE' variable, which
    can be used to specify a resource specification file.

  • 'ctest(1)' gained a '–stop-on-failure' option, which can be used to
    stop running the tests once one has failed.

  • The 'ctest_test()' command gained a 'STOP_ON_FAILURE' option which
    can be used to stop running the tests once one has failed.

  • The 'CTestCoverageCollectGCOV' module
    'ctest_coverage_collect_gcov()' command gained a
    'TARBALL_COMPRESSION' option to control compression of the tarball
    of collected results.

Cmake Generator Ninja

CPack

  • The 'CPack Archive Generator''s 'TXZ' format learned the
    'CPACK_ARCHIVE_THREADS' variable to enable parallel compression.
    Requires support in the 'liblzma' used by CMake.

  • The 'CPack NSIS Generator' gained a new variable
    'CPACK_NSIS_MANIFEST_DPI_AWARE' to declare that the installer is
    DPI-aware.

  • The 'CPack RPM Generator' gained 'CPACK_RPM_PRE_TRANS_SCRIPT_FILE'
    'CPACK_RPM_POST_TRANS_SCRIPT_FILE' variables to specify pre- and
    post-trans scripts.

Other

  • 'cmake-gui(1)' now populates its generator selection widget default
    value from the 'CMAKE_GENERATOR' environment variable.
    Additionally, environment variables 'CMAKE_GENERATOR_PLATFORM' and
    'CMAKE_GENERATOR_TOOLSET' are used to populate their respective
    widget defaults.

  • 'ccmake(1)' learned to read a 'CCMAKE_COLORS' environment variable
    to customize colors.

Deprecated and Removed Features

  • The 'Documentation' module has been deprecated via 'CMP0106'. This
    module was essentially VTK code that CMake should not be shipping
    anymore.

  • An explicit deprecation diagnostic was added for policy 'CMP0070'
    and policy 'CMP0071' ('CMP0069' and below were already deprecated).
    The 'cmake-policies(7)' manual explains that the OLD behaviors of
    all policies are deprecated and that projects should port to the NEW
    behaviors.

Other Changes

  • On Windows, the 'Ninja' and 'Ninja Multi-Config' generators, when a
    compiler is not explicitly specified, now select the first compiler
    (of any name) found in directories listed by the 'PATH' environment
    variable.

  • The 'LINK_OPTIONS' and 'INTERFACE_LINK_OPTIONS' target properties
    are now used for the device link step. See policy 'CMP0105'.

  • Creation of an 'ALIAS' target overwriting an existing target now
    raises an error. See policy 'CMP0107'.

  • Linking a target to itself through an alias now raises an error. See
    policy 'CMP0108'.

  • The 'FindPackageHandleStandardArgs' module option 'REQUIRED_VARS' is
    now optional if 'HANDLE_COMPONENTS' is specified.

  • The 'source_group()' command now also recognizes forward slashes as
    subgroup delimiters, not just backslashes.

  • 'ctest(1)' now logs environment variables that it sets for each
    test, either due to the 'ENVIRONMENT' property or the resource
    allocation feature, and submits this log to CDash. It does not log
    environment variables that were set outside of CTest.

  • When building CMake itself from source and not using a system-
    provided libcurl, HTTP/2 support is now enabled for commands
    supporting network communication via 'http(s)', such as
    'file(DOWNLOAD)', 'file(UPLOAD)', and 'ctest_submit()'. The
    precompiled binaries provided on 'cmake.org' now support HTTP/2.

-->

You can use Visual Studio with Clang to edit and debug C++ CMake projects that target Windows or Linux.

Windows: Visual Studio 2019 version 16.1 includes support for editing, building, and debugging with Clang/LLVM in CMake projects targeting Windows.

Cmake_generator_toolset

Linux: For Linux CMake projects, no special Visual Studio support is required. You can install Clang using your distro's package manager, and add the appropriate commands in the CMakeLists.txt file.

Install

For best IDE support in Visual Studio, we recommend using the latest Clang compiler tools for Windows. If you don't already have those, you can install them by opening the Visual Studio Installer and choosing C++ Clang compiler for Windows under Desktop development with C++ optional components. When using a custom Clang installation, check the C++ Clang-cl for v142 build tools component.

Create a new configuration

To add a new Clang configuration to a CMake project:

  1. Right-click on CMakeLists.txt in Solution Explorer and choose CMake settings for project.

  2. Under Configurations, press the Add Configuration button:

  3. Choose the desired Clang configuration (note that separate Clang configurations are provided for Windows and Linux), then press Select:

  4. To make modifications to this configuration, use the CMake Settings Editor. For more information, see Customize CMake build settings in Visual Studio.

Modify an existing configuration to use Clang

Cmake Set Default Generator

To modify an existing configuration to use Clang, follow these steps:

  1. Right-click on CMakeLists.txt in Solution Explorer and choose CMake settings for project.

  2. Under General select the Toolset dropdown and choose the desired Clang toolset:

Custom Clang locations

Cmake_generator_toolset

By default, Visual Studio looks for Clang in two places:

  • (Windows) The internally installed copy of Clang/LLVM that comes with the Visual Studio installer.
  • (Windows and Linux) The PATH environment variable.

You can specify another location by setting the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER CMake variables in CMake Settings:

Cmake set default generator

Languages

  • The 'CUDA' language can now be compiled using Clang.
    This is experimental and still under development.

Command-Line

  • 'cmake(1)' gained support for profiling of CMake scripts through the
    parameters '–profiling-output' and '–profiling-format'.

  • 'cmake(1)' gained a 'cat' command line option that can be used to
    concatenate files and print them on standard output.

Commands

  • The 'add_library()' and 'add_executable()' commands learned to
    create Alias Targets referencing non-'GLOBAL' Imported Targets.

  • The 'cmake_language()' command was added for meta-operations on
    scripted or built-in commands, starting with a mode to 'CALL' other
    commands, and 'EVAL CODE' to inplace evaluate a CMake script.

  • The 'execute_process()' command gained the 'ECHO_OUTPUT_VARIABLE'
    and 'ECHO_ERROR_VARIABLE' options.

  • The 'export()' command now raise an error if used multiple times
    with same 'FILE' without 'APPEND'. See policy 'CMP0103'.

  • The 'file()' command gained the 'ARCHIVE_CREATE' and
    'ARCHIVE_EXTRACT' subcommands to expose the 'cmake(1)' '-E tar'
    functionality to CMake scripting code.

  • The 'file(CONFIGURE)' subcommand was created in order to replicate
    the 'configure_file()' functionality without resorting to a pre-
    existing file on disk as input. The content is instead passed as a
    string.

  • The 'file(UPLOAD)' command gained 'TLS_VERIFY' and 'TLS_CAINFO'
    options to control server certificate verification.

  • The 'find_program()', 'find_library()', 'find_path()' and
    'find_file()' commands gained a new 'REQUIRED' option that will stop
    processing with an error message if nothing is found.

  • The 'get_property()' command with 'SOURCE' scope gained the
    'DIRECTORY' and 'TARGET_DIRECTORY' options to get a property from
    the provided directory scope.

  • The 'get_source_file_property()' command gained the 'DIRECTORY' and
    'TARGET_DIRECTORY' options to get a property from the provided
    directory scope.

  • The 'list()' operation 'SORT' gained the 'NATURAL' sort option to
    sort using natural order (see 'strverscmp(3)' manual).

  • The 'set_property()' command with the 'SOURCE' scope gained the
    'DIRECTORY' and 'TARGET_DIRECTORY' options to set properties in the
    provided directory scopes.

  • The 'set_source_files_properties()' command gained the 'DIRECTORY'
    and 'TARGET_DIRECTORY' options to set properties in the provided
    directory scopes.

  • The 'string()' command learned a new 'HEX' sub-command, which
    converts strings into their hexadecimal representation.

Variables

  • A 'CMAKE_CUDA_ARCHITECTURES' variable was added to specify CUDA
    output architectures. Users are encouraged to use this instead of
    specifying options manually, as this approach is compiler-agnostic.
    The variable is initialized automatically when
    'CMAKE_CUDA_COMPILER_ID' is 'NVIDIA'. The variable is used to
    initialize the new 'CUDA_ARCHITECTURES' target property. See policy
    'CMP0104'.

  • The 'CMAKE_PCH_WARN_INVALID' variable was added to initialize the
    'PCH_WARN_INVALID' target property to allow the removal of the
    precompiled header invalid warning.

Properties

  • The 'CUDA_ARCHITECTURES' target property was added to specify CUDA
    output architectures. Users are encouraged to use this instead of
    specifying options manually, as this approach is compiler-agnostic.
    The property is initialized by the new 'CMAKE_CUDA_ARCHITECTURES'
    variable. See policy 'CMP0104'.

  • The 'Fortran_PREPROCESS' target property and 'Fortran_PREPROCESS'
    source-file property were added to control preprocessing of Fortran
    source files.

  • The 'FRAMEWORK_MULTI_CONFIG_POSTFIX_' target property and
    associated 'CMAKE_FRAMEWORK_MULTI_CONFIG_POSTFIX_' variable
    were created to allow adding a postfix to the name of a framework
    file name when using a multi-config generator.

  • The 'OBJECT_OUTPUTS' source file property now supports 'generator
    expressions'.

  • The 'UNITY_BUILD_MODE' target property was added to tell generators
    which algorithm to use for grouping included source files.

  • The 'VS_SOURCE_SETTINGS_' target property was added to tell
    Visual Studio Generators for VS 2010 and above to add metadata to
    non-built source files using ''.

  • The 'VS_SETTINGS' source file property was added to tell Visual
    Studio Generators for VS 2010 and above to add metadata to a non-
    built source file.

  • The 'VS_PLATFORM_TOOLSET' target property was added to tell Visual
    Studio Generators for VS 2010 and above to override the platform
    toolset.

  • The 'VS_SOLUTION_DEPLOY' target property was added to tell Visual
    Studio Generators for VS 2010 and above to mark a target for
    deployment even when not building for Windows Phone/Store/CE.

Modules

  • The 'CheckLinkerFlag' module has been added to provide a facility to
    check validity of link flags.

  • The 'ExternalProject' module 'ExternalProject_Add()' command gained
    a new 'GIT_REMOTE_UPDATE_STRATEGY' keyword. This can be used to
    specify how failed rebase operations during a git update should be
    handled. The 'CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY' variable was also
    added as a global default and is honored by both the
    'ExternalProject' and 'FetchContent' modules.

  • The 'FetchContent' module 'FetchContent_Declare()' command now
    supports a 'SOURCE_SUBDIR' option. It can be used to direct
    'FetchContent_MakeAvailable()' to look in a different location for
    the 'CMakeLists.txt' file.

  • The 'FindBLAS' module now provides an imported target.

  • The 'FindLAPACK' module now provides an imported target.

  • The 'FindPython3', 'FindPython2' and 'FindPython' modules:

    • gained the possibility to create per-artifact cache variables for
      interactive editing in 'cmake-gui(1)' and 'ccmake(1)'.

    • gained sub-components 'Development.Module' and 'Development.Embed'
      under the 'Development' component.

    • gained the capability to specify which Python implementations to
      find, including 'IronPython' and 'PyPy'.

  • The 'FindRuby' module input and output variables were all renamed
    from 'RUBY_' to 'Ruby_' for consistency with other find modules.
    Input variables of the old case will be honored if provided, and
    output variables of the old case are always provided.

  • The 'FindSWIG' module now accepts target languages as 'COMPONENTS'
    and 'OPTIONAL_COMPONENTS' arguments to 'find_package'.

  • The 'GoogleTest' module 'gtest_discover_tests()' command:

    • gained a new 'DISCOVERY_MODE' option to control when the test
      discovery step is run. It offers a new 'PRE_TEST' setting to run
      the discovery at test time instead of build time.

    • gained a new optional parameter 'XML_OUTPUT_DIR'. When set the
      JUnit XML test results are stored in that directory.

  • The 'FindLibXslt' module now provides imported targets.

  • The 'UseSWIG' module now supports Fortran as a target language if
    the 'SWIG_EXECUTABLE' is SWIG-Fortran.

Generator Expressions

  • The '$' and '$' 'generator
    expressions' were added to manage device and host link steps.

  • The '$' and '$' 'generator
    expressions' were added.

Cmake Generator Platform

CTest

  • 'ctest(1)' gained a new 'CTEST_RESOURCE_SPEC_FILE' variable, which
    can be used to specify a resource specification file.

  • 'ctest(1)' gained a '–stop-on-failure' option, which can be used to
    stop running the tests once one has failed.

  • The 'ctest_test()' command gained a 'STOP_ON_FAILURE' option which
    can be used to stop running the tests once one has failed.

  • The 'CTestCoverageCollectGCOV' module
    'ctest_coverage_collect_gcov()' command gained a
    'TARBALL_COMPRESSION' option to control compression of the tarball
    of collected results.

Cmake Generator Ninja

CPack

  • The 'CPack Archive Generator''s 'TXZ' format learned the
    'CPACK_ARCHIVE_THREADS' variable to enable parallel compression.
    Requires support in the 'liblzma' used by CMake.

  • The 'CPack NSIS Generator' gained a new variable
    'CPACK_NSIS_MANIFEST_DPI_AWARE' to declare that the installer is
    DPI-aware.

  • The 'CPack RPM Generator' gained 'CPACK_RPM_PRE_TRANS_SCRIPT_FILE'
    'CPACK_RPM_POST_TRANS_SCRIPT_FILE' variables to specify pre- and
    post-trans scripts.

Other

  • 'cmake-gui(1)' now populates its generator selection widget default
    value from the 'CMAKE_GENERATOR' environment variable.
    Additionally, environment variables 'CMAKE_GENERATOR_PLATFORM' and
    'CMAKE_GENERATOR_TOOLSET' are used to populate their respective
    widget defaults.

  • 'ccmake(1)' learned to read a 'CCMAKE_COLORS' environment variable
    to customize colors.

Deprecated and Removed Features

  • The 'Documentation' module has been deprecated via 'CMP0106'. This
    module was essentially VTK code that CMake should not be shipping
    anymore.

  • An explicit deprecation diagnostic was added for policy 'CMP0070'
    and policy 'CMP0071' ('CMP0069' and below were already deprecated).
    The 'cmake-policies(7)' manual explains that the OLD behaviors of
    all policies are deprecated and that projects should port to the NEW
    behaviors.

Other Changes

  • On Windows, the 'Ninja' and 'Ninja Multi-Config' generators, when a
    compiler is not explicitly specified, now select the first compiler
    (of any name) found in directories listed by the 'PATH' environment
    variable.

  • The 'LINK_OPTIONS' and 'INTERFACE_LINK_OPTIONS' target properties
    are now used for the device link step. See policy 'CMP0105'.

  • Creation of an 'ALIAS' target overwriting an existing target now
    raises an error. See policy 'CMP0107'.

  • Linking a target to itself through an alias now raises an error. See
    policy 'CMP0108'.

  • The 'FindPackageHandleStandardArgs' module option 'REQUIRED_VARS' is
    now optional if 'HANDLE_COMPONENTS' is specified.

  • The 'source_group()' command now also recognizes forward slashes as
    subgroup delimiters, not just backslashes.

  • 'ctest(1)' now logs environment variables that it sets for each
    test, either due to the 'ENVIRONMENT' property or the resource
    allocation feature, and submits this log to CDash. It does not log
    environment variables that were set outside of CTest.

  • When building CMake itself from source and not using a system-
    provided libcurl, HTTP/2 support is now enabled for commands
    supporting network communication via 'http(s)', such as
    'file(DOWNLOAD)', 'file(UPLOAD)', and 'ctest_submit()'. The
    precompiled binaries provided on 'cmake.org' now support HTTP/2.

-->

You can use Visual Studio with Clang to edit and debug C++ CMake projects that target Windows or Linux.

Windows: Visual Studio 2019 version 16.1 includes support for editing, building, and debugging with Clang/LLVM in CMake projects targeting Windows.

Linux: For Linux CMake projects, no special Visual Studio support is required. You can install Clang using your distro's package manager, and add the appropriate commands in the CMakeLists.txt file.

Install

For best IDE support in Visual Studio, we recommend using the latest Clang compiler tools for Windows. If you don't already have those, you can install them by opening the Visual Studio Installer and choosing C++ Clang compiler for Windows under Desktop development with C++ optional components. When using a custom Clang installation, check the C++ Clang-cl for v142 build tools component.

Create a new configuration

To add a new Clang configuration to a CMake project:

  1. Right-click on CMakeLists.txt in Solution Explorer and choose CMake settings for project.

  2. Under Configurations, press the Add Configuration button:

  3. Choose the desired Clang configuration (note that separate Clang configurations are provided for Windows and Linux), then press Select:

  4. To make modifications to this configuration, use the CMake Settings Editor. For more information, see Customize CMake build settings in Visual Studio.

Modify an existing configuration to use Clang

Cmake Set Default Generator

To modify an existing configuration to use Clang, follow these steps:

  1. Right-click on CMakeLists.txt in Solution Explorer and choose CMake settings for project.

  2. Under General select the Toolset dropdown and choose the desired Clang toolset:

Custom Clang locations

By default, Visual Studio looks for Clang in two places:

  • (Windows) The internally installed copy of Clang/LLVM that comes with the Visual Studio installer.
  • (Windows and Linux) The PATH environment variable.

You can specify another location by setting the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER CMake variables in CMake Settings:

Clang compatibility modes

For Windows configurations, CMake by default invokes Clang in clang-cl mode and links with the Microsoft implementation of the Standard Library. By default, clang-cl.exe is located in C:Program Files (x86)Microsoft Visual Studio2019Common7IDECommonExtensionsMicrosoftLlvmbin.

You can modify these values in CMake Settings under CMake variables and cache. Click Show advanced variables. Scroll down to find CMAKE_CXX_COMPILER, then click the Browse button to specify a different compiler path.

Edit, build, and debug

After you have set up a Clang configuration, you can build and debug the project. Visual Studio detects that you are using the Clang compiler and provides IntelliSense, highlighting, navigation, and other editing features. Errors and warnings are displayed in the Output Window.

When debugging, you can use breakpoints, memory and data visualization, and most other debugging features. Some compiler-dependent features such as Edit and Continue are not available for Clang configurations.





broken image