| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 1 | # Build Thrift IDL compiler using CMake |
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 2 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 3 | <!-- TOC --> |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 4 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 5 | - [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, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 23 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 24 | <!-- /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 Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 36 | |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 37 | ``` |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 38 | mkdir cmake-build && cd cmake-build |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 39 | cmake .. |
| 40 | make |
| 41 | ``` |
| henrique | 55087a4 | 2014-06-17 12:36:39 +0200 | [diff] [blame] | 42 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 43 | #### Build with Eclipse IDE |
| 44 | |
| 45 | - Go to **thrift\compiler\cpp** |
| 46 | - Use the following steps to build using cmake: |
| henrique | 55087a4 | 2014-06-17 12:36:39 +0200 | [diff] [blame] | 47 | |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 48 | ``` |
| 49 | mkdir cmake-ec && cd cmake-ec |
| 50 | cmake -G "Eclipse CDT4 - Unix Makefiles" .. |
| 51 | make |
| 52 | ``` |
| henrique | 55087a4 | 2014-06-17 12:36:39 +0200 | [diff] [blame] | 53 | |
| Roger Meier | 880a2b3 | 2015-05-16 22:40:17 +0200 | [diff] [blame] | 54 | Now open the folder cmake-ec using eclipse. |
| henrique | 55087a4 | 2014-06-17 12:36:39 +0200 | [diff] [blame] | 55 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 56 | #### Build with XCode IDE in MacOS |
| henrique | 55087a4 | 2014-06-17 12:36:39 +0200 | [diff] [blame] | 57 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 58 | - Install/update flex, bison and cmake with brew |
| 59 | |
| 60 | ``` |
| 61 | brew install cmake |
| 62 | brew install bison |
| 63 | ``` |
| 64 | |
| 65 | - Go to **thrift\compiler\cpp** |
| 66 | - Run commands in command line: |
| 67 | |
| 68 | ``` |
| 69 | mkdir cmake-build && cd cmake-build |
| James E. King III | 29f7f8f | 2019-01-26 09:15:19 -0500 | [diff] [blame^] | 70 | cmake -G "Xcode" .. |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 71 | cmake --build . |
| 72 | ``` |
| 73 | |
| 74 | #### Usage of other IDEs |
| 75 | |
| 76 | Please check list of supported IDE |
| 77 | |
| 78 | ``` |
| 79 | cmake --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 | |
| 92 | Git Bash provides flex and bison |
| 93 | |
| 94 | - Go to **thrift\compiler\cpp** |
| 95 | - Use the following steps to build using cmake: |
| 96 | |
| 97 | ``` |
| 98 | mkdir cmake-vs && cd cmake-vs |
| 99 | cmake -DWITH_SHARED_LIB=off .. |
| 100 | cmake --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 | ``` |
| 108 | mkdir cmake-vs |
| 109 | cd cmake-vs |
| James E. King III | 29f7f8f | 2019-01-26 09:15:19 -0500 | [diff] [blame^] | 110 | cmake -G "Visual Studio 15 2017" .. |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 111 | ``` |
| 112 | - Now open the folder cmake-vs using Visual Studio. |
| 113 | |
| 114 | ### Cross compile using mingw32 and generate a Windows Installer with CPack |
| henrique | 55087a4 | 2014-06-17 12:36:39 +0200 | [diff] [blame] | 115 | |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 116 | ``` |
| 117 | mkdir cmake-mingw32 && cd cmake-mingw32 |
| James E. King III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 118 | cmake -DCMAKE_TOOLCHAIN_FILE=../build/cmake/mingw32-toolchain.cmake -DBUILD_COMPILER=ON -DBUILD_LIBRARIES=OFF -DBUILD_TESTING=OFF .. |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 119 | cpack |
| 120 | ``` |
| Roger Meier | 8720260 | 2014-08-15 22:16:02 +0200 | [diff] [blame] | 121 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 122 | # Other cases |
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 123 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 124 | ## Building the Thrift IDL compiler in Windows without CMake |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 125 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 126 | If you don't want to use CMake you can use the already available Visual Studio 2010 solution. |
| Roger Meier | 86fded2 | 2015-05-15 12:01:38 +0200 | [diff] [blame] | 127 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 128 | The 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 Meier | 86fded2 | 2015-05-15 12:01:38 +0200 | [diff] [blame] | 129 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 130 | These depend on bison, flex and their dependencies to work properly. |
| Roger Meier | 86fded2 | 2015-05-15 12:01:38 +0200 | [diff] [blame] | 131 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 132 | Download flex & bison as described above. |
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 133 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 134 | Place these binaries somewhere in the path and rename win_flex.exe and win_bison.exe to flex.exe and bison.exe respectively. |
| Nobuaki Sukegawa | d8c6a84 | 2016-10-02 14:21:55 +0900 | [diff] [blame] | 135 | |
| 136 | If this doesn't work on a system, try these manual pre-build steps. |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 137 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 138 | Open compiler.sln and remove the Pre-build commands under the project's: Properties -> Build Events -> Pre-Build Events. |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 139 | |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 140 | From a command prompt: |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 141 | ``` |
| 142 | cd thrift/compiler/cpp |
| James E. King, III | 113614b | 2017-09-04 18:28:25 -0700 | [diff] [blame] | 143 | flex -o src\thrift\thriftl.cc src\thrift\thriftl.ll |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 144 | ``` |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 145 | In the generated thriftl.cc, comment out #include <unistd.h> |
| 146 | |
| 147 | Place a copy of bison.simple in thrift/compiler/cpp |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 148 | ``` |
| 149 | bison -y -o "src/thrift/thrifty.cc" --defines src/thrift/thrifty.yy |
| 150 | move src\thrift\thrifty.cc.hh src\thrift\thrifty.hh |
| 151 | ``` |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 152 | |
| 153 | Bison 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, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 155 | ``` |
| 156 | move src\thrift\version.h.in src\thrift\version.h |
| 157 | ``` |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 158 | |
| 159 | Download inttypes.h from the interwebs and place it in an include path |
| 160 | location (e.g. thrift/compiler/cpp/src). |
| 161 | |
| 162 | Build the compiler in Visual Studio. |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 163 | |
| 164 | # Unit tests for compiler |
| 165 | |
| 166 | ## Using boost test |
| 167 | - pls check **test** folder |
| 168 | |
| 169 | ## Using Catch C++ test library |
| 170 | |
| 171 | Added 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 III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 175 | # Have a Happy free time and holidays |