CMake ошибка в Ubuntu - include не может найти загрузочный файл: - PullRequest
0 голосов
/ 18 апреля 2019

Я получаю следующую ошибку при выполнении команды cmake в Ubuntu.

Версия CMAke - 3.10.2

 mapp@ubuntu:~/Desktop/LocatePro$ cmake .
 -- Enable testing: ON
 CMake Error at CMakeLists.txt:40 (include):
  include could not find load file:

   FetchContent


CMake Error at CMakeLists.txt:42 (FetchContent_Declare):
   Unknown CMake command "FetchContent_Declare".

 -- Configuring incomplete, errors occurred!
    See also "/home/mapp/Desktop/LocatePro/CMakeFiles/CMakeOutput.log".
 mapp@ubuntu:~/Desktop/LocatePro$ 

Ниже приведено содержимое CMakeLists.txt из строки №.31

# we will use the network to fetch Google Test sources
# make it possible to disable unit tests when not on network
option(ENABLE_UNIT_TESTS "Enable unit tests" ON)
message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}")

if(ENABLE_UNIT_TESTS)
# the following code to fetch googletest
# is inspired by and adapted after:
#   - https://cmake.org/cmake/help/v3.11/module/FetchContent.html
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG        release-1.8.0
)

FetchContent_GetProperties(googletest)

if(NOT googletest_POPULATED)
    FetchContent_Populate(googletest)

    # Prevent GoogleTest from overriding our compiler/linker options
    # when building with Visual Studio
    set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
    # Prevent GoogleTest from using PThreads
    set(gtest_disable_pthreads ON CACHE BOOL "" FORCE)

    # adds the targers: gtest, gtest_main, gmock, gmock_main
    add_subdirectory(
      ${googletest_SOURCE_DIR}
      ${googletest_BINARY_DIR}
      )

    # Silence std::tr1 warning on MSVC
    if(MSVC)
      foreach(_tgt gtest gtest_main gmock gmock_main)
        target_compile_definitions(${_tgt}
          PRIVATE
            "_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING"
          )
      endforeach()
    endif()
  endif()

 add_executable(LocatPro_Test "")

 target_sources(LocatPro_Test
    PRIVATE
    LocatProTest/LocatProTest.cpp
   )

  target_link_libraries(LocatPro_Test
     PRIVATE
     gtest_main
   )

  enable_testing()

  add_test(
     NAME google_test
     COMMAND $<TARGET_FILE:LocatPro_Test>
     )
endif()

Я новичок и только сегодня я начал работать над CMake.Пожалуйста, дайте мне знать, если я делаю что-то не так и / или что-то упускаю в Cmake.

include (FetchContent) поддерживается в версии CMAke - 3.10.2 в Ubuntu.

Спасибо mapppppp

1 Ответ

2 голосов
/ 18 апреля 2019

Модуль FetchContent появился только в CMake 3.11.

(Вы можете попробовать выбрать предыдущие версии CMake по приведенной выше ссылке и обнаружить, что модуль отсутствует в этих версиях).

...