GithubHelp home page GithubHelp logo

wang-bin / cmake-tools Goto Github PK

View Code? Open in Web Editor NEW
36.0 6.0 9.0 400 KB

Cmake utilities for C++11 projects targeting Windows(host/cross build), Raspberry Pi (host/cross build), macOS, iOS, Android

License: MIT License

CMake 100.00%
raspberry-pi rpi cmake winrt android macos ios clang lld windows

cmake-tools's Introduction

Windows Cross Build via Clang-CL + LLD

toolchain file: windows.clang.cmake

MSVC ABI compatible. Supports x86, x64, arm64(clang-8+).

Requirements

  • Copy of Windows SDK, only Include and Lib are used
  • Copy of msvc sdk, only include and lib are used

Options

  • WINSDK_DIR (or environment var WindowsSdkDir): win10 sdk dir containing Include and Lib
  • WINSDK_VER (or environment var WindowsSDKVersion): win10 sdk version
  • MSVC_DIR (or environment var VCDIR): msvc dir containing include and lib
  • UWP: build for uwp
  • PHONE: build for windows phone
  • ONECORE: use onecore
  • USE_LIBCXX: use libc++ instead of msvcp

Defined CMake Vars

  • WINRT: true if UWP or PHONE is set
  • WINSTORE: same as WINRT
  • WINDOWS_DESKTOP: not WINRT
  • WINDOWS_XP: if CMAKE_SYSTEM_VERSION < 6.0

Defined C/C++ Macros

  • _WIN32_WINNT

Generic Linux Clang+LLD Toolchain

toolchain file: linux.clang.cmake

Clang(set by CMAKE_C_COMPILER or auto detect) and LLVM tools are auto detected and highest version is selected.

Options

Also applies for raspberry pi, sunxi etc.

  • USE_LIBCXX: use libc++ instead of libstdc++
  • USE_CXXABI: can be c++abi, stdc++ and supc++. Only required if libc++ is built with none abi
  • USE_COMPILER_RT: use compiler-rt instead of libgcc as compiler runtime library
  • USE_STDCXX: libstdc++ version to use, MUST be >= 4.8. default is 0, selected by compiler
  • LINUX_SYSROOT: sysroot dir

Legacy Raspberry Pi Host/Cross Build via Clang + LLD

toolchain file: rpi.clang.cmake

NOTE: using linux.clang.cmake and a generic linux sysroot is enough for a modern arm64 rpi OS. Legacy rpi(1~3) includes brcm libraries.

Requirements

Options

  • USE_LIBCXX (optional, default off): use libc++ instead of libstdc++

Defined CMake Vars

  • CMAKE_SYSTEM_PROCESSOR: armv6
  • RPI: 1
  • OS: rpi
  • CMAKE_CROSSCOMPILING: auto detected

Defined C/C++ Macros

  • OS_RPI

iOS

toolchain file: ios.cmake (https://github.com/wang-bin/ios.cmake)

Options

  • IOS_ARCH: can be armv7, arm64, i386, x86_64 and any combination of above, e.g. "arm64;x86_64" to build universal 64bit binaries
  • IOS_BITCODE (optional, default off)
  • IOS_EMBEDDED_FRAMEWORK (optional, default off)
  • IOS_DEPLOYMENT_TARGET (optional)

Additional Tools

include(tools.cmake) after project(...)

Features

  • Dead code elimination
  • ELF hardened (through option ELF_HARDENED, default is on)
  • ELF separated debug symbol
  • Windows XP support for VC (through option WINDOWS_XP, default is on)
  • Android system stdc++ dependency removal
  • LTO: USE_LTO=thin/0/1/N/AUTO, default is off
  • C++11 support for macOS 10.7
  • asan, ubsan
  • uninstall template

Defined CMake Vars

  • ARCH: x86, x64, ${ANDROID_ABI}, empty for apple multi-arch build
  • WINRT, WINSTORE
  • OS=rpi, iOS, macOS, WinRT, android

Functions

  • enable_ldflags_if
  • mkdsym: create elf debug symbol file
  • mkres: convert any binary to C/C++ byte array
  • set_relocatable_flags: enable relocatable object target
  • exclude_libs_all: forbid exporting symbols from static dependencies
  • set_rpath: rpath/runpath flags for ELF and Mach-O
  • target_sources: compatible implementation for cmake < 3.1

Defined C Macros

  • OS_RPI: if build for raspberry pi

cmake-tools's People

Contributors

wang-bin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cmake-tools's Issues

直接修改CMAKE_${LANG}_FLAGS_MINSIZEREL_INIT无效

根据我的测试,直接修改CMAKE_C_FLAGS_MINSIZEREL_INITCMAKE_CXX_FLAGS_MINSIZEREL_INIT是不管用的,生成的Makefile里还是-O1,没有变成-Xclang -Oz

我自己的做法是直接替换CMAKE_${LANG}_FLAGS_MINSIZEREL中的参数:string(REGEX REPLACE "[-|/]O[1|s]" "-Xclang -Oz" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}"),这样做是有效的。

[Bug] windows上的target设置有问题

--target=${TRIPLE_ARCH}-windows-msvc

这一行设置的target有问题。我写的程序在连接Qt静态库时会报非常多的警告,说程序的target是x86_64-unknown-windows-msvc,与Qt库的x86_64-pc-windows-msvc不匹配。正常的target是x86_64-pc-windows-msvc,您落下了一个-pc-。其实编译程序是没问题的,但有些情况会出现大量警告,不好看。

[Bug] project的LANGUAGES设置为CXX后报错

如题,如果使用类似的语句project(demo VERSION 1.0 LANGUAGES CXX),再包含您的脚本,cmake会报错。看错误信息大概是您的脚本在某处要检查C语言的相关参数导致的。

macOS和Android支持的问题?

这个repo的描述里提到还支持macOS和Android,但这个repo里明显没有这两个平台相关的cmake脚本啊,是描述有误还是暂时还没有添加相关的脚本?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.