CMake examples of daily use.
Single file to multiple files application alongwith setting up a specific version of CXX version.
-
101:
- A very basic cmake application.
-
102:
- A very basic cmake application with an option to set build type.
-
103:
- Hello world app to instruct where to install executables.
-
104:
- Build & install application having multiple source files.
-
105:
- Build & install application having multiple sources files + private header.
-
106:
- Build & install application having multiple sources files + private header + version file generated by cmake template.
-
107:
- A hello-world of std::cxx14.
Create static and shared libraries and how to use these libraries with application in different ways.
-
201:
- A static library using std::cxx14.
-
202:
- A shared library using std::cxx14.
- Also see 211
-
203:
- An application using a static library (direct linking).
-
204:
- An application using a shared library (direct linking).
-
205:
- An application using a libary via
.pc
(usingpkg-config
) pkg-config
can be referred to static or shared library.
- An application using a libary via
-
206:
- Generate .cmake file for a library (static).
-
207:
- An application using a static library (using
.cmake
). - TODO: Inherit compiler specific flags from library just like
pkg-config
can do that.
- An application using a static library (using
-
208:
- Generate
.cmake
file for a library (shared library).
- Generate
-
209:
- An application using a shared library (using
.cmake
). - TODO: Inherit compiler specific flags from library just like
pkg-config
can do that.
- An application using a shared library (using
-
210:
- A single project to build shared and static lib (
pkg-config
,.cmake
).
- A single project to build shared and static lib (
-
211:
- An enhanced version of 202. Generator expressions are used.
Use 3rd party libraries in an application.
- 301:
- A hello-world using cmake.BOOST.
Miscellaneous usages.
-
401:
- Application packaging using cpack.
-
402:
- How to use cmake custom command and target interfaces.
add_custom_command
links to different stages of buildPRE_BUILD
,PRE_LINK
,POST_BUILD
- Link
add_custom_command
with custom target.
- How to use cmake custom command and target interfaces.
-
403:
- ExternalProject: Create custom targets to build projects in external trees.
-
404:
- ExternalProject: Pull GoogleTest (gtest) as cmake external project.
- Linking of protobuf, flatbuffers and nanopb via cmake.
set(TEST_VAR "value") # Overwrite old value if it set
set(TEST_VAR "${TEST_VAR} value") # Append new value to old
message("-----------------------------------------------------------")
message("Lib Version : ${VERSION_STRING}")
message("Compiler Id : ${CMAKE_CXX_COMPILER_ID}")
message("Compiler (c) version : ${CMAKE_C_COMPILER_VERSION}")
message("Compiler (cxx) version : ${CMAKE_CXX_COMPILER_VERSION}")
message("-----------------------------------------------------------")
##
message("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
# Get all variables as a list
get_cmake_property(varList VARIABLES)
# Filter variable to have only those starting with our required package
list(FILTER varList INCLUDE REGEX "^sample_lib*")
message("Variables associated to sample_lib are: ")
foreach (_variableName ${varList})
message(" ${_variableName}=${${_variableName}}")
endforeach()
message("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
##
- Show all targets generated by cmake for a project
cmake --build /path/to/build/folder --target help
- Run a specific target
cmake --build /path/to/build/folder --target <target_name>
- Save compiler intermediate files
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --save-temps")