Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Path to the CMake file to process. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 2 | OECMAKE_SOURCEPATH ??= "${S}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3 | |
| 4 | DEPENDS_prepend = "cmake-native " |
| 5 | B = "${WORKDIR}/build" |
| 6 | |
| 7 | # We need to unset CCACHE otherwise cmake gets too confused |
| 8 | CCACHE = "" |
| 9 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | # C/C++ Compiler (without cpu arch/tune arguments) |
| 11 | OECMAKE_C_COMPILER ?= "`echo ${CC} | sed 's/^\([^ ]*\).*/\1/'`" |
| 12 | OECMAKE_CXX_COMPILER ?= "`echo ${CXX} | sed 's/^\([^ ]*\).*/\1/'`" |
| 13 | OECMAKE_AR ?= "${AR}" |
| 14 | |
| 15 | # Compiler flags |
| 16 | OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}" |
| 17 | OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 18 | OECMAKE_C_FLAGS_RELEASE ?= "-DNDEBUG" |
| 19 | OECMAKE_CXX_FLAGS_RELEASE ?= "-DNDEBUG" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}" |
| 21 | OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}" |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 22 | CXXFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}" |
| 23 | CFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | |
| 25 | OECMAKE_RPATH ?= "" |
| 26 | OECMAKE_PERLNATIVE_DIR ??= "" |
| 27 | OECMAKE_EXTRA_ROOT_PATH ?= "" |
| 28 | |
| 29 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "ONLY" |
| 30 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM_class-native = "BOTH" |
| 31 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 32 | EXTRA_OECMAKE_append = " ${PACKAGECONFIG_CONFARGS}" |
| 33 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | # CMake expects target architectures in the format of uname(2), |
| 35 | # which do not always match TARGET_ARCH, so all the necessary |
| 36 | # conversions should happen here. |
| 37 | def map_target_arch_to_uname_arch(target_arch): |
| 38 | if target_arch == "powerpc": |
| 39 | return "ppc" |
| 40 | if target_arch == "powerpc64": |
| 41 | return "ppc64" |
| 42 | return target_arch |
| 43 | |
| 44 | cmake_do_generate_toolchain_file() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 45 | if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then |
| 46 | cmake_crosscompiling="set( CMAKE_CROSSCOMPILING FALSE )" |
| 47 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | cat > ${WORKDIR}/toolchain.cmake <<EOF |
| 49 | # CMake system name must be something like "Linux". |
| 50 | # This is important for cross-compiling. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 51 | $cmake_crosscompiling |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` ) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 53 | set( CMAKE_SYSTEM_PROCESSOR ${@map_target_arch_to_uname_arch(d.getVar('TARGET_ARCH'))} ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} ) |
| 55 | set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} ) |
| 56 | set( CMAKE_ASM_COMPILER ${OECMAKE_C_COMPILER} ) |
| 57 | set( CMAKE_AR ${OECMAKE_AR} CACHE FILEPATH "Archiver" ) |
| 58 | set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" ) |
| 59 | set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" ) |
| 60 | set( CMAKE_ASM_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "ASM FLAGS" ) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 61 | set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "Additional CFLAGS for release" ) |
| 62 | set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "Additional CXXFLAGS for release" ) |
| 63 | set( CMAKE_ASM_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "Additional ASM FLAGS for release" ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | set( CMAKE_C_LINK_FLAGS "${OECMAKE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" ) |
| 65 | set( CMAKE_CXX_LINK_FLAGS "${OECMAKE_CXX_LINK_FLAGS}" CACHE STRING "LDFLAGS" ) |
| 66 | |
| 67 | # only search in the paths provided so cmake doesnt pick |
| 68 | # up libraries and tools from the native build machine |
| 69 | set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} ${OECMAKE_PERLNATIVE_DIR} ${OECMAKE_EXTRA_ROOT_PATH} ${EXTERNAL_TOOLCHAIN}) |
| 70 | set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY ) |
| 71 | set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM} ) |
| 72 | set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) |
| 73 | set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) |
| 74 | |
| 75 | # Use qt.conf settings |
| 76 | set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf ) |
| 77 | |
| 78 | # We need to set the rpath to the correct directory as cmake does not provide any |
| 79 | # directory as rpath by default |
| 80 | set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} ) |
| 81 | |
| 82 | # Use native cmake modules |
| 83 | list(APPEND CMAKE_MODULE_PATH "${STAGING_DATADIR}/cmake/Modules/") |
| 84 | |
| 85 | # add for non /usr/lib libdir, e.g. /usr/lib64 |
| 86 | set( CMAKE_LIBRARY_PATH ${libdir} ${base_libdir}) |
| 87 | |
| 88 | EOF |
| 89 | } |
| 90 | |
| 91 | addtask generate_toolchain_file after do_patch before do_configure |
| 92 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 93 | CONFIGURE_FILES = "CMakeLists.txt" |
| 94 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | cmake_do_configure() { |
| 96 | if [ "${OECMAKE_BUILDPATH}" ]; then |
| 97 | bbnote "cmake.bbclass no longer uses OECMAKE_BUILDPATH. The default behaviour is now out-of-tree builds with B=WORKDIR/build." |
| 98 | fi |
| 99 | |
| 100 | if [ "${S}" != "${B}" ]; then |
| 101 | rm -rf ${B} |
| 102 | mkdir -p ${B} |
| 103 | cd ${B} |
| 104 | else |
| 105 | find ${B} -name CMakeFiles -or -name Makefile -or -name cmake_install.cmake -or -name CMakeCache.txt -delete |
| 106 | fi |
| 107 | |
| 108 | # Just like autotools cmake can use a site file to cache result that need generated binaries to run |
| 109 | if [ -e ${WORKDIR}/site-file.cmake ] ; then |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 110 | oecmake_sitefile="-C ${WORKDIR}/site-file.cmake" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | else |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 112 | oecmake_sitefile= |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | fi |
| 114 | |
| 115 | cmake \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 116 | $oecmake_sitefile \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | ${OECMAKE_SOURCEPATH} \ |
| 118 | -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 119 | -DCMAKE_INSTALL_BINDIR:PATH=${@os.path.relpath(d.getVar('bindir'), d.getVar('prefix'))} \ |
| 120 | -DCMAKE_INSTALL_SBINDIR:PATH=${@os.path.relpath(d.getVar('sbindir'), d.getVar('prefix'))} \ |
| 121 | -DCMAKE_INSTALL_LIBEXECDIR:PATH=${@os.path.relpath(d.getVar('libexecdir'), d.getVar('prefix'))} \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | -DCMAKE_INSTALL_SYSCONFDIR:PATH=${sysconfdir} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 123 | -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=${@os.path.relpath(d.getVar('sharedstatedir'), d. getVar('prefix'))} \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=${localstatedir} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 125 | -DCMAKE_INSTALL_LIBDIR:PATH=${@os.path.relpath(d.getVar('libdir'), d.getVar('prefix'))} \ |
| 126 | -DCMAKE_INSTALL_INCLUDEDIR:PATH=${@os.path.relpath(d.getVar('includedir'), d.getVar('prefix'))} \ |
| 127 | -DCMAKE_INSTALL_DATAROOTDIR:PATH=${@os.path.relpath(d.getVar('datadir'), d.getVar('prefix'))} \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | -DCMAKE_INSTALL_SO_NO_EXE=0 \ |
| 129 | -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \ |
| 130 | -DCMAKE_VERBOSE_MAKEFILE=1 \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 131 | -DCMAKE_NO_SYSTEM_FROM_IMPORTED=1 \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 132 | ${EXTRA_OECMAKE} \ |
| 133 | -Wno-dev |
| 134 | } |
| 135 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 136 | do_compile[progress] = "percent" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | cmake_do_compile() { |
| 138 | cd ${B} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 139 | base_do_compile VERBOSE=1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | cmake_do_install() { |
| 143 | cd ${B} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 144 | oe_runmake 'DESTDIR=${D}' install |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file |