trybuild.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>xmake</title>
  6. <link rel="icon" href="/assets/img/favicon.ico">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  8. <meta name="description" content="Description">
  9. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  10. <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  11. <style>
  12. .markdown-body {
  13. box-sizing: border-box;
  14. min-width: 200px;
  15. max-width: 980px;
  16. margin: 0 auto;
  17. padding: 45px;
  18. }
  19. @media (max-width: 767px) {
  20. .markdown-body {
  21. padding: 15px;
  22. }
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <article class="markdown-body">
  28. <h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/features/trybuild">https://xmake.io/#/features/trybuild</a>
  29. <div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
  30. </br>
  31. <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
  32. <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
  33. <style>
  34. #carbonads {
  35. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  36. Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
  37. }
  38. #carbonads {
  39. display: flex;
  40. max-width: 330px;
  41. background-color: hsl(0, 0%, 98%);
  42. box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
  43. }
  44. #carbonads a {
  45. color: inherit;
  46. text-decoration: none;
  47. }
  48. #carbonads a:hover {
  49. color: inherit;
  50. }
  51. #carbonads span {
  52. position: relative;
  53. display: block;
  54. overflow: hidden;
  55. }
  56. #carbonads .carbon-wrap {
  57. display: flex;
  58. }
  59. .carbon-img {
  60. display: block;
  61. margin: 0;
  62. line-height: 1;
  63. }
  64. .carbon-img img {
  65. display: block;
  66. }
  67. .carbon-text {
  68. font-size: 13px;
  69. padding: 10px;
  70. line-height: 1.5;
  71. text-align: left;
  72. }
  73. .carbon-poweredby {
  74. display: block;
  75. padding: 8px 10px;
  76. background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  77. text-align: center;
  78. text-transform: uppercase;
  79. letter-spacing: .5px;
  80. font-weight: 600;
  81. font-size: 9px;
  82. line-height: 1;
  83. }
  84. </style>
  85. <h1 id="tringtobuildwithotherbuildsystems">Tring to build with other build systems</h1>
  86. <p>Xmake v2.3.1 and above directly interface with other third-party build systems. Even if other projects do not use xmake.lua for maintenance, Xmake can directly call other build tools to complete the compilation. Then the user can directly use a third-party build tool to compile, so why use Xmake to call it? The main benefits are:</p>
  87. <ol>
  88. <li>Completely consistent behavior, simplifying the compilation process. No matter which other build system is used, you only need to execute the Xmake command to compile. Users no longer need to study the different compilation processes of other tools.</li>
  89. <li>Docking the configuration environment of <code>xmake config</code>, reuse the platform detection and SDK environment detection of xmake, simplify the platform configuration.</li>
  90. <li>Docking cross-compilation environment, even for projects maintained with Autotools, you can quickly cross-compile through Xmake.</li>
  91. </ol>
  92. <h2 id="supportedbuildsystems">Supported build systems</h2>
  93. <ul>
  94. <li>Autotools (support for cross-compiling with Xmake)</li>
  95. <li>XCodeBuild</li>
  96. <li>CMake (support for cross-compiling with Xmake)</li>
  97. <li>Make</li>
  98. <li>MSBuild</li>
  99. <li>Scons</li>
  100. <li>Meson</li>
  101. <li>Bazel</li>
  102. <li>NdkBuild</li>
  103. <li>Ninja</li>
  104. </ul>
  105. <h2 id="automaticallydetectbuildsystemandcompile">Automatically detect build system and compile</h2>
  106. <p>For example, for a project maintained using cmake, executing Xmake directly in the project root directory will automatically trigger a detection mechanism, detect CMakeLists.txt, and then prompt the user if cmake is needed to continue compiling.</p>
  107. <pre><code class="lang-bash">$ xmake
  108. note: CMakeLists.txt found, try building it (pass -y or --confirm=y/n/d to skip confirm)?
  109. please input: y (y/n)
  110. -- Symbol prefix:
  111. -- Configuring done
  112. -- Generating done
  113. -- Build files have been written to:/Users/ruki/Downloads/libpng-1.6.35/build
  114. [ 7%] Built target png-fix-itxt
  115. [ 21%] Built target genfiles
  116. [ 81%] Built target png
  117. [ 83%] Built target png_static
  118. ...
  119. output to/Users/ruki/Downloads/libpng-1.6.35/build/artifacts
  120. build ok!
  121. </code></pre>
  122. <h2 id="seamlesslyusingthexmakecommand">Seamlessly, using the Xmake command</h2>
  123. <p>Currently supports common commands such as <code>xmake clean</code>,<code>xmake --rebuild</code> and <code>xmake config</code> to seamlessly interface with third-party systems. We can directly clean the compiled output files of the cmake maintenance project</p>
  124. <pre><code class="lang-bash">$ xmake clean
  125. $ xmake clean --all
  126. </code></pre>
  127. <p>If you bring <code>--all</code> to perform the cleanup, all files generated by autotools/cmake will be cleared, not only the object files. The default <code>xmake</code> is docked with incremental build behavior, but we can also force a quick rebuild:</p>
  128. <pre><code class="lang-bash">$ xmake --rebuild
  129. </code></pre>
  130. <h2 id="manuallyswitchthespecifiedbuildsystem">Manually switch the specified build system</h2>
  131. <p>If there are multiple build systems under maintenance in a project, such as the libpng project, which comes with Autotools/CMake/Makefile and other build system maintenance, Xmake defaults to using Autotools by default. If you want to force switch to other build systems, you can execute:</p>
  132. <pre><code class="lang-bash">$ xmake f --trybuild=[autotools|cmake|make|msbuild|..]
  133. $ xmake
  134. </code></pre>
  135. <p>In addition, the <code>--trybuild=</code> parameter is configured to manually specify the default build system, and the subsequent build process will not prompt the user for selection.</p>
  136. <h2 id="crosscompilefast">Cross compile fast!</h2>
  137. <p>As we all know, although many projects maintained by Autotools support cross-compilation, the configuration process of cross-compilation is very complicated. There are still many differences in different toolchain processing methods, and many pits will be stepped in the middle.</p>
  138. <p>Even if you run through a toolchain&#39;s cross-compilation, if you switch to another toolchain environment, it may take a long time, and if you use Xmake, you usually only need two simple commands:</p>
  139. <p>!> At present CMake/Autotools supports cross-compilation of Xmake.</p>
  140. <h3 id="crosscompileandroidplatform">Cross compile android platform</h3>
  141. <pre><code class="lang-bash">$ xmake f -p android --trybuild=autotools [--ndk=xxx]
  142. $ xmake
  143. </code></pre>
  144. <p>!> Among them, the --ndk parameter configuration is optional. If the user sets the ANDROID_NDK_HOME environment variable, or if the ndk is placed in ~/Library/Android/sdk/ndk-bundle, Xmake can automatically detect it.</p>
  145. <p>Is not it simple? If you think this is not much, then you can directly operate <code>./configure</code> to configure cross-compilation. You can see this document for comparison: <a href="https://developer.android.com/ndk/guides/other_build_systems#autoconf">Using NDK with other compilation systems</a>.</p>
  146. <p>To put it bluntly, you probably have to do this, you may not be able to do it once:</p>
  147. <pre><code class="lang-bash">$ export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
  148. $ export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
  149. $ export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
  150. $ export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
  151. $ export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
  152. $ export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
  153. $ export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
  154. $ export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
  155. $ ./configure --host aarch64-linux-android
  156. $ make
  157. </code></pre>
  158. <p>If it is CMake, cross-compilation is not an easy task. For the Android platform, this configuration is required.</p>
  159. <pre><code class="lang-bash">$ cmake \
  160. -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
  161. -DANDROID_ABI=$ABI \
  162. -DANDROID_NATIVE_API_LEVEL=$MINSDKVERSION \
  163. $OTHER_ARGS
  164. </code></pre>
  165. <p>For the iOS platform, I did not find a short-answer configuration method, but found a third-party iOS toolchain configuration, which is very complicated: <a href="https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake">https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake</a></p>
  166. <p><!-- What? -->
  167. </p>
  168. <p>For MinGW, it is another way. I have been tossing about the environment for a long time, which is very tossing.</p>
  169. <p>After using XMake, whether it is CMake or Autotools, cross-compilation is very simple, and the configuration method is exactly the same, streamlined and consistent.</p>
  170. <h3 id="crosscompileiphoneosplatform">Cross compile iPhoneOS platform</h3>
  171. <pre><code class="lang-bash">$ xmake f -p iphoneos --trybuild=[cmake|autotools]
  172. $ xmake
  173. </code></pre>
  174. <h3 id="crosscompilemingwplatform">Cross-compile MinGW platform</h3>
  175. <pre><code class="lang-bash">$ xmake f -p mingw --trybuild=[cmake|autotools] [--mingw=xxx]
  176. $ xmake
  177. </code></pre>
  178. <h3 id="usingothercrosscompilationtoolchains">Using other cross-compilation toolchains</h3>
  179. <pre><code class="lang-bash">$ xmake f -p cross --trybuild=[cmake|autotools] --sdk=/xxxx
  180. $ xmake
  181. </code></pre>
  182. <p>For more cross compilation configuration details, please refer to the document: <a href="https://xmake.io/#/guide/configuration?id=cross-compilation">Cross Compilation</a>, except for an additional <code>--trybuild=</code> parameter, all other cross-compilation configuration parameters are completely universal.</p>
  183. <h2 id="passinguserconfigurationparameters">Passing user configuration parameters</h2>
  184. <p>We can use <code>--tryconfigs=</code> to pass additional configuration parameters of the user to the corresponding third-party build system. For example: autotools will be passed to <code>. / Configure</code>, cmake will be passed to the<code>cmake</code> command.</p>
  185. <pre><code class="lang-bash">$ xmake f --trybuild=autotools --tryconfigs="-enable-shared=no"
  186. $ xmake
  187. </code></pre>
  188. <p>For example, the above command, pass <code>--enable-shared=no</code> to<code>./configure</code> to disable dynamic library compilation. In addition, for <code>--cflags</code>,<code>--includedirs</code> and <code>--ldflags</code>, you don&#39;t need to pass<code>--tryconfigs</code>, you can pass the built-in parameters like <code>xmake config --cflags=</code> to pass through.</p>
  189. <h2 id="examplesofcompilingotherbuildsystem">Examples of compiling other build system</h2>
  190. <h3 id="generalcompilation">General Compilation</h3>
  191. <p>In most cases, the compilation method after each docking system is consistent, except for the <code>--trybuild=</code> configuration parameter.</p>
  192. <pre><code class="lang-bash">$ xmake f --trybuild=[autotools|cmake|meson|ninja|bazel|make|msbuild|xcodebuild]
  193. $ xmake
  194. </code></pre>
  195. <p>!> We also need to make sure that the build tool specified by --trybuild is installed and working properly.</p>
  196. <h3 id="buildingandroidjniprograms">Building Android JNI programs</h3>
  197. <p>If <code>jni/Android.mk</code> exists in the current project, then Xmake can directly call NdkBuild to build the jni library.</p>
  198. <pre><code class="lang-bash">$ xmake f -p android --trybuild=ndkbuild [--ndk =]
  199. $ xmake
  200. </code></pre>
  201. <p>We also provided <a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a> to build jni library in gradle, you can see <a href="https://xmake.io/#/plugin/more_plugins?id=gradle-plugin-jni">Uses xmake to build JNI in Gradle</a></p>
  202. </article>
  203. </body>
  204. </html>