GNU開發(fā)工具——CMake快速入門

GNU開發(fā)工具——CMake快速入門

一、CMake簡介

不同Make工具,如GNU Make、QT的qmake、微軟的MS nmake、BSD Make(pmake)等,遵循著不同的規(guī)范和標(biāo)準(zhǔn),所執(zhí)行的Makefile格式也不同。如果軟件想跨平臺,必須要保證能夠在不同平臺編譯。而如果使用Make工具,必須為不同的Make工具編寫不同的Makefile。
CMake是一個比Make工具更高級的編譯配置工具,是一個跨平臺的、開源的構(gòu)建系統(tǒng)(BuildSystem)。CMake允許開發(fā)者編寫一種平臺無關(guān)的CMakeList.txt文件來定制整個編譯流程,然后再根據(jù)目標(biāo)用戶的平臺進(jìn)一步生成所需的本地化Makefile和工程文件,如:為Unix平臺生成Makefile文件(使用GCC編譯),為Windows MSVC生成projects/workspaces(使用VS IDE編譯)或Makefile文件(使用nmake編譯)。使用CMake作為項(xiàng)目架構(gòu)系統(tǒng)的知名開源項(xiàng)目有VTK、ITK、KDE、OpenCV、OSG等。

目前成都創(chuàng)新互聯(lián)已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、肇慶網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

二、CMake管理工程

在Linux平臺下使用CMake生成Makefile并編譯的流程如下:
A、編寫CMake配置文件CMakeLists.txt
B、執(zhí)行命令cmake PATH生成Makefile,PATH是CMakeLists.txt所在的目錄。
C、使用make命令進(jìn)行編譯。

三、單個源文件工程

1、源文件編寫

假設(shè)項(xiàng)目test中只有一個main.cpp源文件,程序用途是計(jì)算一個數(shù)的指數(shù)冪。

#include <stdio.h>
#include <stdlib.h>
/**
 * power - Calculate the power of number.
 * @param base: Base value.
 * @param exponent: Exponent value.
 *
 * @return base raised to the power exponent.
 */
double power(double base, int exponent)
{
    int result = base;
    int i;

    if (exponent == 0)
    {
        return 1;
    }

    for(i = 1; i < exponent; ++i)
    {
        result = result * base;
    }
    return result;
}
int main(int argc, char *argv[])
{
    if(argc < 3)
    {
        printf("Usage: %s base exponent \n", argv[0]);
        return 1;
    }
    double base = atof(argv[1]);
    int exponent = atoi(argv[2]);
    double result = power(base, exponent);
    printf("%g ^ %d is %g\n", base, exponent, result);
    return 0;
}

2、編寫CMakeLists.txt

在main.cpp源文件目錄test下編寫CMakeLists.txt文件。

#CMake最低版本號要求
cmake_minimum_required (VERSION 2.8)
#項(xiàng)目信息
project (demo)
#指定生成目標(biāo)
add_executable(demomain.cpp)

CMakeLists.txt由命令、注釋和空格組成,其中命令是不區(qū)分大小寫。符號#后的內(nèi)容被認(rèn)為是注釋。命令由命令名稱、小括號和參數(shù)組成,參數(shù)之間使用空格進(jìn)行間隔。
本例中CMakeLists.txt文件的命令如下:
cmake_minimum_required:指定運(yùn)行本配置文件所需的CMake的最低版本;
project:參數(shù)值是demo,表示項(xiàng)目的名稱是demo。
add_executable:將名為main.cpp的源文件編譯成一個名稱為demo的可執(zhí)行文件。

3、編譯工程

在源碼根目錄下創(chuàng)建一個build目錄,進(jìn)入build目錄,執(zhí)行cmake ..,生成Makefile,再使用make命令編譯得到demo可執(zhí)行文件。
通常,建議在源碼根目錄下創(chuàng)建一個獨(dú)立的build構(gòu)建編譯目錄,將構(gòu)建過程產(chǎn)生的臨時文件等文件與源碼隔離,避免源碼被污染。

四、單目錄多源文件工程

1、源文件編寫

假如把power函數(shù)單獨(dú)寫進(jìn)一個名為MathFunctions.cpp的源文件里,使得這個工程變成如下的形式:
GNU開發(fā)工具——CMake快速入門
MathFunctions.h文件:

/**
 * power - Calculate the power of number.
 * @param base: Base value.
 * @param exponent: Exponent value.
 *
 * @return base raised to the power exponent.
 */

double power(double base, int exponent);

MathFunctions.cpp文件:

double power(double base, int exponent)
{
    int result = base;
    int i;

    if (exponent == 0)
    {
        return 1;
    }

    for(i = 1; i < exponent; ++i)
    {
        result = result * base;
    }
    return result;
}

main.cpp文件:

#include <stdio.h>
#include <stdlib.h>
#include "MathFunctions.h"

int main(int argc, char *argv[])
{
    if(argc < 3)
    {
        printf("Usage: %s base exponent \n", argv[0]);
        return 1;
    }

    double base = atof(argv[1]);
    int exponent = atoi(argv[2]);
    double result = power(base, exponent);
    printf("%g ^ %d is %g\n", base, exponent, result);

    return 0;
}

2、編寫CMakeLists.txt

#CMake最低版本號要求
cmake_minimum_required(VERSION 2.8)
#項(xiàng)目信息
project(demo)
#指定生成目標(biāo)
add_executable(demomain.cpp MathFunctions.cpp)

add_executable命令中增加了一個MathFunctions.cpp源文件,但如果源文件很多,可以使用aux_source_directory命令,aux_source_directory命令會查找指定目錄下的所有源文件,然后將結(jié)果存進(jìn)指定變量名。其語法如下:
aux_source_directory(dir variable)
修改后CMakeLists.txt如下:

#CMake最低版本號要求
cmake_minimum_required(VERSION 2.8)
# 項(xiàng)目信息
project(demo)
#查找當(dāng)前目錄下的所有源文件
#并將名稱保存到DIR_SRCS變量
aux_source_directory(. DIR_SRCS)
#指定生成目標(biāo)
add_executable(demo${DIR_SRCS})

CMake會將當(dāng)前目錄所有源文件的文件名賦值給變量DIR_SRCS ,再指示變量DIR_SRCS中的源文件需要編譯成一個名稱為demo的可執(zhí)行文件。

五、多文件多目錄工程

1、源碼文件編寫

創(chuàng)建一個math目錄,將MathFunctions.h和MathFunctions.cpp文件移動到math目錄下。在工程目錄根目錄test和子目錄math里各編寫一個CMakeLists.txt文件,可以先將math目錄里的文件編譯成靜態(tài)庫再由main函數(shù)調(diào)用。
GNU開發(fā)工具——CMake快速入門
math子目錄:
MathFunctions.h文件:

/**
 * power - Calculate the power of number.
 * @param base: Base value.
 * @param exponent: Exponent value.
 *
 * @return base raised to the power exponent.
 */

double power(double base, int exponent);

MathFunctions.cpp文件:

double power(double base, int exponent)
{
    int result = base;
    int i;

    if (exponent == 0)
    {
        return 1;
    }

    for(i = 1; i < exponent; ++i)
    {
        result = result * base;
    }
    return result;
}

根目錄源文件:

#include <stdio.h>
#include <stdlib.h>
#include "math/MathFunctions.h"

int main(int argc, char *argv[])
{
    if(argc < 3)
    {
        printf("Usage: %s base exponent \n", argv[0]);
        return 1;
    }

    double base = atof(argv[1]);
    int exponent = atoi(argv[2]);
    double result = power(base, exponent);
    printf("%g ^ %d is %g\n", base, exponent, result);

    return 0;
}

2、CMakeLists.txt文件編寫

根目錄的CMakeLists.txt文件:

# CMake最低版本號要求
cmake_minimum_required(VERSION 2.8)
# 項(xiàng)目信息
project(demo)
#查找當(dāng)前目錄下的所有源文件
#并將名稱保存到DIR_SRCS變量
aux_source_directory(. DIR_SRCS)
#添加math子目錄
add_subdirectory(math)
#指定生成目標(biāo) 
add_executable(demo${DIR_SRCS})
# 添加鏈接庫
target_link_libraries(demoMathFunctions)

add_subdirectory命令指明本工程包含一個子目錄math,math目錄下的 CMakeLists.txt文件和源代碼也會被處理 。target_link_libraries命令指明可執(zhí)行文件demo需要連接一個名為MathFunctions的鏈接庫 。
math子目錄的CMakeLists.txt文件:

#查找當(dāng)前目錄下的所有源文件
#并將名稱保存到DIR_LIB_SRCS變量
aux_source_directory(. DIR_LIB_SRCS)
#生成鏈接庫
add_library(MathFunctions ${DIR_LIB_SRCS})

add_library命令將math目錄中的源文件編譯為靜態(tài)鏈接庫。

六、自定義編譯選項(xiàng)

1、自定義編譯選項(xiàng)簡介

CMake允許為工程增加編譯選項(xiàng),從而可以根據(jù)用戶的環(huán)境和需求選擇最合適的編譯方案。
例如,可以將MathFunctions庫設(shè)為一個可選的庫,如果該選項(xiàng)為ON ,就使用MathFunctions庫定義的數(shù)學(xué)函數(shù)來進(jìn)行運(yùn)算,否則就調(diào)用標(biāo)準(zhǔn)庫中的數(shù)學(xué)函數(shù)庫。

2、CMakeLists 文件編寫

在根目錄的CMakeLists.txt文件指定自定義編譯選項(xiàng):

# CMake 最低版本號要求
cmake_minimum_required (VERSION 2.8)
# 項(xiàng)目信息
project (demo)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# 加入一個配置頭文件,用于處理 CMake 對源碼的設(shè)置
configure_file (
  "${PROJECT_SOURCE_DIR}/config.h.in"
  "${PROJECT_BINARY_DIR}/config.h"
  )
# 是否使用自己的MathFunctions庫
option (USE_MYMATH
           "Use provided math implementation" ON)
# 是否加入 MathFunctions 庫
if (USE_MYMATH)
  include_directories ("${PROJECT_SOURCE_DIR}/math")
  add_subdirectory (math)
  set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)

# 查找當(dāng)前目錄下的所有源文件
# 并將名稱保存到 DIR_SRCS 變量
aux_source_directory(. DIR_SRCS)
# 指定生成目標(biāo)
add_executable (demo${DIR_SRCS})
target_link_libraries (demo  ${EXTRA_LIBS})

configure_file命令用于加入一個配置頭文件config.h,config.h文件由CMake從config.h.in生成,通過預(yù)定義一些參數(shù)和變量來控制代碼的生成。
option命令添加了一個USE_MYMATH選項(xiàng),并且默認(rèn)值為ON。
根據(jù)USE_MYMATH變量的值來決定是否使用自己編寫的MathFunctions庫。

3、修改源文件的調(diào)用

修改main.cpp文件,讓其根據(jù)USE_MYMATH的預(yù)定義值來決定是否調(diào)用標(biāo)準(zhǔn)庫還是MathFunctions庫。

#include <cstdio>
#include <cstdlib>
#include <config.h>

#ifdef USE_MYMATH
#include <MathFunctions.h>
#else
#include <cmath>
#endif

int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        printf("Usage: %s base exponent \n", argv[0]);
        return 1;
    }

    double base = atof(argv[1]);
    int exponent = atoi(argv[2]);

#ifdef USE_MYMATH
    printf("Now we use our own Math library. \n");
    double result = power(base, exponent);
#else
    printf("Now we use the standard library. \n");
    double result = pow(base, exponent);
#endif

    printf("%g ^ %d is %g\n", base, exponent, result);
    return 0;
}

4、編寫config.h.in文件

main.cpp文件包含了一個config.h文件,config.h文件預(yù)定義了USE_MYMATH 的值。但不會直接編寫config.h文件,為了方便從CMakeLists.txt中導(dǎo)入配置,通常編寫一個config.h.in文件,內(nèi)容如下:
#cmakedefine USE_MYMATH
CMake會自動根據(jù)CMakeLists.txt配置文件中的設(shè)置自動生成config.h文件。

5、編譯工程

修改CMakeLists.txt文件,USE_MYMATH為OFF,使用標(biāo)準(zhǔn)庫。

# 是否使用自己的MathFunctions庫
option (USE_MYMATH
           "Use provided math implementation" OFF)

在build目錄下cmake ..,make,執(zhí)行程序:
GNU開發(fā)工具——CMake快速入門

七、安裝和測試

1、定制安裝規(guī)則

在math/CMakeLists.txt文件指定MathFunctions庫的安裝規(guī)則:

#指定MathFunctions庫的安裝路徑
install(TARGETS MathFunctions DESTINATION bin)
install(FILES MathFunctions.h DESTINATION include)

修改根目錄的CMakeLists.txt文件指定目標(biāo)文件的安裝規(guī)則:

#指定安裝路徑
install(TARGETS test DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/config.h"
         DESTINATION include)

通過對安裝規(guī)則的定制,生成的目標(biāo)文件和MathFunctions函數(shù)庫 libMathFunctions.o文件將會被拷貝到/usr/local/bin中,而MathFunctions.h和生成的config.h文件則會被復(fù)制到/usr/local/include中。
/usr/local是默認(rèn)安裝到的根目錄,可以通過修改 CMAKE_INSTALL_PREFIX 變量的值來指定文件應(yīng)該拷貝到哪個根目錄。

2、為工程添加測試

CMake提供了一個CTest測試工具。在項(xiàng)目根目錄的CMakeLists.txt文件中調(diào)用一系列的add_test 命令。

     #啟用測試
     enable_testing()
     #測試程序是否成功運(yùn)行
     add_test(test_run demo 5 2)
     #測試幫助信息是否可以正常提示
     add_test(test_usage demo)
     set_tests_properties(test_usage
       PROPERTIES PASS_REGULAR_EXPRESSION "Usage: .* base exponent")
     #測試5的平方
     add_test(test_5_2 demo 5 2)
     set_tests_properties(test_5_2
      PROPERTIES PASS_REGULAR_EXPRESSION "is 25")
     #測試10的5次方
     add_test(test_10_5 demo 10 5)
     set_tests_properties(test_10_5
      PROPERTIES PASS_REGULAR_EXPRESSION "is 100000")
     #測試2的10次方
     add_test(test_2_10 demo 2 10)
     set_tests_properties(test_2_10
      PROPERTIES PASS_REGULAR_EXPRESSION "is 1024")

GNU開發(fā)工具——CMake快速入門
第一個測試test_run用來測試程序是否成功運(yùn)行并返回0值。剩下的三個測試分別用來測試 5 的 平方、10 的 5 次方、2 的 10 次方是否都能得到正確的結(jié)果。其中PASS_REGULAR_EXPRESSION用來測試輸出是否包含后面跟著的字符串。
如果要測試更多的輸入數(shù)據(jù),可以通過編寫宏來實(shí)現(xiàn):

# 啟用測試
     enable_testing()

     # 測試程序是否成功運(yùn)行
     add_test (test_run demo 5 2)

     # 測試幫助信息是否可以正常提示
     add_test (test_usage demo)
     set_tests_properties (test_usage
       PROPERTIES PASS_REGULAR_EXPRESSION "Usage: .* base exponent")

     # 測試 5 的平方
     # add_test (test_5_2 Demo 5 2)

     # set_tests_properties (test_5_2
     #  PROPERTIES PASS_REGULAR_EXPRESSION "is 25")

     # 測試 10 的 5 次方
     # add_test (test_10_5 Demo 10 5)

     # set_tests_properties (test_10_5
     #  PROPERTIES PASS_REGULAR_EXPRESSION "is 100000")

     # 測試 2 的 10 次方
     # add_test (test_2_10 Demo 2 10)

     # set_tests_properties (test_2_10
     #  PROPERTIES PASS_REGULAR_EXPRESSION "is 1024")

     # 定義一個宏,用來簡化測試工作
     macro (do_test arg1 arg2 result)
       add_test (test_${arg1}_${arg2} demo ${arg1} ${arg2})
       set_tests_properties (test_${arg1}_${arg2}
         PROPERTIES PASS_REGULAR_EXPRESSION ${result})
     endmacro (do_test)

     # 利用 do_test 宏,測試一系列數(shù)據(jù)
     do_test (5 2 "is 25")
     do_test (10 5 "is 100000")
     do_test (2 10 "is 1024")

GNU開發(fā)工具——CMake快速入門

八、GDB支持

讓CMake支持gdb的設(shè)置只需要指定Debug模式下開啟-g選項(xiàng):

set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

生成的程序可以直接使用gdb來調(diào)試。

九、添加環(huán)境檢查

使用平臺相關(guān)的特性時,需要對系統(tǒng)環(huán)境做檢查。檢查系統(tǒng)是否自帶pow函數(shù),如果有pow函數(shù),就使用;否則使用自定義的power函數(shù)。

1、添加 CheckFunctionExists 宏

首先在頂層CMakeLists.txt文件中添加CheckFunctionExists.cmake 宏,并調(diào)用check_function_exists命令測試鏈接器是否能夠在鏈接階段找到 pow函數(shù)。

#檢查系統(tǒng)是否支持 pow 函數(shù)
include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
check_function_exists (pow HAVE_POW)
check_function_exists需要放在configure_file命令前。

2、預(yù)定義相關(guān)宏變量

修改 config.h.in 文件,預(yù)定義相關(guān)的宏變量。

// does the platform provide pow function?
#cmakedefine HAVE_POW

3、在代碼中使用宏和函數(shù)

修改 main.cpp文件 ,在代碼中使用宏和函數(shù)。

#include <stdio.h>
#include <stdlib.h>
#include <config.h>

#ifdef HAVE_POW
#include <math.h>
#else
#include <MathFunctions.h>
#endif

int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        printf("Usage: %s base exponent \n", argv[0]);
        return 1;
    }
    double base = atof(argv[1]);
    int exponent = atoi(argv[2]);

#ifdef HAVE_POW
    printf("Now we use the standard library. \n");
    double result = pow(base, exponent);
#else
    printf("Now we use our own Math library. \n");
    double result = power(base, exponent);
#endif

    printf("%g ^ %d is %g\n", base, exponent, result);
    return 0;
}

十、添加版本號

修改頂層CMakeLists.txt文件,在project命令后分別指定當(dāng)前的項(xiàng)目的主版本號和副版本號。

# CMake 最低版本號要求
cmake_minimum_required (VERSION 2.8)
# 項(xiàng)目信息
project (demo)

set (Demo_VERSION_MAJOR 1)
set (Demo_VERSION_MINOR 0)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

#檢查系統(tǒng)是否支持 pow 函數(shù)
include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
check_function_exists (pow HAVE_POW)

# 加入一個配置頭文件,用于處理 CMake 對源碼的設(shè)置
configure_file (
  "${PROJECT_SOURCE_DIR}/config.h.in"
  "${PROJECT_BINARY_DIR}/config.h"
  )

# 是否加入 MathFunctions 庫
if (NOT HAVE_POW)
  include_directories ("${PROJECT_SOURCE_DIR}/math")
  add_subdirectory (math)
  set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (NOT HAVE_POW)

# 查找當(dāng)前目錄下的所有源文件
# 并將名稱保存到 DIR_SRCS 變量
aux_source_directory(. DIR_SRCS)
# 指定生成目標(biāo)
add_executable (demo ${DIR_SRCS})
target_link_libraries (demo  ${EXTRA_LIBS})

#指定安裝路徑
install(TARGETS demo DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/config.h"
         DESTINATION include)

     # 啟用測試
     enable_testing()

     # 測試程序是否成功運(yùn)行
     add_test (test_run demo 5 2)

     # 測試幫助信息是否可以正常提示
     add_test (test_usage demo)
     set_tests_properties (test_usage
       PROPERTIES PASS_REGULAR_EXPRESSION "Usage: .* base exponent")

     # 測試 5 的平方
     # add_test (test_5_2 Demo 5 2)

     # set_tests_properties (test_5_2
     #  PROPERTIES PASS_REGULAR_EXPRESSION "is 25")

     # 測試 10 的 5 次方
     # add_test (test_10_5 Demo 10 5)

     # set_tests_properties (test_10_5
     #  PROPERTIES PASS_REGULAR_EXPRESSION "is 100000")

     # 測試 2 的 10 次方
     # add_test (test_2_10 Demo 2 10)

     # set_tests_properties (test_2_10
     #  PROPERTIES PASS_REGULAR_EXPRESSION "is 1024")

     # 定義一個宏,用來簡化測試工作
     macro (do_test arg1 arg2 result)
       add_test (test_${arg1}_${arg2} demo ${arg1} ${arg2})
       set_tests_properties (test_${arg1}_${arg2}
         PROPERTIES PASS_REGULAR_EXPRESSION ${result})
     endmacro (do_test)

     # 利用 do_test 宏,測試一系列數(shù)據(jù)
     do_test (5 2 "is 25")
     do_test (10 5 "is 100000")
     do_test (2 10 "is 1024")

分別指定當(dāng)前的項(xiàng)目的主版本號和副版本號。
為了在代碼中獲取版本信息,可以修改 config.h.in 文件,添加兩個預(yù)定義變量:

// the configured options and settings for Tutorial
#define Demo_VERSION_MAJOR @Demo_VERSION_MAJOR@
#define Demo_VERSION_MINOR @Demo_VERSION_MINOR@

// does the platform provide pow function?
#cmakedefine HAVE_POW

直接在源碼中使用:

#include <stdio.h>
#include <stdlib.h>
#include <config.h>

#ifdef HAVE_POW
#include <math.h>
#else
#include <MathFunctions.h>
#endif

int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        // print version info
        printf("%s Version %d.%d\n",
               argv[0],
               Demo_VERSION_MAJOR,
               Demo_VERSION_MINOR);
        printf("Usage: %s base exponent \n", argv[0]);
        return 1;
    }

    double base = atof(argv[1]);
    int exponent = atoi(argv[2]);

#ifdef HAVE_POW
    printf("Now we use the standard library. \n");
    double result = pow(base, exponent);
#else
    printf("Now we use our own Math library. \n");
    double result = power(base, exponent);
#endif

    printf("%g ^ %d is %g\n", base, exponent, result);
    return 0;
}

十一、生成安裝包

1、增加CPack模塊

CMake提供了一個專門用于打包的工具CPack,用于配置生成各種平臺上的安裝包,包括二進(jìn)制安裝包和源碼安裝包。
首先在頂層的CMakeLists.txt文件尾部添加下面幾行:

# 構(gòu)建一個 CPack 安裝包
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE
  "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set (CPACK_PACKAGE_VERSION_MAJOR "${Demo_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${Demo_VERSION_MINOR}")
include (CPack)

導(dǎo)入InstallRequiredSystemLibraries模塊,便于導(dǎo)入CPack模塊;
設(shè)置一些CPack相關(guān)變量,包括版權(quán)信息和版本信息
導(dǎo)入CPack模塊。
在頂層目錄下創(chuàng)建License.txt文件內(nèi)如如下:

The MIT License (MIT)

Copyright (c) 2018 Scorpio Studio

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2、生成安裝包

生成二進(jìn)制安裝包:
cpack -C CPackConfig.cmake
生成源碼安裝包:
cpack -C CPackSourceConfig.cmake
上述兩個命令都會在目錄下創(chuàng)建3個不同格式的二進(jìn)制包文件:
demo-1.0.1-Linux.tar.gz
demo-1.0.1-Linux.tar.Z
demo-1.0.1-Linux.sh
3個二進(jìn)制包文件所包含的內(nèi)容是完全相同的。

新聞名稱:GNU開發(fā)工具——CMake快速入門
分享路徑:http://muchs.cn/article42/isjphc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、服務(wù)器托管手機(jī)網(wǎng)站建設(shè)、網(wǎng)站營銷微信公眾號、用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司