Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,288
    • Issues 3,288
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 11
    • Merge Requests 11
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #22027

Closed
Open
Created Apr 05, 2021 by Timur Kristóf@Venemo

find_package called before project() gives unhelpful error message

Consider the following CMakeLists.txt file, which uses find_package to find Vulkan:

cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)

find_package(Vulkan REQUIRED)

project(hellovulkan)
project(hellovulkan VERSION 0.1)
add_executable(hellovulkan main.c)
configure_file(hellovulkan-config.h.in hellovulkan-config.h)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${Vulkan_INCLUDE_DIRS})

target_link_libraries(hellovulkan glfw vulkan)
target_compile_definitions(hellovulkan PUBLIC GLFW_INCLUDE_VULKAN)

This yields the following error:

[Timur@timur-xps build]$ cmake ..
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_PREFIXES
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_SUFFIXES
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
  Could NOT find Vulkan (missing: Vulkan_LIBRARY Vulkan_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindVulkan.cmake:96 (find_package_handle_standard_args)
  CMakeLists.txt:8 (find_package)


-- Configuring incomplete, errors occurred!

The error message Error required internal CMake variable not set, cmake may not be built correctly. is very unhelpful and doesn't help me figure out how to solve this.

I'm new to CMake so I don't understand what the problem is, but after some trial and error I found out that if I put the line find_package between the configure_file and include_directories then it starts working. I haven't a clue why.

Suggested solution: Please give a better error message which tells me where I need to put find_package.

Edited Apr 05, 2021 by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None