In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you what are the learning points of cmake in c language. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1 set
Set (var hello) message (${var})
Output
Hello
In fact, not only output hello, there is a lot of other information, will generate a lot of files
Files
2 CMAKE_C (XX) _ FLAGS
The contents of the variable CMAKE_C_FLAGS are passed to the C compiler, which acts on all compiled configurations. If you want to be valid for only one specific configuration, you can set CMAKE_C_FLAGS_, such as CMAKE_C_FLAGS_RELEASE, CMAKE_C_FLAGS_DEBUG.
Set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-Wall-O3-march=native-Wno-reorder")
Set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-Wall-O3-march=native-Wno-reorder")
Optimization of compilation option-Wall O3
Other internal variables:
CMAKE_C_COMPILER: specifies the C compiler
CMAKE_CXX_COMPILER:
CMAKE_C_FLAGS: options for compiling C files, such as-g; you can also add compilation options through add_definitions
EXECUTABLE_OUTPUT_PATH: the path to the executable file
LIBRARY_OUTPUT_PATH: library file path
CMAKE_BUILD_TYPE::build type (Debug, Release,...)
CMAKE_BUILD_TYPE=Debug
BUILD_SHARED_LIBS:Switch between shared and static libraries
Use of built-in variables:
Specified in CMakeLists.txt, using set
Used in the cmake command, such as cmake-DBUILD_SHARED_LIBS=OFF
3 CHECK_CXX_COMPILER_FLAG
Check whether the CXX compiler supports the given flag
Must first include (CheckCXXCompilerFlag)
Include (CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG ()
E.g.
CHECK_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") add_definitions (- DCOMPILEDWITHC11) message (STATUS "Using flag-std=c++11.") Elseif (COMPILER_SUPPORTS_CXX0X) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-std=c++0x") add_definitions (- DCOMPILEDWITHC0X) message (STATUS "Using flag-std=c++0x.") else () message (FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no containers 11 support. Please use a different C++ compiler.") endif ()
The above code is straightforward.
Is to check whether the current compiler supports cymbals 11
The var assigned by CHECK_CXX_COMPILER_FLAG is of Bool type.
4 add_definitions
Add compilation parameters
Add_definitions (- DDEBUG)
The DEBUG macro definition will be added to the gcc command line, so you can face the DEBUG macro in your source file.
5 ENV
Syntax:
$ENV (VAR) # reads the environment variable VAR and can also assign a value to it with set
Eg:
IF (DEFINED ENV {ARM_ARCHITECTURE}) # if it is an arm machine
6 list
List operation
List (LENGTH) list (GET [...]) list (APPEND [...]) list (FIND) list (INSERT [...]) list (REMOVE_ITEM [...]) list (REMOVE_AT [...]) list (REMOVE_DUPLICATES) list (REVERSE) list (SORT)
APPEND appends elements, see? these are all operations of list.
7 CMAKE_MODULE_PATH
The list of the modules searched by cmake, which is a list
8 find_package
This is a little complicated. Let's just look at the official documents.
And this
9 include_directories
Increase the search path of the header file, which is equivalent to specifying the-I parameter of gcc
Include_directories ([AFTER | BEFORE] [SYSTEM] dir1 [dir2...])
10 add_library
Add_library ([STATIC | SHARED | MODULE]
[EXCLUDE_FROM_ALL]
Source1 [source2...])
Add the directory of the library
11 target_link_libraries
Target_link_libraries ([item1 [item2 [...]
[[debug | optimized | general]].)
The directive target_link_libraries () is used to specify the libraries that target needs to link to, and there are different options.
E.g.
Target_link_libraries (myapp debug-labc optimized-lxyz)
Myapp links libabc.an in debug build and libxyz.an in release build, and their directories are added by the add_library command
12 add_executable
Add executable files (from source files)
Add_executable ([WIN32] [MACOSX_BUNDLE])
[EXCLUDE_FROM_ALL]
Source1 [source2...])
E.g.
Add_executable (stereo_euroc Examples/Stereo/stereo_euroc.cc) target_link_libraries (stereo_euroc ${PROJECT_NAME})
Stereo_euroc is the executable file to be generated, and the source code is the later .cc file. Link to the following libraries.
These are the learning points of cmake in the c language shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.