日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Cmake-2

發(fā)布時(shí)間:2024/4/17 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Cmake-2 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")

把配置文件寫到二進(jìn)制樹中。

?

# specify the C++ standard set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True)

上面的命令指定C++的標(biāo)準(zhǔn)。

Step 2:增加一個(gè)庫

把自定義的庫文件放到子目錄:MathFunctions;庫包含頭文件:MathFunctions.h和源文件:mysqrt.cxx;有一個(gè)方法是mysqrt。

add_library(MathFunctions mysqrt.cxx)的cmakeLists.txt到MathFunctions的子目錄中。

為了使用mathFunctions的功能,高一級(jí)的cmakeLists的寫法如下:

# add the MathFunctions library add_subdirectory(MathFunctions)# add the executable add_executable(Tutorial tutorial.cxx)target_link_libraries(Tutorial PUBLIC MathFunctions)# add the binary tree to the search path for include files # so that we will find TutorialConfig.h target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}""${PROJECT_SOURCE_DIR}/MathFunctions")

為了讓這個(gè)math庫變?yōu)榭膳渲玫摹?/p> option(USE_MYMATH "Use tutorial provided math implementation" ON)# configure a header file to pass some of the CMake settings # to the source code configure_file(TutorialConfig.h.in TutorialConfig.h)

改變上一級(jí)的cmakelist.txt:

if(USE_MYMATH)add_subdirectory(MathFunctions)list(APPEND EXTRA_LIBS MathFunctions)list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions") endif()# add the executable add_executable(Tutorial tutorial.cxx)target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})# add the binary tree to the search path for include files # so that we will find TutorialConfig.h target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}"${EXTRA_INCLUDES})

在?in?tutorial.cxx中使用宏定義:

#ifdef USE_MYMATH # include "MathFunctions.h" #endif #ifdef USE_MYMATHconst double outputValue = mysqrt(inputValue); #elseconst double outputValue = sqrt(inputValue); #endif

編譯:

cmake ../Step2 -DUSE_MYMATH=OFF

Step 3:添加庫的使用要求

1)接口的使用,是用戶需要的,需要修改MathFunctions/CMakeLists.txt增加下面一行:

?

target_include_directories(MathFunctionsINTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

如果增加了上面一行,那就可以修改上一級(jí)的CMakeLists.txt:

if(USE_MYMATH)add_subdirectory(MathFunctions)list(APPEND EXTRA_LIBS MathFunctions) endif()

And here:

target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")

?

?

?

總結(jié)

以上是生活随笔為你收集整理的Cmake-2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。