Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing cmake_layout single config #2891

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion creating_packages/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<path>/conan_toolchain.cmake`` argument, plus other possible arguments,
like ``-DCMAKE_BUILD_TYPE=<config>`` 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.

Expand Down
4 changes: 2 additions & 2 deletions developing_packages/editable_packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 .


Expand Down Expand Up @@ -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!
Expand Down
58 changes: 12 additions & 46 deletions integrations/cross_platform/android.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<path/to/myandroid/ndk>


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:
Expand All @@ -119,16 +121,17 @@ 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 <path/provided/via/environment/variable>)
set(CMAKE_ANDROID_NDK <path/to/myandroid/ndk>)


With this toolchain file you can execute CMake's command to generate the binaries:

.. code-block:: bash

conan install <conanfile> --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
Expand Down Expand Up @@ -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=<path/to/myandroid/ndk>``


For this, you will need a small CMake toolchain file:

Expand Down Expand Up @@ -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 <https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android>`__ 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
14 changes: 11 additions & 3 deletions migrating_to_2.0/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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<conan_tools>`.
Expand Down
4 changes: 2 additions & 2 deletions reference/conanfile/tools/cmake/cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Available since: `1.32.0 <https://github.com/conan-io/conan/releases/tag/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=<path>/conan_toolchain.cmake`` to the ``configure()`` call, as well as other possible
arguments like ``-DCMAKE_BUILD_TYPE=<config>``. The arguments that will be used are obtained from a
generated ``CMakePresets.json`` file.

Expand Down Expand Up @@ -67,7 +67,7 @@ configure()
Reads the ``CMakePresets.json`` file generated by the :ref:`CMakeToolchain<conan-cmake-toolchain>` 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=<path>/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.
Expand Down
2 changes: 1 addition & 1 deletion reference/conanfile/tools/cmake/cmakedeps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<path>/conan_toolchain.cmake -DCMAKE_MAP_IMPORTED_CONFIG_COVERAGE=Debug
19 changes: 9 additions & 10 deletions reference/conanfile/tools/cmake/cmaketoolchain.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CMakeToolchain
Available since: `1.32.0 <https://github.com/conan-io/conan/releases/tag/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=<path>/conan_toolchain.cmake``. This generator translates
the current package configuration, settings, and options, into CMake toolchain syntax.


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down