mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 19:30:13 -06:00
Merge topic 'tutorial-updates'
5e56300742Tutorial: Refactor Step 1093289830eaTutorial: Clarify Step 4 TODO 4c65e01a979Tutorial: Clarify Step 34f955834cfTutorial: Fix Step 1 TODO 1 to be expandable Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8590
This commit is contained in:
@@ -149,8 +149,8 @@ interface library.
|
||||
|
||||
Lastly, we only want these warning flags to be used during builds. Consumers
|
||||
of our installed project should not inherit our warning flags. To specify
|
||||
this, we wrap our flags in a generator expression using the ``BUILD_INTERFACE``
|
||||
condition. The resulting full code looks like the following:
|
||||
this, we wrap our flags from TODO 3 in a generator expression using the
|
||||
``BUILD_INTERFACE`` condition. The resulting full code looks like the following:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ Remove this line:
|
||||
|
||||
</details>
|
||||
|
||||
And the lines:
|
||||
And remove ``EXTRA_INCLUDES`` from ``target_include_directories``:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
@@ -143,23 +143,6 @@ And the lines:
|
||||
|
||||
</details>
|
||||
|
||||
The remaining code looks like:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<details><summary>Click to show/hide the resulting code</summary>
|
||||
|
||||
.. literalinclude:: Step4/CMakeLists.txt
|
||||
:caption: Remaining code after removing EXTRA_INCLUDES
|
||||
:name: CMakeLists.txt-after-removing-EXTRA_INCLUDES
|
||||
:language: cmake
|
||||
:start-after: add_subdirectory(MathFunctions)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
Notice that with this technique, the only thing our executable target does to
|
||||
use our library is call :command:`target_link_libraries` with the name
|
||||
of the library target. In larger projects, the classic method of specifying
|
||||
@@ -309,8 +292,8 @@ and this:
|
||||
:caption: TODO 7: MathFunctions/CMakeLists.txt
|
||||
:name: MathFunctions-SqrtLibrary-target_link_libraries-step4
|
||||
:language: cmake
|
||||
:start-after: target_link_libraries(SqrtLibrary
|
||||
:end-before: endif()
|
||||
:start-after: # link our compiler flags interface library
|
||||
:end-before: target_link_libraries(MathFunctions PUBLIC SqrtLibrary)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ a library target called ``MathFunctions`` with :command:`add_library`. The
|
||||
source files for the library are passed as an argument to
|
||||
:command:`add_library`. This looks like the following line:
|
||||
|
||||
.. raw:: html/
|
||||
.. raw:: html
|
||||
|
||||
<details><summary>TODO 1: Click to show/hide answer</summary>
|
||||
|
||||
|
||||
@@ -44,7 +44,18 @@ SqrtLibrary to be ``True`` when building shared libraries.
|
||||
:caption: MathFunctions/CMakeLists.txt
|
||||
:name: MathFunctions/CMakeLists.txt-POSITION_INDEPENDENT_CODE
|
||||
:language: cmake
|
||||
:lines: 37-42
|
||||
:start-at: # state that SqrtLibrary need PIC when the default is shared libraries
|
||||
:end-at: )
|
||||
|
||||
Define ``EXPORTING_MYMATH`` stating we are using ``declspec(dllexport)`` when
|
||||
building on Windows.
|
||||
|
||||
.. literalinclude:: Step11/MathFunctions/CMakeLists.txt
|
||||
:caption: MathFunctions/CMakeLists.txt
|
||||
:name: MathFunctions/CMakeLists.txt-dll-export
|
||||
:language: cmake
|
||||
:start-at: # define the symbol stating we are using the declspec(dllexport) when
|
||||
:end-at: target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
|
||||
|
||||
**Exercise**: We modified ``MathFunctions.h`` to use dll export defines.
|
||||
Using CMake documentation can you find a helper module to simplify this?
|
||||
|
||||
Reference in New Issue
Block a user