meta data for this page
CMake
https://cmake.org/Wiki/CMake_Useful_Variables http://www.vtk.org/Wiki/CMake_Cross_Compiling#Setting_up_the_system_and_toolchain
verbose build
Method 1
- CMakeList.txt
set(CMAKE_VERBOSE_MAKEFILE ON)
Method 2
make VERBOSE=1
Method 3
cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON $path_to_project_source
multiline strings
Use 2 space indentation
message(STATUS "This is a very long message spanning on several lines ")
add all *.c files
cmake_minimum_required(VERSION 2.8) file(GLOB helloworld_SRC "*.h" "*.cpp" ) add_executable(helloworld ${helloworld_SRC})
linker flags
Check:
- CMAKE_EXE_LINKER_FLAGS
- CMAKE_MODULE_LINKER_FLAGS
- CMAKE_SHARED_LINKER_FLAGS
- CMAKE_STATIC_LINKER_FLAGS
set (CMAKE_EXE_LINKER_FLAGS "-Wl,--unresolved-symbols=ignore-in-object-files")
debug build
mkdir Debug cd Debug cmake -DCMAKE_BUILD_TYPE=Debug .. make
mkdir Release cd Release cmake -DCMAKE_BUILD_TYPE=Release .. make
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
libraries
add_executable(ws2812 ${COMMON_SOURCES} ${TARGET_SOURCES}) target_link_libraries(ws2812 rpi_ws281x) set(RPI_WS281X_SOURCES mailbox.c ws2811.c pwm.c dma.c rpihw.c ) add_library(rpi_ws281x STATIC ${RPI_WS281X_SOURCES})
find_package vs find_library
- find_package Loads settings for external project. Try to configure all variables related to package (headers, paths)
- module: package_name.cmake (or shipped with CMake /usr/share/cmake/Modules/FindPackage_name.cmake)
- config: package_nameConfig.cmake or package_name-.cmake
- find_library