当前位置:网站首页>Cmake common commands

Cmake common commands

2022-06-11 02:41:00 Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma,

project( project name )
# It's necessary 

set( Variable name   route )
# Defining variables , You can use... Later ${ Variable name } To represent the path 

file(GLOB  Variable name  globbing expression )
# Will produce a match by all globbing A list of expression files , And save it to a variable 

file(GLOB_RECURSE  Variable name  globbing expression )
# And GLOB similar , The difference is that it will traverse all the files in the matching directory and the files under the subdirectories 

add_compile_options( Compilation options )
# Add compile options , Such as -g -std=c++17 -O2

include_directories( Header file path )
# Add header file search path 

link_directories( Library file base path )
# Specify the base path of the library file , Must be written in add_executable Before 
# Library files are compiled programs , Using library files instead of source files can greatly reduce compilation time 
# Library files are divided into static library and dynamic library . Static libraries are linked to the object code when the program is compiled .
  # Dynamic library ( Shared library ) When the program is compiled, it is not linked to the object code , It is loaded only when the program is running ;
  # When different programs need the same library , You only need to have a copy of the shared library in memory , Avoid the waste of space ;
  # And it will be loaded at runtime , It also solves the update of static library to program , The trouble of deployment and release 

add_executable( Generate executable file name    Path to the file to compile 1   Path to the file to compile 2  ...)
# It's necessary 

target_link_libraries( Generate executable file name    Library file path )
# Link shared library , Must be written in add_executable after 
原网站

版权声明
本文为[Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma, Ma,]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110200115241.html