diff --git a/creating_packages/getting_started.rst b/creating_packages/getting_started.rst index 62bc0e73721f..9622d6025f71 100644 --- a/creating_packages/getting_started.rst +++ b/creating_packages/getting_started.rst @@ -108,7 +108,7 @@ Let's explain a little bit about this recipe: the Conan ``settings`` and ``options`` to CMake syntax. - The ``build()`` method uses the ``CMake`` wrapper to call CMake commands, it is a thin layer that will manage - to pass in this case the ``-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake`` argument, plus other possible arguments, + to pass in this case the ``-DCMAKE_TOOLCHAIN_FILE=/conan_toolchain.cmake`` argument, plus other possible arguments, like ``-DCMAKE_BUILD_TYPE=`` if necessary. It will configure the project and build it from source. The actual arguments that will be used are obtained from a generated ``CMakePresets.json`` file. diff --git a/developing_packages/editable_packages.rst b/developing_packages/editable_packages.rst index 599bf17f85cb..0b145874e0ff 100644 --- a/developing_packages/editable_packages.rst +++ b/developing_packages/editable_packages.rst @@ -83,7 +83,7 @@ Now the ``say/0.1@user/channel`` package is in editable mode, lets build it loca # Linux, we will only build 1 configuration $ conan install . $ cd build/Release - $ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake + $ cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake $ cmake --build . @@ -112,7 +112,7 @@ In this case we can build the ``hello`` application as usual: # Linux, we will only build 1 configuration $ conan install . $ cd build/Release - $ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake + $ cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake $ cmake --build . $ ./hello say/0.1: Hello World Release! diff --git a/integrations/cross_platform/android.rst b/integrations/cross_platform/android.rst index 459599f2d856..c6fb51a9d9fd 100644 --- a/integrations/cross_platform/android.rst +++ b/integrations/cross_platform/android.rst @@ -105,7 +105,9 @@ Use a regular profile for the *host* context: compiler.libcxx=c++_shared build_type=Release -and add Android NDK to the ``PATH`` or populate the ``CONAN_CMAKE_ANDROID_NDK`` environment variable. + [conf] + tools.android:ndk_path= + Together with the files created by the generators that make it possible to find and link the requirements, :command:`conan install` command will generate a toolchain file like the following one: @@ -119,7 +121,7 @@ requirements, :command:`conan install` command will generate a toolchain file li set(CMAKE_SYSTEM_VERSION 23) set(CMAKE_ANDROID_ARCH_ABI x86_64) set(CMAKE_ANDROID_STL_TYPE c++_shared) - set(CMAKE_ANDROID_NDK ) + set(CMAKE_ANDROID_NDK ) With this toolchain file you can execute CMake's command to generate the binaries: @@ -127,8 +129,9 @@ With this toolchain file you can execute CMake's command to generate the binarie .. code-block:: bash conan install --profile:host=profile_host --profile:build=default - cmake . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release - cmake --build . --config Release + cd build/Release + cmake ../.. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release + cmake --build . Using Docker images @@ -198,7 +201,11 @@ However, when building CMake projects, there are several approaches available, a Using toolchain from Android NDK -------------------------------- -This is the official way recommended by Android developers. +.. warning:: + + This method is deprecated. Use the one above using ``CMakeToolchain``, the generated ``conan_toolchain.cmake`` + and the conf ``tools.android:ndk_path=`` + For this, you will need a small CMake toolchain file: @@ -232,46 +239,5 @@ And then, you may use the following profile: In the profile, ``CONAN_CMAKE_TOOLCHAIN_FILE`` points to the CMake toolchain file listed above. -Using CMake built-in Android NDK support ----------------------------------------- - -.. warning:: - - This workflow is not supported by Android and is often broken with new NDK releases or when using older versions of CMake. - This workflow is **strongly discouraged** and will not work with Gradle. - -For this approach, you don't need to specify CMake toolchain file at all. It's enough to indicate ``os`` is Android -and Conan will automatically set up all required CMake -`variables `__ for you. - -Therefore, the following conan profile could be used for ``ARMv8``: - -.. code-block:: text - - include(default) - [settings] - arch=armv8 - build_type=Release - compiler=clang - compiler.libcxx=libc++ - compiler.version=7.0 - os=Android - os.api_level=21 - [tool_requires] - [options] - [env] - ANDROID_NDK_ROOT=/home/conan/android-ndk-r18b - -The only way you have to configure is ``ANDROID_NDK_ROOT`` which is a path to the Android NDK installation. - -Once profile is configured, you should see the following output during the CMake build: - -.. code-block:: text - - -- Android: Targeting API '21' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64' - -- Android: Selected Clang toolchain 'aarch64-linux-android-clang' with GCC toolchain 'aarch64-linux-android-4.9' - -It means native CMake integration has successfully found Android NDK and configured the build. - .. |android_logo| image:: ../../images/android_logo.png :width: 180px diff --git a/migrating_to_2.0/recipes.rst b/migrating_to_2.0/recipes.rst index d9f131c7b8d6..a1456d780f2e 100644 --- a/migrating_to_2.0/recipes.rst +++ b/migrating_to_2.0/recipes.rst @@ -475,10 +475,18 @@ other build systems, even a custom one, remember you should generate everything If we are using that recipe for our project we can build it by typing: .. code-block:: bash - - $ conan install . + # This will generate the config files from the dependencies and the toolchain - $ cmake . -DCMAKE_TOOLCHAIN_FILE=./cmake-build-release/conan/conan_toolchain.cmake + $ conan install . + + # Windows + $ cd build + $ cmake .. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake + $ cmake --build . --config=Release + + # Linux + $ cd build/Release + $ cmake ../.. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release $ cmake --build . You can check all the generators and toolchains for different build systems in the :ref:`tools reference page`. diff --git a/reference/conanfile/tools/cmake/cmake.rst b/reference/conanfile/tools/cmake/cmake.rst index 41eac67a0089..ea7b67dabf57 100644 --- a/reference/conanfile/tools/cmake/cmake.rst +++ b/reference/conanfile/tools/cmake/cmake.rst @@ -12,7 +12,7 @@ Available since: `1.32.0 The ``CMake`` build helper is a wrapper around the command line invocation of cmake. It will abstract the calls like ``cmake --build . --config Release`` into Python method calls. It will also add the argument -``-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake`` to the ``configure()`` call, as well as other possible +``-DCMAKE_TOOLCHAIN_FILE=/conan_toolchain.cmake`` to the ``configure()`` call, as well as other possible arguments like ``-DCMAKE_BUILD_TYPE=``. The arguments that will be used are obtained from a generated ``CMakePresets.json`` file. @@ -67,7 +67,7 @@ configure() Reads the ``CMakePresets.json`` file generated by the :ref:`CMakeToolchain` to get: - The generator, to append ``-G="xxx"``. - - The path to the toolchain and append ``-DCMAKE_TOOLCHAIN_FILE=/path/conan_toolchain.cmake`` + - The path to the toolchain and append ``-DCMAKE_TOOLCHAIN_FILE=/conan_toolchain.cmake`` - The declared ``cache variables`` and append ``-Dxxx``. - ``build_script_folder``: Relative path to the folder containing the root *CMakeLists.txt* - ``cli_args``: List of extra arguments provided when calling to CMake. diff --git a/reference/conanfile/tools/cmake/cmakedeps.rst b/reference/conanfile/tools/cmake/cmakedeps.rst index c5daf975f5c5..6e9f6c2b8337 100644 --- a/reference/conanfile/tools/cmake/cmakedeps.rst +++ b/reference/conanfile/tools/cmake/cmakedeps.rst @@ -339,4 +339,4 @@ tell CMake how to map the configurations from the current project to the importe cd build-coverage/ conan install .. -s build_type=Debug - cmake .. -DCMAKE_BUILD_TYPE=Coverage -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_MAP_IMPORTED_CONFIG_COVERAGE=Debug + cmake .. -DCMAKE_BUILD_TYPE=Coverage -DCMAKE_TOOLCHAIN_FILE=/conan_toolchain.cmake -DCMAKE_MAP_IMPORTED_CONFIG_COVERAGE=Debug diff --git a/reference/conanfile/tools/cmake/cmaketoolchain.rst b/reference/conanfile/tools/cmake/cmaketoolchain.rst index 91fc219b8c96..01c509a135a8 100644 --- a/reference/conanfile/tools/cmake/cmaketoolchain.rst +++ b/reference/conanfile/tools/cmake/cmaketoolchain.rst @@ -11,7 +11,7 @@ CMakeToolchain Available since: `1.32.0 `_ The ``CMakeToolchain`` is the toolchain generator for CMake. It will generate toolchain files that can be used in the -command line invocation of CMake with the ``-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake``. This generator translates +command line invocation of CMake with the ``-DCMAKE_TOOLCHAIN_FILE=/conan_toolchain.cmake``. This generator translates the current package configuration, settings, and options, into CMake toolchain syntax. @@ -292,19 +292,17 @@ with local development flows, than when the package is created in the cache. .. code:: bash - # Lets start in the folder containing the conanfile.py - $ mkdir build && cd build # Install both debug and release deps and create the toolchain - $ conan install .. - $ conan install .. -s build_type=Debug - # the conan_toolchain.cmake is common for both configurations + $ conan install . + $ conan install . -s build_type=Debug -If you are using a multi-configuration generator: +If you are using a multi-configuration generator (e.g. Windows MSVC): .. code:: bash + $ cd build # Need to pass the generator WITHOUT the platform, that matches your default settings - $ cmake .. -G "Visual Studio 15" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake + $ cmake .. -G "Visual Studio 15" -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake # Now you can open the IDE, select Debug or Release config and build # or, in the command line $ cmake --build . --config Release @@ -319,8 +317,9 @@ If you are using a single-configuration generator: .. code:: bash - $ cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release - $ cmake --build + $ cd build/Release + $ cmake ../.. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release + $ cmake --build . It is recommended to use the ``cmake_layout(self)`` in the ``layout()`` method of your ``conanfile.py``. If a layout