CMake Common Statements List

Source: Internet
Author: User

Cmake_minimum_required (VERSION2.8. 2Fatal_error) Project ("ProjName")//It is not recommended to use Add_definitions to set compilation options because it acts like a cmake-dAdd_definitions (-std=c++ One # or-std=c++0x-wall-wfatal-errors# Other Flags)//General set compilation options via the Next statementSet(Cmake_cxx_flags"${cmake_cxx_flags}-std=c++11-wall-wfatal-errors-fpic")//variable: Cmake_prefix_path:path used for searching by find_xxx (), with appropriate suffixes added. Set(Cmake_prefix_path/path/path/path)//Referencing environment variablesExport Foo=/use/lib$env{foo}//Header file pathInclude_directories (include    relative/path/absolute/path/)//link library directoryLink_directories (directory1 directory2 ...)//Link function libraryTarget_link_libraries (a. Out Mylib Ompl)//Can be a target in the cmake, or it can be a libompl.so in the path, which is the-lompl parameter in gcc//source file path, in sub-directoryAdd_subdirectory (Somedirectory src/otherdirecotry)//Find all source files in a directory, format: aux_source_directory (<dir> <variable>)Aux_source_directory (src_srcFiles)//Generate library filesAdd_library (Mylib [shared| STATIC] Mylib.cpp other.cpp)//Generate executable programAdd_executable (a. Out Main.cpp Src/func.cpp)//Set VariableSet(somevariable"some string")//Print MessagesMessage (STATUS"Some Status ${somevariable}")//list OperationList (Remove_item_srcFiles"Src/f4.cpp")//Remove an item from a variableList (APPEND <list> <element> [<element> ...])//Add an item to a variable//Check whether the compiler supports one of the compilation optionsCheck_cxx_compiler_flag ("-std=c++11"COMPILER_SUPPORTS_CXX11) Check_cxx_compiler_flag ("-std=c++0x"compiler_supports_cxx0x)if(compiler_supports_cxx11)Set(Cmake_cxx_flags"${cmake_cxx_flags}-std=c++11") ElseIf (compiler_supports_cxx0x)Set(Cmake_cxx_flags"${cmake_cxx_flags}-std=c++0x")Else() Message (STATUS"The Compiler ${cmake_cxx_compiler} has a no c++11 support. Please use a different C + + compiler. ") endif ()

Common variables

Cmake_source_dir (equivalent to the engineering root directory)
The directory, from which CMake were started, i.e. the top level source directory

Cmake_current_source_dir
The the directory where the currently processed CMakeLists.txt is located in

Cmake_current_binary_dir
If you were building In-source, this is the same as cmake_current_source_dir, and otherwise this is the directory where the COM Piled or generated files from the current CMakeLists.txt would go to

Project_source_dir (=cmake_source_dir equivalent to the engineering root directory)
Contains the full path to the root of your project source directory, i.e. to the nearest directory where CMakeLists.txt Co Ntains the PROJECT () command

CMake cross-compilation environment settings, create file Toolchain.cmake, add the following: # This one is importantSET(Cmake_system_name Linux) #this One notSo muchSET(cmake_system_version1) # Specify the CrossCompilerSET(CMAKE_C_COMPILER/OPT/ARM/ARM-LINUX-GNUEABIHF-GCC)SET(cmake_cxx_compiler/opt/arm/arm-linux-gnueabihf-g++) #where  isThe target environmentSET(cmake_find_root_path/opt/arm/install) # Search forProgramsinchThe Build host DirectoriesSET(Cmake_find_root_path_mode_program never) # forLibraries andHeadersinchThe target directoriesSET(cmake_find_root_path_mode_library only)SET(Cmake_find_root_path_mode_include only)//IfThis file isNamed Toolchain.cmake and  isLocatedinchYour home directory andYou isBuildinginchThe subdirectory Build ThenYou can Do: ~/src$ CD build~/src/build$ Cmake-dcmake_toolchain_file=~/toolchain.cmake.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

CMake Common Statements List

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.