简体   繁体   中英

CMake Error 'The Source Does Not Appear to contain CMakeLists.txt', problems with path/library connection

I'm new to cmake , and I'm only using Visual studio 19 Community. I have a problem with running the program. The Program is unable to find the correct path/library. Here's the command, I ran;

cd path/to/examples
mkdir build
cd build
cmake -G"Visual Studio 16 2019" -DLEAP_ROOT="C:\Users\User\Desktop\LeapDeveloperKit_3.2.1+45911_win\LeapSDK" ..

Then it returns the error:

CMake Error at CMakeLists.txt:6 (message):
  Run CMake in a separate build directory to avoid source code contamination.


-- Configuring incomplete, errors occurred!
See also "C:/Users/User/Desktop/Windows Win64/Examples/CMakeFiles/CMakeOutput.log".

I'm workin wth Windows10 and use prompt. How do I solve it? Here my CmakeLists.txt:

cmake_minimum_required(VERSION 3.3)

project(UltrahapticsExamples)

if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
    message(FATAL_ERROR "Run CMake in a separate build directory to avoid source code contamination.")
endif ()

# For FindLeap.cmake
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")

find_package(Ultrahaptics REQUIRED)

find_package(Leap)
if (LEAP_FOUND)
    include_directories(${LEAP_INCLUDE_DIR})
else ()
    message(WARNING "Could not find Leap SDK")
endif ()

set(ULTRAHAPTICS_CSHARP_DIR "" CACHE PATH "Ultrahaptics CSharp libraries folder")
if (NOT ULTRAHAPTICS_CSHARP_DIR STREQUAL "" AND EXISTS "${ULTRAHAPTICS_CSHARP_DIR}")
    find_file(ULTRAHAPTICS_CSHARP_RUNTIME 
        NAMES libUltrahapticsCSharp.dylib libUltrahapticsCSharp.so UltrahapticsCSharp.dll 
        PATHS "${ULTRAHAPTICS_CSHARP_DIR}")

    find_file(ULTRAHAPTICS_CSHARP_40 UltrahapticsCSharp.NET40.dll "${ULTRAHAPTICS_CSHARP_DIR}")
    if (ULTRAHAPTICS_CSHARP_RUNTIME AND ULTRAHAPTICS_CSHARP_40)
        set(ULTRAHAPTICS_CSHARP_FOUND TRUE)
    endif()
endif()

add_subdirectory(cpp)
if (ULTRAHAPTICS_CSHARP_FOUND)
    add_subdirectory(csharp)
endif()

message(STATUS "    ========== Examples Configuration Summary =========\n")

if (LEAP_FOUND)
    message(STATUS "    Leap:            Enabled")
else ()
    message(STATUS "    Leap:            Not Found")
endif ()

message(STATUS "")

The error is telling you that your build directory is same as the directory that contains the source. You need to change this to enable out of source build. This will keep your compiled files separate from your source code.

if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
    message(FATAL_ERROR "Run CMake in a separate build directory to avoid source code contamination.")
endif ()

This line checks whether your build and source directories are same, and if they, it gives a fatal error and stops the build.

Here's how to fix it:

  1. Go into the directory: C:/Users/User/Desktop/Windows Win64/Examples
  2. Open cmd / ps in this directory
  3. Enter: mkdir build // create build directory
  4. Enter: cd build // go into this directory

After this step the console should show that you are in directory: C:/Users/User/Desktop/Windows Win64/Examples/build

  1. Enter: cmake -G"Visual Studio 16 2019" -DLEAP_ROOT="C:\Users\User\Desktop\LeapDeveloperKit_3.2.1+45911_win\LeapSDK"..

After the project has been configured (at least, partially) as in-source , it is impossible to perform out-of-source builds:

Even if you call cmake from the other directory, it will behave "as if" called from the source directory.

For make out-of-source build accessible again, you need to cleanup build files in the source directory, namely CMakeCache.txt file and CMakeFiles directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM