Skip to content

Commit

Permalink
Small fixes for conan
Browse files Browse the repository at this point in the history
* Example of cross-compilation (and fixes)
* Shorter profile names
  • Loading branch information
ytimenkov authored and whyman committed Jun 24, 2020
1 parent 13b842d commit a3a64be
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 23 deletions.
8 changes: 4 additions & 4 deletions cmake/FindFilesystem.cmake
Expand Up @@ -105,7 +105,7 @@ endif()

include(CMakePushCheckState)
include(CheckIncludeFileCXX)
include(CheckCXXSourceRuns)
include(CheckCXXSourceCompiles)

cmake_push_check_state()

Expand Down Expand Up @@ -186,20 +186,20 @@ if(CXX_FILESYSTEM_HAVE_FS)
]] code @ONLY)

# Try to compile a simple filesystem program without any linker flags
check_cxx_source_runs("${code}" CXX_FILESYSTEM_NO_LINK_NEEDED)
check_cxx_source_compiles("${code}" CXX_FILESYSTEM_NO_LINK_NEEDED)

set(can_link ${CXX_FILESYSTEM_NO_LINK_NEEDED})

if(NOT CXX_FILESYSTEM_NO_LINK_NEEDED)
set(prev_libraries ${CMAKE_REQUIRED_LIBRARIES})
# Add the libstdc++ flag
set(CMAKE_REQUIRED_LIBRARIES ${prev_libraries} -lstdc++fs)
check_cxx_source_runs("${code}" CXX_FILESYSTEM_STDCPPFS_NEEDED)
check_cxx_source_compiles("${code}" CXX_FILESYSTEM_STDCPPFS_NEEDED)
set(can_link ${CXX_FILESYSTEM_STDCPPFS_NEEDED})
if(NOT CXX_FILESYSTEM_STDCPPFS_NEEDED)
# Try the libc++ flag
set(CMAKE_REQUIRED_LIBRARIES ${prev_libraries} -lc++fs)
check_cxx_source_runs("${code}" CXX_FILESYSTEM_CPPFS_NEEDED)
check_cxx_source_compiles("${code}" CXX_FILESYSTEM_CPPFS_NEEDED)
set(can_link ${CXX_FILESYSTEM_CPPFS_NEEDED})
endif()
endif()
Expand Down
3 changes: 3 additions & 0 deletions conan/common
@@ -0,0 +1,3 @@
# Common requirements for Gerbera
[settings]
compiler.cppstd=17
1 change: 1 addition & 0 deletions conan/gerbera-dev → conan/dev
@@ -1,5 +1,6 @@
# Profile for gerbera development
include(default)
include(./common)

[settings]
build_type=Debug
Expand Down
11 changes: 11 additions & 0 deletions conan/minimal
@@ -0,0 +1,11 @@
[options]
gerbera:debug_logging=True
gerbera:tests=False
gerbera:magic=False
gerbera:taglib=False
gerbera:exif=False
gerbera:matroska=False
gerbera:curl=False
gerbera:mysql=False
gerbera:ffmpeg=False
gerbera:ffmpegthumbnailer=False
5 changes: 3 additions & 2 deletions conan/gerbera-release → conan/release
@@ -1,13 +1,14 @@
# Profile for release
include(default)
include(./common)

[settings]
build_type=RelWithDebInfo

[options]
# Build isolated static binary.
*:shared=Flase
*:shared=False
*:fPIC=False

[env]
CXXFLAGS=-O2 -Werror -Wall
CXXFLAGS=-O2 -Werror -Wall -flto
29 changes: 24 additions & 5 deletions conanfile.py
Expand Up @@ -36,7 +36,7 @@ class GerberaConan(ConanFile):
"ffmpegthumbnailer": True,
}

scm = {"type": "git"}
scm = {"type": "git", "url": "auto", "revision": "auto"}

requires = [
"fmt/6.2.1",
Expand All @@ -55,19 +55,29 @@ def configure(self):
# Moreover, if "shared" is True then main is an .so...
self.options["gtest"].no_main = True

@property
def _needs_system_uuid(self):
if self.options.ffmpeg:
os_info = tools.OSInfo()
# ffmpeg on Ubuntu has libuuid as a deep transitive dependency
# and fails to link otherwise.
return os_info.with_apt

def requirements(self):
if self.options.tests:
self.requires("gtest/1.10.0")

if self.options.js:
self.requires("duktape/2.5.0")

if not self.options.ffmpeg:
# ffmpeg has libuuid as a deep transitive dependency
# and fails to link otherwise.
if not self._needs_system_uuid:
self.requires("libuuid/1.0.3")

def system_requirements(self):
if tools.cross_building(self):
self.output.info("Cross-compiling, not installing system packages")
return

os_info = tools.OSInfo()
if os_info.with_apt:
pm = "apt"
Expand Down Expand Up @@ -154,6 +164,11 @@ def system_requirements(self):
}[pm]
)

if self._needs_system_uuid:
installer.install(
{"apt": "uuid-dev", "pacman": [], "yum": [], "freebsd": []}[pm]
)

if self.options.ffmpegthumbnailer:
installer.install(
{
Expand All @@ -178,8 +193,12 @@ def build(self):
cmake.definitions["WITH_AVCODEC"] = self.options.ffmpeg
cmake.definitions["WITH_FFMPEGTHUMBNAILER"] = self.options.ffmpegthumbnailer

if self.settings.os != "Linux":
if self.settings.os != "Linux" or tools.cross_building(self):
cmake.definitions["WITH_SYSTEMD"] = False

cmake.configure()
cmake.build()

if tools.get_env("CONAN_RUN_TESTS", True):
with tools.run_environment(self):
cmake.test(output_on_failure=True)
87 changes: 75 additions & 12 deletions doc/conan.rst
Expand Up @@ -12,7 +12,7 @@ To set up everything from scratch
Setting up Conan
----------------

From `Conan documentation <https://docs.conan.io/en/latest/installation.html>`_:
From `Conan installation instructions <https://docs.conan.io/en/latest/installation.html>`_:

.. code-block:: bash
Expand All @@ -21,7 +21,6 @@ From `Conan documentation <https://docs.conan.io/en/latest/installation.html>`_:
# Auto-detect system settings
$ conan profile new default --detect
$ conan profile update settings.compiler.cppstd=17 default
# If using gcc:
$ conan profile update settings.compiler.libcxx=libstdc++11 default
Expand All @@ -31,9 +30,9 @@ Building Gerbera

.. code-block:: bash
# Get dependencies and generate build files:
# Get dependencies (building them if needed) and generate build files:
# The commands generate build system in build/ subfolder
$ conan install -pr ./conan/gerbera-dev -if build . && conan build --configure -bf build .
$ conan install -pr ./conan/dev --build missing -if build . && conan build --configure -bf build .
# Now project is ready to build.
Expand Down Expand Up @@ -80,10 +79,6 @@ Add to ``~/.conan/profiles/default``:
CC=gcc-10
CXX=g++-10
.. note::

Most likely you need to add ``--build missing`` option to ``conan install``.

If your system has an outdated CMake
::::::::::::::::::::::::::::::::::::

Expand All @@ -99,8 +94,15 @@ Then just clean the build directory and rerun ``conan install && conan build``.
There may be no prebuilt pacakge with particular compiler / settings
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Conan has prebuilt binaries for a fairly new Linux distro (and thus libc)
which may not work on an old one.
Conan has prebuilt binaries, but they may not be suitable.
Some may be built with older C++ standard
(`conan-center-index#1984 <https://github.com/conan-io/conan-center-index/issues/1984>`_),
while others may require newer libc
(`conan-docker-tools#205 <https://github.com/conan-io/conan-docker-tools/issues/205>`_).

Therefore the most reasonable default is to build missing binary packages
(which is handled nicely by Conan).


Also you may want to build dependencies with some specific flags, for example
``-flto`` to get better codegen.
Expand All @@ -109,11 +111,11 @@ You need to run rebuild missing or all packages:

.. code-block:: bash
# Build only missing pacakges
# Build only missing packages
$ conan install --build=missing ...
# Rebuild all packages
$ conan install --build ...
$ conan install --build=force ...
See `Conan documentation <https://docs.conan.io/en/latest/reference/commands/consumer/install.html#build-options>`_.

Expand All @@ -129,6 +131,13 @@ It is also possible to define custom compile / link flags in the profile.

There is a number of profiles in the ``conan`` subfolder you can use for reference.

Cleanup
:::::::

Conan stores all data in ``$HOME/.conan`` just remove this folder to free disk space.

To remove only packages use ``conan remove -f '*'``

Searching for a package (or checking an update)
:::::::::::::::::::::::::::::::::::::::::::::::

Expand Down Expand Up @@ -171,3 +180,57 @@ Remaining system packages are managed by Conan.

It is not a good idea to build with GCC on FreeBSD since resulting binaries crash
because system uses CLang and its libc++ which is incompatible with gccs libstdc++.

Cross-building
::::::::::::::

This is an example for Raspberry Pi 3 on Ubuntu host.

.. code-block:: bash
$ apt install g++-10-aarch64-linux-gnu
$ conan profile new raspberry-pi3
Populate file with content:

.. code-block:: ini
toolchain=/usr/aarch64-linux-gnu
target_host=aarch64-linux-gnu
cc_compiler=gcc-10
cxx_compiler=g++-10
[env]
CONAN_CMAKE_FIND_ROOT_PATH=$toolchain
CHOST=$target_host
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
STRIP=$target_host-strip
[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=10
compiler.libcxx=libstdc++11
.. code-block:: bash
$ conan install -pr:b default -pr:h ./conan/release -pr:h ./conan/minimal -pr:h raspberry-pi3 --build missing -if build . && conan build --configure -bf build .
$ cd build && make
...
[100%] Linking CXX executable gerbera
[100%] Built target gerbera
build $ file gerbera
gerbera: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=7bfdb98dd51a1a5dda5101a0e9f090806fb35a41, for GNU/Linux 3.7.0, with debug_info, not stripped
$ aarch64-linux-gnu-strip -s -o gerbera-s gerbera
$ du -hs gerbera-s
3.9M gerbera-s
This is a minimal example to begin with.
If you have packages from the target system you may omit the minimal profile
or tune options on the command line.

0 comments on commit a3a64be

Please sign in to comment.