C++高性能并行编程与优化 - 课件 - 16 现代 CMake 模块化项目管理指南biology : target_link_libraries(pybmain PUBLIC biology) • 由于 PUBLIC 属性具有传染性,根 /biology/include 现在也加入 pybmain 的 头文件搜索路径了,因此 pybmain 里可以 #include 到 biology 的头文件。 • 同理如果又有一个 target_link_libraries(zxxpig PUBLIC s(yourapp ${XXX_INCLUDE_DIRS}) • target_link_libraries(yourapp ${XXX_LIBRARIES}) • 现代(小彭老师推荐): • find_package(XXX REQUIRED COMPONENTS xxx) • target_link_libraries(yourapp XXX::xxx) 大多都能同时兼容现代和古代 cpp) • find_package(TBB CONFIG REQUIRED COMPONENTS tbb) • target_link_libraries(yourapp PUBLIC TBB::tbb) 古代 CMake 常见问题 1. target_link_libraries(yourapp ${XXX_LIBRARIES}) 2. target_include_directories(yourapp0 码力 | 56 页 | 6.87 MB | 1 年前3
Conan 1.4 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 4.2 Installing dependencies If you have a terminal with light colors 4.5 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 121 conan Documentation, Release 1.4.5 The conan_basic_setup() is0 码力 | 421 页 | 2.84 MB | 1 年前3
Conan 1.5 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 4.2 Installing dependencies If you have a terminal with light colors 5.2 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 422 页 | 2.85 MB | 1 年前3
Conan 1.6 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 3.2 Installing dependencies If you have a terminal with light colors 6.1 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 428 页 | 2.87 MB | 1 年前3
Conan 1.7 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) 3.2 Installing Dependencies To improve visibility, if you have a terminal 7.4 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 433 页 | 2.95 MB | 1 年前3
Libraries: A First Step Toward Standard C++ Dependency Managementadd_library(SqrtLibrary STATIC mysqrt.cxx) target_link_libraries(MathFunctions PUBLIC SqrtLibrary) add_executable(Tutorial tutorial.cxx) target_link_libraries(Tutorial PUBLIC MathFunctions) % ninja -v part of the build find_package(bar REQUIRED) # external to the build add_executable(foo) target_link_libraries(foo bar) # makes no difference which bar # bar could be in this build or could be from find_package "Link to default component(s)." ON) if (USE_DEFAULT_COMPONENTS) target_link_libraries(demo spdlog) else() target_link_libraries(demo spdlog::spdlog) endif() 69Configure [0/1] Running CMake to regenerate0 码力 | 82 页 | 4.21 MB | 6 月前3
Conan 1.8 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(md5 md5.cpp) target_link_libraries(md5 ${CONAN_LIBS}) 8. Now we are ready to build and run our Encrypter app: (win) $ cmake 8.4 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 458 页 | 3.03 MB | 1 年前3
Conan 1.9 Documentationinclude(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(md5 md5.cpp) target_link_libraries(md5 ${CONAN_LIBS}) 8. Now we are ready to build and run our Encrypter app: (win) $ cmake 9.2 (continued from previous page) if(ENABLE_TESTING) add_executable(example test.cpp) target_link_libraries(example ${CONAN_LIBS}) enable_testing() add_test(NAME example WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() add_executable(timer timer.cpp) target_link_libraries(timer ${CONAN_LIBS}) The conan_basic_setup() is split in smaller macros, that should be self0 码力 | 470 页 | 3.05 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - 01 学 C++ 从 CMake 学起准备的参数可能对 MSVC 不适用。 • CMake 可以自动检测当前的编译器,需要添加哪些 flag 。比如 OpenMP ,只需要在 CMakeLists.txt 中指明 target_link_libraries(a.out OpenMP::OpenMP_CXX) 即可。 输出的可执行文件 输入的多个源文件 CMake 的命令行调用 • 读取当前目录的 CMakeLists.txt ,并在 环境下,初学者自己创建库时,建议使用静态库。 • 但是他人提供的库,大多是作为动态库的,我们之后会讨论如何使用他人的库。 • 创建库以后,要在某个可执行文件中使用该库,只需要: • target_link_libraries(myexec PUBLIC test) # 为 myexec 链接刚刚制作的库 libtest.a • 其中 PUBLIC 的含义稍后会说明( CMake 中有很多这样的大写修饰符) PRIVATE 对他们同理: • target_include_directories(myapp PUBLIC /usr/include/eigen3) # 添加头文件搜索目录 • target_link_libraries(myapp PUBLIC hellolib) # 添加要链接的库 • target_add_definitions(myapp0 码力 | 32 页 | 11.40 MB | 1 年前3
C++20 Modules: The Packaging and Binary Redistribution StoryThese days this is handled by build system abstractions and is hidden away from developers target_link_libraries(hello_world PRIVATE fmt::fmt)A typical library package “fmt” package ├── include │ └── set(CMAKE_CXX_EXTENSIONS OFF) find_package(fmt REQUIRED) add_executable(hello hello_world.cpp) target_link_libraries(hello PRIVATE fmt::fmt) CMakeLists.txt import fmt; int main() { fmt::print("Hello, world FetchContent_MakeAvailable(fmt) find_package(fmt REQUIRED) add_executable(hello hello_world.cpp) target_link_libraries(hello PRIVATE fmt::fmt) target_compile_options(hello PRIVATE "-std=c++23") [7/8] Building0 码力 | 76 页 | 2.09 MB | 6 月前3
共 96 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10













