Я пытаюсь выучить Cmake и работал над задачей учебного пособия Cmake (Шаг 3 Упражнение 2). < /p>
До сих пор проект создал две версии функции SQRT: одно приближение и один стандарт. Он просит пользователя удалить следующие строки из Cmakelists.txt.txt. < /P>
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
и создать библиотеку интерфейсов target_compile_features (turtorial_compiler_flags interface cxx_std_11) и link turtorial_compiler_flags к другим целям (библиотеки и исполняемые). Библиотеки, ссылаясь на наш исполняемый файл для использования любой версии C ++. Например, target_link_libraries (Tutorial Public MathFunctions Tutorial_compiler_flags) . Я думаю, что это означает, что любая библиотека или исполняемый файл, который ссылается на мой исполняемый файл, также должен будет использовать C ++ 11, и то же самое относится ко мне. Поскольку точка упражнения состояла в том, чтобы сделать систему более гибкой, я подумал, что использование личного ключевого слова для того, чтобы быть более подходящим. />[*]cmakelists.txt
[*]tutorialConfig.h.in
[*]tutorial.cxx
[*] mathfunctions
/>mathfunctions.cxx
[*]mathfunctions.h
[*]mysqrt.cxx
[*]mysqrt.h> < /ul>
Cmakelists.txt < /p>
cmake_minimum_required(VERSION 3.10)
# set the project name and version
project(Tutorial VERSION 1.0)
# TODO 4: Replace the following code by:
# * Creating an interface library called tutorial_compiler_flags
# Hint: use add_library() with the INTERFACE signature
# * Add compiler feature cxx_std_11 to tutorial_compiler_flags
# Hint: Use target_compile_features()
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)
# TODO 2: Remove EXTRA_INCLUDES list
# add the MathFunctions library
add_subdirectory(MathFunctions)
list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions")
# add the executable
add_executable(Tutorial tutorial.cxx)
# TODO 5: Link Tutorial to tutorial_compiler_flags
target_link_libraries(Tutorial PUBLIC MathFunctions)
# TODO 3: Remove use of EXTRA_INCLUDES
# 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}
)
mathfunctions/cmakelists.txt
add_library(MathFunctions MathFunctions.cxx)
# TODO 1: State that anybody linking to MathFunctions needs to include the
# current source directory, while MathFunctions itself doesn't.
# Hint: Use target_include_directories with the INTERFACE keyword
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if (USE_MYMATH)
target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
# library that just does sqrt
add_library(SqrtLibrary STATIC
mysqrt.cxx
)
# TODO 6: Link SqrtLibrary to tutorial_compiler_flags
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
# TODO 7: Link MathFunctions to tutorial_compiler_flags
Подробнее здесь: https://stackoverflow.com/questions/797 ... ic-keyword
В Cmake, когда мне следует ссылаться на библиотеку интерфейсов с общедоступным ключевым словом? ⇐ C++
Программы на C++. Форум разработчиков
1755327969
Anonymous
Я пытаюсь выучить Cmake и работал над задачей учебного пособия Cmake (Шаг 3 Упражнение 2). < /p>
До сих пор проект создал две версии функции SQRT: одно приближение и один стандарт. Он просит пользователя удалить следующие строки из Cmakelists.txt.txt. < /P>
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
и создать библиотеку интерфейсов target_compile_features (turtorial_compiler_flags interface cxx_std_11) и link turtorial_compiler_flags к другим целям (библиотеки и исполняемые). Библиотеки, ссылаясь на наш исполняемый файл для использования любой версии C ++. Например, target_link_libraries (Tutorial Public MathFunctions Tutorial_compiler_flags) . Я думаю, что это означает, что любая библиотека или исполняемый файл, который ссылается на мой исполняемый файл, также должен будет использовать C ++ 11, и то же самое относится ко мне. Поскольку точка упражнения состояла в том, чтобы сделать систему более гибкой, я подумал, что использование личного ключевого слова для того, чтобы быть более подходящим. />[*]cmakelists.txt
[*]tutorialConfig.h.in
[*]tutorial.cxx
[*] mathfunctions
/>mathfunctions.cxx
[*]mathfunctions.h
[*]mysqrt.cxx
[*]mysqrt.h> < /ul>
Cmakelists.txt < /p>
cmake_minimum_required(VERSION 3.10)
# set the project name and version
project(Tutorial VERSION 1.0)
# TODO 4: Replace the following code by:
# * Creating an interface library called tutorial_compiler_flags
# Hint: use add_library() with the INTERFACE signature
# * Add compiler feature cxx_std_11 to tutorial_compiler_flags
# Hint: Use target_compile_features()
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)
# TODO 2: Remove EXTRA_INCLUDES list
# add the MathFunctions library
add_subdirectory(MathFunctions)
list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions")
# add the executable
add_executable(Tutorial tutorial.cxx)
# TODO 5: Link Tutorial to tutorial_compiler_flags
target_link_libraries(Tutorial PUBLIC MathFunctions)
# TODO 3: Remove use of EXTRA_INCLUDES
# 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}
)
mathfunctions/cmakelists.txt
add_library(MathFunctions MathFunctions.cxx)
# TODO 1: State that anybody linking to MathFunctions needs to include the
# current source directory, while MathFunctions itself doesn't.
# Hint: Use target_include_directories with the INTERFACE keyword
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if (USE_MYMATH)
target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
# library that just does sqrt
add_library(SqrtLibrary STATIC
mysqrt.cxx
)
# TODO 6: Link SqrtLibrary to tutorial_compiler_flags
target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()
# TODO 7: Link MathFunctions to tutorial_compiler_flags
Подробнее здесь: [url]https://stackoverflow.com/questions/79736981/in-cmake-when-should-i-link-to-an-interface-library-with-the-public-keyword[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия