<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 1.5 向用戶顯示選項 **NOTE**: *這個示例代碼可以在 https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-01/recipe-05 找到,其中有一個C++示例。該配置在CMake 3.5版(或更高版本)測試有效的,并且已經在GNU/Linux、macOS和Windows上進行了測試。* 前面的配置中,我們引入了條件句:通過硬編碼的方式給定邏輯變量值。不過,這會影響用戶修改這些變量。CMake代碼沒有向讀者傳達,該值可以從外部進行修改。推薦在`CMakeLists.txt`中使用`option()`命令,以選項的形式顯示邏輯開關,用于外部設置,從而切換構建系統的生成行為。本節的示例將向您展示,如何使用這個命令。 ## 具體實施 看一下前面示例中的靜態/動態庫示例。與其硬編碼`USE_LIBRARY`為`ON`或`OFF`,現在為其設置一個默認值,同時也可以從外部進行更改: 1. 用一個選項替換上一個示例的`set(USE_LIBRARY OFF)`命令。該選項將修改`USE_LIBRARY`的值,并設置其默認值為`OFF`: ```cmake option(USE_LIBRARY "Compile sources into a library" OFF) ``` 2. 現在,可以通過CMake的`-D`CLI選項,將信息傳遞給CMake來切換庫的行為: ```shell $ mkdir -p build $ cd build $ cmake -D USE_LIBRARY=ON .. -- ... -- Compile sources into a library? ON -- ... $ cmake --build . Scanning dependencies of target message [ 25%] Building CXX object CMakeFiles/message.dir/Message.cpp.o [ 50%] Linking CXX static library libmessage.a [ 50%] Built target message Scanning dependencies of target hello-world [ 75%] Building CXX object CMakeFiles/hello-world.dir/hello-world.cpp.o [100%] Linking CXX executable hello-world [100%] Built target hello-world ``` `-D`開關用于為CMake設置任何類型的變量:邏輯變量、路徑等等。 ## 工作原理 `option`可接受三個參數: `option(<option_variable> "help string" [initial value])` * `<option_variable>`表示該選項的變量的名稱。 * `"help string"`記錄選項的字符串,在CMake的終端或圖形用戶界面中可見。 * `[initial value]`選項的默認值,可以是`ON`或`OFF`。 ## 更多信息 有時選項之間會有依賴的情況。示例中,我們提供生成靜態庫或動態庫的選項。但是,如果沒有將`USE_LIBRARY`邏輯設置為`ON`,則此選項沒有任何意義。CMake提供`cmake_dependent_option()`命令用來定義依賴于其他選項的選項: ```cmake include(CMakeDependentOption) # second option depends on the value of the first cmake_dependent_option( MAKE_STATIC_LIBRARY "Compile sources into a static library" OFF "USE_LIBRARY" ON ) # third option depends on the value of the first cmake_dependent_option( MAKE_SHARED_LIBRARY "Compile sources into a shared library" ON "USE_LIBRARY" ON ) ``` 如果`USE_LIBRARY`為`ON`,`MAKE_STATIC_LIBRARY`默認值為`OFF`,否則`MAKE_SHARED_LIBRARY`默認值為`ON`。可以這樣運行: ```shell $ cmake -D USE_LIBRARY=OFF -D MAKE_SHARED_LIBRARY=ON .. ``` 這仍然不會構建庫,因為`USE_LIBRARY`仍然為`OFF`。 CMake有適當的機制,通過包含模塊來擴展其語法和功能,這些模塊要么是CMake自帶的,要么是定制的。本例中,包含了一個名為`CMakeDependentOption`的模塊。如果沒有`include`這個模塊,`cmake_dependent_option()`命令將不可用。參見 https://cmake.org/cmake/help/latest/module/CMakeDependentOption.html **TIPS**:*手冊中的任何模塊都可以以命令行的方式使用`cmake --help-module <name-of-module> `。例如,`cmake --help-module CMakeDependentOption`將打印剛才討論的模塊的手冊頁(幫助頁面)。*
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看