Skip to content
Latchkey

CMake "X Function invoked with incorrect arguments" in CI

A CMake command got the wrong arguments. A common cause is an unquoted variable that expands to nothing, so a command like if() or set() sees fewer arguments than required and aborts.

What this error means

Configuration fails at a command call. The error names the function and shows the expanded argument list, which is short because a variable was empty.

CMake
CMake Error at CMakeLists.txt:14 (if):
  if given arguments:

    "STREQUAL" "release"

  Unknown arguments specified

Common causes

How to fix it

Quote variable expansions

  1. Wrap variables in quotes so an empty value still counts as one argument.
  2. Reconfigure and confirm the command receives the expected arguments.
CMakeLists.txt
# empty BUILD_TYPE drops an arg; quote it
if("${BUILD_TYPE}" STREQUAL "release")

Set a default before use

Give the variable a fallback so it is never empty when a command consumes it.

CMakeLists.txt
if(NOT DEFINED BUILD_TYPE)
  set(BUILD_TYPE "debug")
endif()

How to prevent it

  • Quote variable references that feed CMake commands and define defaults so an unset variable never silently removes a required argument.

Frequently asked questions

What causes ""invoked with incorrect arguments""?
Configuration fails at a command call. The error names the function and shows the expanded argument list, which is short because a variable was empty.
How do I fix "invoked with incorrect arguments"?
Quote variable expansions

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card