| 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 | ``` |
| bhalchandrap | 82a9c67 | 2021-08-09 23:14:05 -0700 | [diff] [blame] | 61 | brew install flex |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 62 | brew install bison |
| bhalchandrap | 82a9c67 | 2021-08-09 23:14:05 -0700 | [diff] [blame] | 63 | brew install cmake |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 64 | ``` |
| 65 | |
| 66 | - Go to **thrift\compiler\cpp** |
| 67 | - Run commands in command line: |
| 68 | |
| 69 | ``` |
| 70 | mkdir cmake-build && cd cmake-build |
| James E. King III | 29f7f8f | 2019-01-26 09:15:19 -0500 | [diff] [blame] | 71 | cmake -G "Xcode" .. |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 72 | cmake --build . |
| 73 | ``` |
| 74 | |
| 75 | #### Usage of other IDEs |
| 76 | |
| bhalchandrap | 82a9c67 | 2021-08-09 23:14:05 -0700 | [diff] [blame] | 77 | Please check list of supported IDE |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 78 | |
| 79 | ``` |
| 80 | cmake --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/ |
| bhalchandrap | 82a9c67 | 2021-08-09 23:14:05 -0700 | [diff] [blame] | 88 | - In case if you want to build with Visual Studio - install Visual Studio |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 89 | - 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 | |
| 93 | Git Bash provides flex and bison |
| 94 | |
| 95 | - Go to **thrift\compiler\cpp** |
| 96 | - Use the following steps to build using cmake: |
| 97 | |
| 98 | ``` |
| 99 | mkdir cmake-vs && cd cmake-vs |
| 100 | cmake -DWITH_SHARED_LIB=off .. |
| 101 | cmake --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 | ``` |
| 109 | mkdir cmake-vs |
| 110 | cd cmake-vs |
| James E. King III | 29f7f8f | 2019-01-26 09:15:19 -0500 | [diff] [blame] | 111 | cmake -G "Visual Studio 15 2017" .. |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 112 | ``` |
| 113 | - Now open the folder cmake-vs using Visual Studio. |
| 114 | |
| 115 | ### Cross compile using mingw32 and generate a Windows Installer with CPack |
| henrique | 55087a4 | 2014-06-17 12:36:39 +0200 | [diff] [blame] | 116 | |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 117 | ``` |
| 118 | mkdir cmake-mingw32 && cd cmake-mingw32 |
| James E. King III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 119 | 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] | 120 | cpack |
| 121 | ``` |
| Roger Meier | 8720260 | 2014-08-15 22:16:02 +0200 | [diff] [blame] | 122 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 123 | # Other cases |
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 124 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 125 | ## Building the Thrift IDL compiler in Windows without CMake |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 126 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 127 | 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] | 128 | |
| bhalchandrap | 82a9c67 | 2021-08-09 23:14:05 -0700 | [diff] [blame] | 129 | 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] | 130 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 131 | These depend on bison, flex and their dependencies to work properly. |
| Roger Meier | 86fded2 | 2015-05-15 12:01:38 +0200 | [diff] [blame] | 132 | |
| bhalchandrap | 82a9c67 | 2021-08-09 23:14:05 -0700 | [diff] [blame] | 133 | Download flex & bison as described above. |
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 134 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 135 | 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] | 136 | |
| 137 | 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] | 138 | |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 139 | 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] | 140 | |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 141 | From a command prompt: |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 142 | ``` |
| 143 | cd thrift/compiler/cpp |
| James E. King, III | 113614b | 2017-09-04 18:28:25 -0700 | [diff] [blame] | 144 | flex -o src\thrift\thriftl.cc src\thrift\thriftl.ll |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 145 | ``` |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 146 | In the generated thriftl.cc, comment out #include <unistd.h> |
| 147 | |
| 148 | Place a copy of bison.simple in thrift/compiler/cpp |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 149 | ``` |
| 150 | bison -y -o "src/thrift/thrifty.cc" --defines src/thrift/thrifty.yy |
| 151 | move src\thrift\thrifty.cc.hh src\thrift\thrifty.hh |
| 152 | ``` |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 153 | |
| 154 | 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". |
| 155 | |
| James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 156 | ``` |
| 157 | move src\thrift\version.h.in src\thrift\version.h |
| 158 | ``` |
| Roger Meier | 746952e | 2014-06-14 21:59:24 +0200 | [diff] [blame] | 159 | |
| 160 | Download inttypes.h from the interwebs and place it in an include path |
| 161 | location (e.g. thrift/compiler/cpp/src). |
| 162 | |
| 163 | Build the compiler in Visual Studio. |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 164 | |
| 165 | # Unit tests for compiler |
| 166 | |
| 167 | ## Using boost test |
| 168 | - pls check **test** folder |
| 169 | |
| 170 | ## Using Catch C++ test library |
| 171 | |
| Jens Geyer | 3f3567a | 2019-10-19 18:27:35 +0200 | [diff] [blame] | 172 | 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 **netstd** implementation) |
| Volodymyr Gotra | 5499329 | 2017-12-18 02:08:09 +0200 | [diff] [blame] | 173 | |
| 174 | - pls check **tests** folder |
| 175 | |
| bhalchandrap | 82a9c67 | 2021-08-09 23:14:05 -0700 | [diff] [blame] | 176 | # Have a Happy free time and holidays |