blob: 8e3a90bb3cd4cfa466b2bc79f0cc0c11e9ad3659 [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```
bhalchandrap82a9c672021-08-09 23:14:05 -070061brew install flex
Volodymyr Gotra54993292017-12-18 02:08:09 +020062brew install bison
bhalchandrap82a9c672021-08-09 23:14:05 -070063brew install cmake
Volodymyr Gotra54993292017-12-18 02:08:09 +020064```
65
66- Go to **thrift\compiler\cpp**
67- Run commands in command line:
68
69```
70mkdir cmake-build && cd cmake-build
James E. King III29f7f8f2019-01-26 09:15:19 -050071cmake -G "Xcode" ..
Volodymyr Gotra54993292017-12-18 02:08:09 +020072cmake --build .
73```
74
75#### Usage of other IDEs
76
bhalchandrap82a9c672021-08-09 23:14:05 -070077Please check list of supported IDE
Volodymyr Gotra54993292017-12-18 02:08:09 +020078
79```
80cmake --help
81```
82
83## Build on Windows
84
85### Prerequisites
86- Install CMake - https://cmake.org/download/
87- In case if you want to build without Git Bash - install winflexbison - https://sourceforge.net/projects/winflexbison/
bhalchandrap82a9c672021-08-09 23:14:05 -070088- In case if you want to build with Visual Studio - install Visual Studio
Volodymyr Gotra54993292017-12-18 02:08:09 +020089 - 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
90
91### Build using Git Bash
92
93Git Bash provides flex and bison
94
95- Go to **thrift\compiler\cpp**
96- Use the following steps to build using cmake:
97
98```
99mkdir cmake-vs && cd cmake-vs
100cmake -DWITH_SHARED_LIB=off ..
101cmake --build .
102```
103
104### Using Visual Studio and Win flex-bison
105
106- Generate a Visual Studio project for version of Visual Studio which you have (**cmake --help** can show list of supportable VS versions):
107- Run commands in command line:
108```
109mkdir cmake-vs
110cd cmake-vs
James E. King III29f7f8f2019-01-26 09:15:19 -0500111cmake -G "Visual Studio 15 2017" ..
Volodymyr Gotra54993292017-12-18 02:08:09 +0200112```
113- Now open the folder cmake-vs using Visual Studio.
114
115### Cross compile using mingw32 and generate a Windows Installer with CPack
henrique55087a42014-06-17 12:36:39 +0200116
James E. King, III330b3f82017-01-23 08:52:04 -0500117```
118mkdir cmake-mingw32 && cd cmake-mingw32
James E. King IIIb1d63e72019-01-22 14:16:39 -0500119cmake -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 -0500120cpack
121```
Roger Meier87202602014-08-15 22:16:02 +0200122
Volodymyr Gotra54993292017-12-18 02:08:09 +0200123# Other cases
Pascal Bach6eb015a2014-04-17 16:19:07 +0200124
Volodymyr Gotra54993292017-12-18 02:08:09 +0200125## Building the Thrift IDL compiler in Windows without CMake
James E. King, III330b3f82017-01-23 08:52:04 -0500126
Volodymyr Gotra54993292017-12-18 02:08:09 +0200127If you don't want to use CMake you can use the already available Visual Studio 2010 solution.
Roger Meier86fded22015-05-15 12:01:38 +0200128
bhalchandrap82a9c672021-08-09 23:14:05 -0700129The 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 +0200130
Volodymyr Gotra54993292017-12-18 02:08:09 +0200131These depend on bison, flex and their dependencies to work properly.
Roger Meier86fded22015-05-15 12:01:38 +0200132
bhalchandrap82a9c672021-08-09 23:14:05 -0700133Download flex & bison as described above.
Pascal Bach6eb015a2014-04-17 16:19:07 +0200134
Volodymyr Gotra54993292017-12-18 02:08:09 +0200135Place 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 +0900136
137If this doesn't work on a system, try these manual pre-build steps.
Roger Meier746952e2014-06-14 21:59:24 +0200138
Volodymyr Gotra54993292017-12-18 02:08:09 +0200139Open 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 +0200140
Roger Meier746952e2014-06-14 21:59:24 +0200141From a command prompt:
James E. King, III330b3f82017-01-23 08:52:04 -0500142```
143cd thrift/compiler/cpp
James E. King, III113614b2017-09-04 18:28:25 -0700144flex -o src\thrift\thriftl.cc src\thrift\thriftl.ll
James E. King, III330b3f82017-01-23 08:52:04 -0500145```
Roger Meier746952e2014-06-14 21:59:24 +0200146In the generated thriftl.cc, comment out #include <unistd.h>
147
148Place a copy of bison.simple in thrift/compiler/cpp
James E. King, III330b3f82017-01-23 08:52:04 -0500149```
150bison -y -o "src/thrift/thrifty.cc" --defines src/thrift/thrifty.yy
151move src\thrift\thrifty.cc.hh src\thrift\thrifty.hh
152```
Roger Meier746952e2014-06-14 21:59:24 +0200153
154Bison 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".
155
James E. King, III330b3f82017-01-23 08:52:04 -0500156```
157move src\thrift\version.h.in src\thrift\version.h
158```
Roger Meier746952e2014-06-14 21:59:24 +0200159
160Download inttypes.h from the interwebs and place it in an include path
161location (e.g. thrift/compiler/cpp/src).
162
163Build the compiler in Visual Studio.
Volodymyr Gotra54993292017-12-18 02:08:09 +0200164
165# Unit tests for compiler
166
167## Using boost test
168- pls check **test** folder
169
170## Using Catch C++ test library
171
Jens Geyer3f3567a2019-10-19 18:27:35 +0200172Added 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 **netstd** implementation)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200173
174- pls check **tests** folder
175
bhalchandrap82a9c672021-08-09 23:14:05 -0700176# Have a Happy free time and holidays