Cmake: leading or trailing spaces (CMP0004 policy)

I follow this question . However mine cmakeencounters an error:

-- Configuring done
CMake Error at CMakeLists.txt:18 (add_executable):
  Target "main" links to item "-L/usr/lib/x86_64-linux-gnu -lSDL2 " which has
  leading or trailing whitespace.  This is now an error according to policy
  CMP0004.


-- Generating done

What's wrong on the list cmake?

I do not think that a small version difference cmakeleads to such an error.

# CMakeLists.txt

cmake_minimum_required(VERSION 3.5.1)
project (main)

add_executable(main
    main.cpp
)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(main ${SDL2_LIBRARIES})

.

// main.cpp

int main()
{
    return 0;
}

Update:

Content /usr/lib/x86_64-linux-gnu/cmake/SDL2/sdl2-config.cmake

is an

# sdl2 cmake project-config input for ./configure scripts

set(prefix "/usr") 
set(exec_prefix "${prefix}")
set(libdir "${prefix}/lib/x86_64-linux-gnu")
set(SDL2_PREFIX "/usr")
set(SDL2_EXEC_PREFIX "/usr")
set(SDL2_LIBDIR "${prefix}/lib/x86_64-linux-gnu")
set(SDL2_INCLUDE_DIRS "${prefix}/include/SDL2")
set(SDL2_LIBRARIES "-L${SDL2_LIBDIR}  -lSDL2 ")
+6
source share
1 answer

The solution is to edit the file sdl2-config.cmake.

You can find this file with the command:

apt-file search sdl2-config

In Ubuntu, Ubuntu 16.04it is in

 /usr/lib/x86_64-linux-gnu/cmake/SDL2/sdl2-config.cmake

In source file

# sdl2 cmake project-config input for ./configure scripts

set(prefix "/usr") 
set(exec_prefix "${prefix}")
set(libdir "${prefix}/lib/x86_64-linux-gnu")
set(SDL2_PREFIX "/usr")
set(SDL2_EXEC_PREFIX "/usr")
set(SDL2_LIBDIR "${prefix}/lib/x86_64-linux-gnu")
set(SDL2_INCLUDE_DIRS "${prefix}/include/SDL2")
set(SDL2_LIBRARIES "-L${SDL2_LIBDIR}  -lSDL2 ")   <---- here

The last line has extra space that should be removed

BEFORE:    set(SDL2_LIBRARIES "-L${SDL2_LIBDIR}  -lSDL2 ")
AFTER :    set(SDL2_LIBRARIES "-L${SDL2_LIBDIR}  -lSDL2")

Then the problem is fixed for me.

+1
source

All Articles