Build Windows exe using Travis CI - c++

I work on MacOS Catalina but want to build a .exe file to run on Windows from a very simple Github repo (https://github.com/hect1995/TimerShutDown) that I have created.
To accomplish that I have been recommended to use Travis CI and I have used https://frame.42yeah.me/2020/02/27/travis-ci.html as a resource.
Following the instructions I have created in my repo a CMakeList.txt, run_command_and_apply_environment_differences.sh and vcvars64_vs2017.bat as stated in the link I have included.
My .travis.yml looks like:
language: cpp
compiler: cl
os: windows
script:
- source ./run_command_and_apply_environment_differences.sh "call vcvars64_vs2017.bat"
- mkdir build
- cd build
- cmake -G "NMake Makefiles" ..
- nmake all
- 7z a meli.zip timer.exe
- ls
deploy:
provider: releases
api_key:
secure: ..........
file: meli
on:
repo: hect1995/TimerShutDown
skip_cleanup: 'true'
And my CMakeList.txt as:
cmake_minimum_required(VERSION 3.5)
project(TimerShutDown LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
SET(CMAKE_CXX_FLAGS "-static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
set(CMAKE_CXX_STANDARD 17)
add_executable(timer TimerShutDown.cpp)
Once I commit and check the travis-ci web interface I get:
travis_fold:start:worker_info
[0K[33;1mWorker information[0m
hostname: 0a9b350c-fad0-45cb-9460-07436dfaa8c5#1.worker-com-78f4bfd8fc-999g5.gce-production-3
version: v6.2.17 https://github.com/travis-ci/worker/tree/bc420764f334fe0d096a417c80426f672f1b7d18
instance: travis-job-22a790f3-b69e-4c16-95ff-7a5c39d100e9 travis-ci-windows-1809-containers-1591408217-f1e3a578 (via amqp)
startup: 6.220642644s
travis_fold:end:worker_info
[0KSecret environment variables are not obfuscated on Windows, please refer to our documentation: https://docs.travis-ci.com/user/best-practices-security[0m
travis_time:start:08c2f9c3
[0Ktravis_time:end:08c2f9c3:start=1592513335826403700,finish=1592513335867923800,duration=41520100,event=check_unsupported
[0Ktravis_time:start:0a2e492a
[0Ktravis_time:end:0a2e492a:start=1592513335919029900,finish=1592513335964019600,duration=44989700,event=apt_get_update
[0Ktravis_time:start:0e5b6a63
[0K[33;1mDisabling Windows Defender[0m
$ powershell -Command Set-MpPreference -DisableArchiveScanning \$true
$ powershell -Command Set-MpPreference -DisableRealtimeMonitoring \$true
$ powershell -Command Set-MpPreference -DisableBehaviorMonitoring \$true
travis_time:end:0e5b6a63:start=1592513336019322100,finish=1592513339154518800,duration=3135196700,event=disable_windows_defender
[0Ktravis_time:start:1c7b39bb
[0Ktravis_time:start:0b71264a
[0Ktravis_time:end:0b71264a:start=1592513339242016100,finish=1592513339421355800,duration=179339700,event=checkout
[0K
travis_fold:start:git.checkout
[0Ktravis_time:start:1ce7f0fb
[0K$ git clone --depth=50 --branch=v0.0.4 https://github.com/hect1995/TimerShutDown.git hect1995/TimerShutDown
Cloning into 'hect1995/TimerShutDown'...
travis_time:end:1ce7f0fb:start=1592513339465777600,finish=1592513340475370500,duration=1009592900,event=checkout
[0K$ cd hect1995/TimerShutDown
$ git checkout -qf v0.0.4
travis_fold:end:git.checkout
[0K
travis_time:end:1ce7f0fb:start=1592513339465777600,finish=1592513340558803300,duration=1093025700,event=checkout
[0Ktravis_time:start:12ce5e00
[0Ktravis_time:end:12ce5e00:start=1592513340603049300,finish=1592513340697202800,duration=94153500,event=env
[0K$ export TRAVIS_COMPILER=cl
$ export CXX=${CXX:-g++}
$ export CXX_FOR_BUILD=${CXX_FOR_BUILD:-g++}
$ export CC=${CC:-gcc}
$ export CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
$ cl --version
travis_time:start:019a62ca
[0K$ source ./run_command_and_apply_environment_differences.sh "call vcvars64_vs2017.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
Note: switching to '1f96e37cfa4189eb2d530b3eb6e46b9564db98e4'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
/c/Users/travis/.travis/functions: line 109: cl: command not found
[vcvarsall.bat] Environment initialized for: 'x64'
travis_time:end:019a62ca:start=1592513340757640300,finish=1592513343086851000,duration=2329210700,event=script
[0K[32;1mThe command "source ./run_command_and_apply_environment_differences.sh "call vcvars64_vs2017.bat"" exited with 0.[0m
travis_time:start:222e0a23
[0K$ mkdir build
travis_time:end:222e0a23:start=1592513343136725800,finish=1592513343204528000,duration=67802200,event=script
[0K[32;1mThe command "mkdir build" exited with 0.[0m
travis_time:start:192a9422
[0K$ cd build
travis_time:end:192a9422:start=1592513343252251400,finish=1592513343290164500,duration=37913100,event=script
[0K[32;1mThe command "cd build" exited with 0.[0m
travis_time:start:2a620736
[0K$ cmake -G "NMake Makefiles" ..
-- The CXX compiler identification is GNU 8.1.0
-- Check for working CXX compiler: C:/ProgramData/chocolatey/bin/g++.exe
-- Check for working CXX compiler: C:/ProgramData/chocolatey/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/travis/build/hect1995/TimerShutDown/build
travis_time:end:2a620736:start=1592513343338398100,finish=1592513348864636400,duration=5526238300,event=script
[0K[32;1mThe command "cmake -G "NMake Makefiles" .." exited with 0.[0m
travis_time:start:01d1e05c
[0K$ nmake all
[35m[1mScanning dependencies of target timer[0m
[ 50%] [32mBuilding CXX object CMakeFiles/timer.dir/timerShutDown.cpp.obj[0m
Microsoft (R) Program Maintenance Utility Version 14.16.27040.0
Copyright (C) Microsoft Corporation. All rights reserved.
[100%] [32m[1mLinking CXX executable timer.exe[0m
[100%] Built target timer
travis_time:end:01d1e05c:start=1592513348905598500,finish=1592513350870157200,duration=1964558700,event=script
[0K[32;1mThe command "nmake all" exited with 0.[0m
travis_time:start:06594c54
[0K$ 7z a meli.zip timer.exe
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive:
1 file, 2498445 bytes (2440 KiB)
Creating archive: meli.zip
Add new data to archive: 1 file, 2498445 bytes (2440 KiB)
Files read from disk: 1
Archive size: 503613 bytes (492 KiB)
Everything is Ok
travis_time:end:06594c54:start=1592513350920836900,finish=1592513351519863900,duration=599027000,event=script
[0K[32;1mThe command "7z a meli.zip timer.exe" exited with 0.[0m
travis_time:start:13e54c19
[0K$ ls
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
meli.zip
timer.exe
travis_time:end:13e54c19:start=1592513351570897100,finish=1592513351641789200,duration=70892100,event=script
[0K[32;1mThe command "ls" exited with 0.[0m
travis_fold:start:dpl_0
[0Ktravis_time:start:134a70da
[0K$ ruby -S gem install dpl
Successfully installed dpl-1.10.15
Parsing documentation for dpl-1.10.15
Installing ri documentation for dpl-1.10.15
Done installing documentation for dpl after 0 seconds
1 gem installed
travis_time:end:134a70da:start=1592513352196029100,finish=1592513354677945800,duration=2481916700,event=after_success
[0Ktravis_fold:end:dpl_0
[0Ktravis_time:start:18a15679
[0KSuccessfully installed multipart-post-2.1.1
Successfully installed faraday-0.15.4
Successfully installed public_suffix-3.0.3
Successfully installed addressable-2.7.0
Successfully installed sawyer-0.8.2
Successfully installed octokit-4.6.2
Successfully installed mime-types-data-3.2020.0512
Successfully installed mime-types-3.3.1
Successfully installed dpl-releases-1.10.15
Parsing documentation for multipart-post-2.1.1
Installing ri documentation for multipart-post-2.1.1
Parsing documentation for faraday-0.15.4
Installing ri documentation for faraday-0.15.4
Parsing documentation for public_suffix-3.0.3
Installing ri documentation for public_suffix-3.0.3
Parsing documentation for addressable-2.7.0
Installing ri documentation for addressable-2.7.0
Parsing documentation for sawyer-0.8.2
Installing ri documentation for sawyer-0.8.2
Parsing documentation for octokit-4.6.2
Installing ri documentation for octokit-4.6.2
Parsing documentation for mime-types-data-3.2020.0512
Installing ri documentation for mime-types-data-3.2020.0512
Parsing documentation for mime-types-3.3.1
Installing ri documentation for mime-types-3.3.1
Parsing documentation for dpl-releases-1.10.15
Installing ri documentation for dpl-releases-1.10.15
Done installing documentation for multipart-post, faraday, public_suffix, addressable, sawyer, octokit, mime-types-data, mime-types, dpl-releases after 4 seconds
9 gems installed
travis_fold:start:dpl.1
[33mInstalling deploy dependencies[0m
C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/faraday-0.15.4/lib/faraday/rack_builder.rb:55: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
The system cannot find the path specified.
The system cannot find the path specified.
Logged in as Hector Esteban
Deploying to repo: hect1995/TimerShutDown
Current tag is: v0.0.4
travis_fold:end:dpl.1
travis_fold:start:dpl.2
[33mPreparing deploy[0m
travis_fold:end:dpl.2
travis_fold:start:dpl.3
[33mDeploying application[0m
travis_fold:end:dpl.3
travis_time:end:18a15679:start=1592513354767121800,finish=1592513366965795700,duration=12198673900,event=after_success
[0K
Done. Your build exited with 0.
Setting target_commitish to 1f96e37cfa4189eb2d530b3eb6e46b9564db98e4
The problem is:
If I run on Windows timer.exe I get:
The code execution cannot proceed because `libwinpthread-1.dll` not found. Reinstalling the program may fix this problem
I have followed how to do static linking of libwinpthread-1.dll in mingw? and did:
SET(CMAKE_CXX_FLAGS "-static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
But still gives error in Windows.
What am I doing wrong?

Related

Building Doxygen on MSYS2 - Failing building CXX object portable.cpp

I'm trying to build doxygen from source, with MSYS2.
I've installed make, bison, flex, and libiconv using the command $ pacman -S <package> and I've installed gcc, cmake and ninja using the explicit environment naming, e.g. $ pacman -S mingw-w64-ucrt-x86_64-<package>.
The build procedure:
git clone https://github.com/doxygen/doxygen.git
cd doxygen
mkdir build
cd build
cmake -G "MSYS Makefiles" ..
make
I'm getting 24% ready without warnings, but when building portable.cpp I get errors. The CMakeError.log shows two failures:
Determining if the function iconv_open exists failed
Performing C++ SOURCE FILE Test ICONV_ACCEPTS_CONST_INPUT failed
I've tried to install the iconv library using both the short libiconv name and the mingw-w64-ucrt-x86_64-iconv name.

CMake unable to find a build program corresponding to "Ninja"

I have MacOS Catalina, Cmake, Ninja and QtCreator installed with the following versions and paths:
[#bin]$ sw_vers -productVersion
10.15.6
[#bin]$ which cmake
/usr/local/bin/cmake
[#bin]$ cmake --version
cmake version 3.18.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
[#bin]$ which ninja
/usr/local/bin/ninja
I'm trying to build a project with QT creator using Cmake. However, the following message appears in QT Creator
Running /usr/local/Cellar/cmake/3.18.2/bin/cmake '-GCodeBlocks - Ninja' -C /private/var/folders/jq/yyp9q2fs1z5780k9l1_2ph4r0000gn/T/QtCreator-HXderc/qtc-cmake-TuClFWan/qtcsettings.cmake /Users/mymac/Documents/programming/Cpp/Qt/try6 in /private/var/folders/jq/yyp9q2fs1z5780k9l1_2ph4r0000gn/T/QtCreator-HXderc/qtc-cmake-TuClFWan.
loading initial cache file /private/var/folders/jq/yyp9q2fs1z5780k9l1_2ph4r0000gn/T/QtCreator-HXderc/qtc-cmake-TuClFWan/qtcsettings.cmake
-- Configuring incomplete, errors occurred!
See also "/private/var/folders/jq/yyp9q2fs1z5780k9l1_2ph4r0000gn/T/QtCreator-HXderc/qtc-cmake-TuClFWan/CMakeFiles/CMakeOutput.log".
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake process exited with exit code 1.
Elapsed time: 00:00.
As indicated on several websites (such as this SO question I tried the following command but it didn't work:
[#bin]$ ln -s /usr/bin/ninja /usr/bin/ninja-build
ln: /usr/bin/ninja-build: Operation not permitted
As indicated in the comments I tried also the following:
[#bin]$ sudo ln -s /usr/bin/ninja /usr/bin/ninja-build
Password:
ln: /usr/bin/ninja-build: Operation not permitted
I also tried:
[#bin]$ sudo ln -s /usr/bin/ninja /usr/local/bin/ninja-build
It didn't cause any error message but the problem in QT creator persisted

How to use clang-10 or gcc-10 when building via Github Actions?

I'm writing a library in C++ that implements a few different coroutine primitives, and the library is targeted at the newly released C++20. As a result, it also makes use of things like concepts that were added to the language in C++20.
I want to use github actions to build the library, but builds are failing because ubuntu-latest uses GCC 9 and CLang 9, but my library requires at least GCC 10 or Clang 10 to build.
I attempted to configure the build action by setting -DCMAKE_CXX_COMPILER=g++-10, but the action fails in the Configure CMake phase because g++-10 can't be found on the system.
Is there any way specify github actions should use GCC 10 or Clang 10?
This is the most recent workflow file I tried running:
name: CMake
on: [push]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE
And this is the point where it fails:
Run cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
The CMAKE_CXX_COMPILER:
g++-10
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/runner/work/conduit/build/CMakeFiles/CMakeOutput.log".
See also "/home/runner/work/conduit/build/CMakeFiles/CMakeError.log".
##[error]Process completed with exit code 1.
As Some programmer dude mentioned, installing g++ from apt is the way to go (unless it's installed by default); adds a minute or two to the build. Then you can tell cmake which compiler it should use by passing CC and CXX variables during configure step:
- run: |
sudo apt update
sudo apt install gcc-10 g++-10
shell: bash
# ... #
- run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
shell: bash
env:
CC: gcc-10
CXX: g++-10
Same solution applies when you want to use clang.
I am using both gcc-9 and clang-10 for C (only) project.
- name: Setup dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install -y gcc-9 llvm-10 clang-10
sudo update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-9 100 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-9 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-9 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-9
sudo update-alternatives \
--install /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-10 100 \
--slave /usr/bin/llvm-ranlib llvm-ranlib /usr/bin/llvm-ranlib-10 \
--slave /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-10
sudo update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-10 100
PS you need to update more alternatives for C++ project, just example.
You can see what's installed by visiting https://github.com/actions/virtual-environments.
If you're trying this in 2022, now ubuntu-latest has "GNU C++ 9.3.0, 10.3.0". g++ is linked to version 9, but g++-10 is available on the PATH without any extra installation steps.

How to build the latest clang-tidy?

I've tried to build clang-tidy from sources but it complains about an undefined CMake command:
CMake Error at clang-apply-replacements/CMakeLists.txt:5 (add_clang_library):
Unknown CMake command "add_clang_library".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.9)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
How can I build clang-tidy or, alternatively, how can I install the latest version on macOS?
Up-to-date steps:
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
make install clang-tidy
Reference, ninja, and other details: my own blog post.
EDIT: this answer is out of date — the LLVM project has moved to a single git repository at https://github.com/llvm/llvm-project. See answers below for updated instructions.
clang-tidy is intended to be built inside a checkout of llvm/clang, and depends on CMake macros from the llvm project. You should check out the llvm repo, then the clang repo inside llvm/tools/clang, then the clang-tools-extra repo inside llvm/tools/clang/tools/extra. Then you can run CMake on the top-level directory, and make clang-tidy should work.
If you're not interested in building it yourself, it looks like the Homebrew formula for LLVM also includes the extra tools: https://github.com/Homebrew/homebrew-core/blob/382d3defb5bc48ce2dccd17261be70c4ada9a124/Formula/llvm.rb#L181
I had same problem as Per Mildner. Got is solved with slightly modified code YvesgereY posted (I don't have enough reputation to post a comment to that answer, hence a new answer instead).
In short, I added -G "Unix Makefiles" to cmake. Without this option, no makefile will be generated. Also, I used -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;". It didn't work when just clang-tools-extra was specified.
Here is the whole snippet:
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;" ../llvm
make -j8 install-clang-tidy
#jtbandes: Thank you for the information.
I'd like to share these explicit steps for us noobs:
1. Download the released sources from LLVM Download Page
LLVM source code -> Links to the file llvm-6.0.0.src.tar.xz
Clang source code -> Links to the file cfe-6.0.0.src.tar.xz
clang-tools-extra -> Links to the file clang-tools-extra-6.0.0.src.tar.xz
2. Detar each of these into the proper directory:
$ tar -zxvf <download_dir_path>/llvm-6.0.1.src.tar.xz
$ cd llvm-6.0.1.src/tools
$ tar -zxcf <download_dir_path>/cfe-6.0.1.src.tar.xz
$ cd llvm-6.0.1.src/tools/cfe-6.0.1.src/tools
$ tar -zxvf <download_dir_path>/clang-tools-extra-6.0.1.src.tar.xz
Results in a directory llvm-6.0.1.src/tools/cfe-6.0.1.src/tools/clang-tools-extra-6.0.1.src/clang-tidy; Which is incorrect. The lang-tools-extra-6.0.1.src needs to be renamed to extra (as mentioned by #jtbandes).
3. So rename it or provide a symbolic link:
$ cd llvm-6.0.1.src/tools/cfe-6.0.1.src/tools
$ mv clang-tools-extra-6.0.1.src extra
or
$ ln -s clang-tools-extra-6.0.1.src extra
The path llvm-6.0.1.src/tools/cfe-6.0.1.src/tools/extra/clang-tidy should now be valid
4. Build it:
$ cd llvm-6.0.1.src
$ mkdir build
$ cd build
$ cmake ..
$ make
Everything should make without errors or warnings.
5. Build Output:
The build output can be found in llvm-6.0.1.src/build/bin.
For everyone who are looking for latest (LLVM 11) Windows build instructions (ensure CMake, Visual Studio 2019 and git are installed and set in PATH):
git clone --config core.autocrlf=false https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -Thost=x64 -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
cmake --build . --target clang-tidy --config RelWithDebInfo --parallel
cmake --build . --target clang-query --config RelWithDebInfo --parallel
This worked for me:
mkdir build
files="
llvm-12.0.1.src.tar.xz
clang-12.0.1.src.tar.xz
clang-tools-extra-12.0.1.src.tar.xz
"
for f in $files; do
echo "Untar $f"
tar xf $f
done
mv llvm-12.0.1.src llvm
mv clang-12.0.1.src llvm/tools/clang
mv clang-tools-extra-12.0.1.src llvm/tools/clang/tools/extra
cd build
cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/llvm \
-DCLANG_BUILD_TOOLS=ON \
../llvm
make -j16 install
As of LLVM 14.0.0, sparse checkouts do no longer work (at least temporarily) and the top-level directory contains no CMakeLists.txt. I believe the tree layout has changed after LLVM 13.0.1. In consequence, none of the approaches here worked without quite some modification.
Here is how you can build version 15.0.0git (the most recent at the time of this writing). See related issue: https://github.com/llvm/llvm-project/issues/53281.
First, get the compressed code or clone with git (slower)
$ wget "https://github.com/llvm/llvm-project/archive/refs/heads/main.zip" -O llvm.zip
$ unzip llvm.zip
As usual, create a build directory and run cmake in the llvm directory.
$ mkdir /build
$ cd /build
$ cmake -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/usr/local/llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
/llvm-project-main/llvm
Navigate downwards in the generated files and only build clang-tidy.
$ cd /build/tools/clang/tools/extra/clang-tidy
$ make install
Cmake will install to /usr/local/llvm. Also, if you want to check out a specific version, use tags in the first step like this:
$ wget "https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-14.0.0.zip"
Note that you need to supply the matching builtin headers for running clang-tidy, which are located in GitHub under llvm-project/clang/lib/Headers and can by pointed to with -extra-arg=-I/path/to/builtin/headers.

How to build flatbuffers on OSX?

I'm trying to build flatbuffers on OSX but I'm not sure how to proceed exactly. According to the doc. I should run cmake -G "Xcode". I did that and got the result:
-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: Temp/flatbuffers
However from there I'm not sure what to do. I've tried to run make but got the error message make: *** No targets specified and no makefile found. Stop.. Any idea how to build it?
When you ran cmake, you generated a project for the Xcode IDE (downloadable from the Apple app store).
If you want to build using make, use this command instead:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
After that,
make
should work as intended.
Instead make, just run following command in the shell:
$ cmakexbuild
After it finish you will get flatc in ./Debug folder.
On OSX it's recommended to use Homebrew to install the flatbuffer schema compiler.
brew install flatbuffers
Usage: Using the schema compiler
For Mac-OSX
Make sure Xcode is already installed in your machine. If not, install it by executing command xcode-select --install.
If you need latest changes download source code from repo or to get source code for a particular version download source from here
cd flatbuffers and execute cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release
If you encounter error like
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeOutput.log".
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeError.log".
Inside the log file CMakeError.log:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
then refer this SO thread
success message is :
-- Configuring done
-- Generating done
-- Build files have been written to: <source-code-path>/standalone/flatbuffers-1.12.0
./FlatBuffers.xcodeproj or open project in xcode
Build and Run project from Xcode UI
cd Debugand you can see all the binaries present.
If you want flatc to be available globally:
ln -sf <path>/flatbuffers-1.12.0/Debug/flatc /usr/local/bin/flatc
Tried and Tested on
MacOSX: Mojave, version: 10.14.3, 10.14.6
Xcode: Version: 10.2.1(10E1001), 11.1(11A1027)
Note: Make sure you use the same version in a project for compatibility.
If you are not sure which version to pick, then you can clone the repo and go to a specific commit and build.
For e.g. For version 1.11, Commit version is bf9eb67a.
Follow the below steps to compile the flatbuffer code
Clone the Flatbuffer repo using - git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles"
make
FlatBuffers for LINUX(Ubuntu 16) install and build:
cd root project folder
yarn add flatc
cd node_modules of project
rm flatbuffers folder(if exist)
git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles" (install cmake if need)
make
cd root project folder
change path in command in package.json file from "./flatc" to "./node_modules/flatbuffers/flatc"