blob: 5c04cd869db2a339baa04837bb07718f06d7739d [file] [log] [blame] [view]
Volodymyr Gotra54993292017-12-18 02:08:09 +02001# Build Thrift IDL compiler using CMake
Pascal Bach6eb015a2014-04-17 16:19:07 +02002
Volodymyr Gotra54993292017-12-18 02:08:09 +02003<!-- TOC -->
James E. King, III330b3f82017-01-23 08:52:04 -05004
Volodymyr Gotra54993292017-12-18 02:08:09 +02005- [Build Thrift IDL compiler using CMake](#build-thrift-idl-compiler-using-cmake)
6 - [Build on Unix-like System](#build-on-unix-like-system)
7 - [Prerequisites](#prerequisites)
8 - [Build using CMake](#build-using-cmake)
9 - [Build with Eclipse IDE](#build-with-eclipse-ide)
10 - [Build with XCode IDE in MacOS](#build-with-xcode-ide-in-macos)
11 - [Usage of other IDEs](#usage-of-other-ides)
12 - [Build on Windows](#build-on-windows)
13 - [Prerequisites](#prerequisites-1)
14 - [Build using Git Bash](#build-using-git-bash)
15 - [Using Visual Studio and Win flex-bison](#using-visual-studio-and-win-flex-bison)
16 - [Cross compile using mingw32 and generate a Windows Installer with CPack](#cross-compile-using-mingw32-and-generate-a-windows-installer-with-cpack)
17- [Other cases](#other-cases)
18 - [Building the Thrift IDL compiler in Windows without CMake](#building-the-thrift-idl-compiler-in-windows-without-cmake)
19- [Unit tests for compiler](#unit-tests-for-compiler)
20 - [Using boost test](#using-boost-test)
21 - [Using Catch C++ test library](#using-catch-c-test-library)
22- [Have a Happy free time and holidays](#have-a-happy-free-time-and-holidays)
James E. King, III330b3f82017-01-23 08:52:04 -050023
Volodymyr Gotra54993292017-12-18 02:08:09 +020024<!-- /TOC -->
25
26## Build on Unix-like System
27
28### Prerequisites
29- Install CMake
30- Install flex and bison
31
32### Build using CMake
33
34- Go to **thrift\compiler\cpp**
35- Use the following steps to build using cmake:
Pascal Bach6eb015a2014-04-17 16:19:07 +020036
James E. King, III330b3f82017-01-23 08:52:04 -050037```
Volodymyr Gotra54993292017-12-18 02:08:09 +020038mkdir cmake-build && cd cmake-build
James E. King, III330b3f82017-01-23 08:52:04 -050039cmake ..
40make
41```
henrique55087a42014-06-17 12:36:39 +020042
Volodymyr Gotra54993292017-12-18 02:08:09 +020043#### Build with Eclipse IDE
44
45- Go to **thrift\compiler\cpp**
46- Use the following steps to build using cmake:
henrique55087a42014-06-17 12:36:39 +020047
James E. King, III330b3f82017-01-23 08:52:04 -050048```
49mkdir cmake-ec && cd cmake-ec
50cmake -G "Eclipse CDT4 - Unix Makefiles" ..
51make
52```
henrique55087a42014-06-17 12:36:39 +020053
Roger Meier880a2b32015-05-16 22:40:17 +020054Now open the folder cmake-ec using eclipse.
henrique55087a42014-06-17 12:36:39 +020055
Volodymyr Gotra54993292017-12-18 02:08:09 +020056#### Build with XCode IDE in MacOS
henrique55087a42014-06-17 12:36:39 +020057
Volodymyr Gotra54993292017-12-18 02:08:09 +020058- Install/update flex, bison and cmake with brew
59
60```
61brew install cmake
62brew install bison
63```
64
65- Go to **thrift\compiler\cpp**
66- Run commands in command line:
67
68```
69mkdir cmake-build && cd cmake-build
James E. King III29f7f8f2019-01-26 09:15:19 -050070cmake -G "Xcode" ..
Volodymyr Gotra54993292017-12-18 02:08:09 +020071cmake --build .
72```
73
74#### Usage of other IDEs
75
76Please check list of supported IDE
77
78```
79cmake --help
80```
81
82## Build on Windows
83
84### Prerequisites
85- Install CMake - https://cmake.org/download/
86- In case if you want to build without Git Bash - install winflexbison - https://sourceforge.net/projects/winflexbison/
87- In case if you want to build with Visual Studio - install Visual Studio
88 - Better to use the latest stable Visual Studio Community Edition - https://www.visualstudio.com/vs/whatsnew/ (ensure that you installed workload "Desktop Development with C++" for VS2017) - Microsoft added some support for CMake and improving it in Visual Studio
89
90### Build using Git Bash
91
92Git Bash provides flex and bison
93
94- Go to **thrift\compiler\cpp**
95- Use the following steps to build using cmake:
96
97```
98mkdir cmake-vs && cd cmake-vs
99cmake -DWITH_SHARED_LIB=off ..
100cmake --build .
101```
102
103### Using Visual Studio and Win flex-bison
104
105- Generate a Visual Studio project for version of Visual Studio which you have (**cmake --help** can show list of supportable VS versions):
106- Run commands in command line:
107```
108mkdir cmake-vs
109cd cmake-vs
James E. King III29f7f8f2019-01-26 09:15:19 -0500110cmake -G "Visual Studio 15 2017" ..
Volodymyr Gotra54993292017-12-18 02:08:09 +0200111```
112- Now open the folder cmake-vs using Visual Studio.
113
114### Cross compile using mingw32 and generate a Windows Installer with CPack
henrique55087a42014-06-17 12:36:39 +0200115
James E. King, III330b3f82017-01-23 08:52:04 -0500116```
117mkdir cmake-mingw32 && cd cmake-mingw32
James E. King IIIb1d63e72019-01-22 14:16:39 -0500118cmake -DCMAKE_TOOLCHAIN_FILE=../build/cmake/mingw32-toolchain.cmake -DBUILD_COMPILER=ON -DBUILD_LIBRARIES=OFF -DBUILD_TESTING=OFF ..
James E. King, III330b3f82017-01-23 08:52:04 -0500119cpack
120```
Roger Meier87202602014-08-15 22:16:02 +0200121
Volodymyr Gotra54993292017-12-18 02:08:09 +0200122# Other cases
Pascal Bach6eb015a2014-04-17 16:19:07 +0200123
Volodymyr Gotra54993292017-12-18 02:08:09 +0200124## Building the Thrift IDL compiler in Windows without CMake
James E. King, III330b3f82017-01-23 08:52:04 -0500125
Volodymyr Gotra54993292017-12-18 02:08:09 +0200126If you don't want to use CMake you can use the already available Visual Studio 2010 solution.
Roger Meier86fded22015-05-15 12:01:38 +0200127
Volodymyr Gotra54993292017-12-18 02:08:09 +0200128The Visual Studio project contains pre-build commands to generate the thriftl.cc, thrifty.cc and thrifty.hh files which are necessary to build the compiler.
Roger Meier86fded22015-05-15 12:01:38 +0200129
Volodymyr Gotra54993292017-12-18 02:08:09 +0200130These depend on bison, flex and their dependencies to work properly.
Roger Meier86fded22015-05-15 12:01:38 +0200131
Volodymyr Gotra54993292017-12-18 02:08:09 +0200132Download flex & bison as described above.
Pascal Bach6eb015a2014-04-17 16:19:07 +0200133
Volodymyr Gotra54993292017-12-18 02:08:09 +0200134Place these binaries somewhere in the path and rename win_flex.exe and win_bison.exe to flex.exe and bison.exe respectively.
Nobuaki Sukegawad8c6a842016-10-02 14:21:55 +0900135
136If this doesn't work on a system, try these manual pre-build steps.
Roger Meier746952e2014-06-14 21:59:24 +0200137
Volodymyr Gotra54993292017-12-18 02:08:09 +0200138Open compiler.sln and remove the Pre-build commands under the project's: Properties -> Build Events -> Pre-Build Events.
Roger Meier746952e2014-06-14 21:59:24 +0200139
Roger Meier746952e2014-06-14 21:59:24 +0200140From a command prompt:
James E. King, III330b3f82017-01-23 08:52:04 -0500141```
142cd thrift/compiler/cpp
James E. King, III113614b2017-09-04 18:28:25 -0700143flex -o src\thrift\thriftl.cc src\thrift\thriftl.ll
James E. King, III330b3f82017-01-23 08:52:04 -0500144```
Roger Meier746952e2014-06-14 21:59:24 +0200145In the generated thriftl.cc, comment out #include <unistd.h>
146
147Place a copy of bison.simple in thrift/compiler/cpp
James E. King, III330b3f82017-01-23 08:52:04 -0500148```
149bison -y -o "src/thrift/thrifty.cc" --defines src/thrift/thrifty.yy
150move src\thrift\thrifty.cc.hh src\thrift\thrifty.hh
151```
Roger Meier746952e2014-06-14 21:59:24 +0200152
153Bison might generate the yacc header file "thrifty.cc.h" with just one h ".h" extension; in this case you'll have to rename to "thrifty.h".
154
James E. King, III330b3f82017-01-23 08:52:04 -0500155```
156move src\thrift\version.h.in src\thrift\version.h
157```
Roger Meier746952e2014-06-14 21:59:24 +0200158
159Download inttypes.h from the interwebs and place it in an include path
160location (e.g. thrift/compiler/cpp/src).
161
162Build the compiler in Visual Studio.
Volodymyr Gotra54993292017-12-18 02:08:09 +0200163
164# Unit tests for compiler
165
166## Using boost test
167- pls check **test** folder
168
169## Using Catch C++ test library
170
171Added generic way to cover code by tests for many languages (you just need to make a correct header file for generator for your language - example in **netcore** implementation)
172
173- pls check **tests** folder
174
James E. King IIIb1d63e72019-01-22 14:16:39 -0500175# Have a Happy free time and holidays