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 specifiedCommon causes
How to fix it
Quote variable expansions
- Wrap variables in quotes so an empty value still counts as one argument.
- 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
CMake "Syntax error in cmake code ... Invalid character escape" in CIFix CMake "Syntax error in cmake code ... Invalid character escape" in CI - a backslash in a quoted argument,…
CMake "Policy CMP0XXX is not set" developer warning fails CIFix CMake "Policy CMP0XXX is not set" warnings that fail CI - a behavior changed in a newer CMake and the pro…
CMake "version X or higher is required" (cmake_minimum_required) in CIFix CMake "CMake X or higher is required. You are running Y" in CI - the runner CMake is older than the proje…