1. 程式人生 > >CMakeLists.txt的寫法

CMakeLists.txt的寫法

har sele ica exc words platform 庫文件 linked builds

[1]ADD_LIBRARY: Add a library to the project using the specified source files.要求CMake根據指定的源文件生成庫文件 .
? ADD_LIBRARY(libname [SHARED | STATIC | MODULE] [EXCLUDE_FROM_ALL] source1 source2 ... sourceN)Adds a library target.

SHARED, STATIC or MODULE keywords are used to set the library type. If the keyword MODULE appears, the library type is set to MH_BUNDLE on systems which use dyld. On systems without dyld, MODULE is treated like SHARED. If no keywords appear as the second argument, the type defaults to the current value of BUILD_SHARED_LIBS. If this variable is not set, the type defaults to STATIC.

If EXCLUDE_FROM_ALL is given the target will not be built by default. It will be built only if the user explicitly builds the target or another target that requires the target depends on it.

[2]INCLUDE_DIRECTORIES: Add include directories to the build.添加查找頭文件的路徑
? INCLUDE_DIRECTORIES([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)Add the given directories to those searched by the compiler for include files. By default the directories are appended onto the current list of directories. This default behavior can be changed by setting CMAKE_INCLUDE_DIRECTORIES_BEFORE to ON. By using BEFORE or AFTER you can select between appending and prepending, independent from the default. If the SYSTEM option is given the compiler will be told that the directories are meant as system include directories on some platforms.

[3]LINK_DIRECTORIES: Specify directories in which to search for libraries.添加庫文件的搜索路徑

LINK_DIRECTORIES(directory1 directory2 ...)

[4]TARGET_LINK_LIBRARIES: Link a target to given libraries.為每個目標分別指定需要鏈接的庫文件(指定部分目標專用的庫文件)

TARGET_LINK_LIBRARIES(target library1 <debug | optimized> library2 ...)Specify a list of libraries to be linked into the specified target. The debug and optimized strings may be used to indicate that the next library listed is to be used only for that specific type of build

[5]LINK_LIBRARIES: Link libraries to all targets added later.為所有目標統一指定需要的庫文件(指定所有目標都用的庫文件)
LINK_LIBRARIES(library1 <debug | optimized> library2 ...)This is an old CMake command for linking libraries. Use TARGET_LINK_LIBRARIES unless you have a good reason for every target to link to the same set of libraries.

Specify a list of libraries to be linked into any following targets (typically added with the ADD_EXECUTABLE or ADD_LIBRARY calls). This command is passed down to all subdirectories. The debug and optimized strings may be used to indicate that the next library listed is to be used only for that specific type of build.

CMakeLists.txt的寫法