Overview of common cmake statements and cmake statements

Source: Internet
Author: User

Overview of common cmake statements and cmake statements

Cmake_minimum_required (VERSION 2.8.2 FATAL_ERROR) project ("ProjName") // add_definitions is not recommended to set compilation options, because it works like cmake-Dadd_definitions (-std = c ++ 11 # Or-std = c ++ 0x-Wall-Wfatal-errors # Other flags) // set the compilation option set (CMAKE_CXX_FLAGS "$ {CMAKE_CXX_FLAGS}-std = c ++ 11-Wall-Wfatal-errors-fPIC") using the following statement. // variable: CMAKE_PREFIX_PATH: Path used for searching by FIND_XXX (), with appropriate suffixes added. Set (CMAKE_PREFIX_PATH/path) // reference the environment variable export FOO =/use/lib $ ENV {FOO} // header file path include_directories (include relative/path/absolute/path /) // link library directory link_directories (directory1 directory2 ...) // link function library target_link_libraries (. out mylib ompl) // It can be the target in cmake or the libompl in the path. so, that is, the-lompl parameter in gcc // source file path, in the subdirectory add_subdirectory (someDirectory src/otherDirecotry) // find all source files in a directory, format: aux_source_directory (<dir> <variable>) aux_source_directory (src _ srcFiles) // generate the library file add_library (mylib [SHARED | STATIC] mylib. cpp other. cpp) // generate the executable program add_executable (. out main. cpp src/func. cpp) // set the variable set (someVariable "some string") // print the message (STATUS "some status $ {someVariable }") // list Operation list (REMOVE_ITEM _ srcFiles "src/f4.cpp ") // remove a list from the variable (APPEND <list> <element> [<element>...]) // Add an item to the variable // check whether the compiler supports a compilation option CHECK_CXX_COMPILER_FLAG ("-std = c ++ 11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG ("-std = c ++ 0x" delimiter) if (delimiter) set (CMAKE_CXX_FLAGS "$ {CMAKE_CXX_FLAGS}-std = c ++ 11") elseif (delimiter) set (CMAKE_CXX_FLAGS "$ {CMAKE_CXX_FLAGS}-std = c ++ 0x") else () message (STATUS "The compiler $ {CMAKE_CXX_COMPILER} has no C ++ 11 support. please use a different C ++ compiler. ") endif ()

// Common variables

CMAKE_SOURCE_DIR (equivalent to the project root directory)
This is the directory, from which cmake was started, I. e.TopLevel source directory

This is the directory where the currently processed CMakeLists.txt is located in

If you are building in-source, this is the same as CMAKE_CURRENT_SOURCE_DIR, otherwise this is the directory where the compiled or generated files from the current CMakeLists.txt will go

PROJECT_SOURCE_DIR (= CMAKE_SOURCE_DIR is equivalent to the project root directory)
Contains the full path to the root of your project source directory, I. e. to the nearest directory where CMakeLists.txt contains the PROJECT () command

// Configure the cross-compilation environment of cmake to create the toolchain file. cmake: # this one is importantSET (CMAKE_SYSTEM_NAME Linux) # this one not so muchSET (CMAKE_SYSTEM_VERSION 1) # specify the cross compilerSET (CMAKE_C_COMPILER/opt/arm-linux-gnueabihf-gcc) SET (CMAKE_CXX_COMPILER/opt/arm-linux-gnueabihf-g ++) # where is the target environment SET (CMAKE_FIND_ROOT_PATH/opt/arm/install) # search for programs in the build host dir EctoriesSET (effecnever) # for libraries and headers in the target directoriesSET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) // If this file is named toolchain. cmake and is located in your home directory and you are building in the subdirectory build then you can do :~ /Src $ cd build ~ /Src/build $ cmake-DCMAKE_TOOLCHAIN_FILE = ~ /Toolchain. cmake ..

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.