cmake/libs/Directory.cmake
Share
Specify how to compile the source programs in cmake/libs/Directory.cmake.
The target_include_directories function specifies include paths for each target.
The target_link_libraries function specifies the libraries to link for each target.
The link method can be PRIVATE, PUBLIC, or INTERFACE. The use of the INTERFACE keyword is limited, so it will be explained first.
The INTERFACE keyword has two uses. The first is used when creating a target from a header file. The first use is limited because of the include_directories function.
add_library(target INTERFACE)
target_include_directories(target INTERFACE include_dir)
Another way to use the INTERFACE keyword is as an interface for multiple libraries.
add_library(target INTERFACE)
target_link_libraries(target INTERFACE abc ...)
The INTERFACE keyword can be used to create a header-only target, or to create a target that is a set of libraries.
The difference between the PRIVATE and PUBLIC keywords is explained. In target_link_libraries, a target that links to a target is called a consuming target. If the consuming target does not provide an interface for the linked target, you can specify the PRIVATE keyword. If the consuming target provides a definition that is in the linked target, you can specify the PUBLIC keyword.
By specifying the appropriate link keywords, you can create a shared library and switch the link using a project variable.
Once the target is created, install it into the component. The component specifies how to package it in packaging/CMakeLists.txt.
install(TARGETS targets RUNTIME COMPONENT CppRestApi_Runtime ...)
Similarly for cmake/tests/DirectoryTest.cmake.
This completes the explanation of the CppRestApi CMake project.