cmake_parse_arguments causes all arguments to be unhandeled

I have a function and am trying to pass arguments though. Specifically my project name, and then Source files for my project. It’s set up like this:

function( make_function )
 set( oneValueArgs APP_NAME )
 set( multiValueArgs SOURCES INCLUDES LIBRARIES )

 cmake_parse_arguments( ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

 if( NOT ARG_APP_NAME )
     message( WARNING "Name not provided" )
     set( ARG_APP_NAME "${PROJECT_NAME}" )
 endif()

 if( ARG_UNPARSED_ARGUMENTS )
     message( WARNING "unhandled arguments: ${ARG_UNPARSED_ARGUMENTS}" )
 endif()
endfunction()

I have tried passing in just random text and also several cpp files and none show up.

For some reason all my arguments appear in the UNPARSED_ARGUMENTS variable. Why does this keep happening? I can’t access parameters the way I should.

Entire CMakeLists.txt:

cmake_minimum_required( VERSION 3.16 )
set( CMAKE_CXX_STANDARD 14 )
project( make_function_test )

include( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/makeFunction.cmake" )

set( SOURCES
    src/main.cpp
    src/test.cpp
    )

make_function( TARGETS foo bar )

add_executable(${PROJECT_NAME} ${SOURCES})

Entire makeFunction.cmake:

include( CMakeParseArguments )

function( make_function )
  set( oneValueArgs APP_NAME )
  set( multiValueArgs SOURCES INCLUDES LIBRARIES )

  cmake_parse_arguments( ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

  if( NOT ARG_APP_NAME )
      message( WARNING "Name not provided" )
      set( ARG_APP_NAME "${PROJECT_NAME}" )
  endif()

  if( ARG_UNPARSED_ARGUMENTS )
      message( WARNING "unhandled arguments: ${ARG_UNPARSED_ARGUMENTS}" )
  endif()

endfunction()

Please show specific examples of the ways you’ve tried calling the function rather than just stating you tried things in general terms. The problem may be in the way you are calling it, but without seeing how you’re doing that, we can’t tell. A full set of steps to reproduce your problem is more likely to get feedback and suggestions for the source of the problem.

Sorry I rushed the post pretty fast. I tried these:

make_function( TARGETS foo bar )
make_function( ${PROJECT_NAME} ${SOURCES} )

and my SOURCES is this:

set( SOURCES src/main.cpp src/test.cpp )

Edited my original post with the code I used.

TARGETS is not one of the keyword options you have defined. Presumably it should have been listed as one of the multiValueArgs.

This call doesn’t use any keywords. You probably meant this:

make_function(APP_NAME ${PROJECT_NAME} SOURCES ${SOURCES})

I have to specify the variable types before? Like which is going to be SOURCES? I was referring to how libCinder had done this and I did not have to define before what variable I was referencing.

This is the beginning of the cinder make app file:

function( ci_make_app )
set( oneValueArgs APP_NAME CINDER_PATH ASSETS_PATH )
set( multiValueArgs SOURCES INCLUDES LIBRARIES RESOURCES BLOCKS )

cmake_parse_arguments( ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

if( NOT ARG_APP_NAME )
	set( ARG_APP_NAME "${PROJECT_NAME}" )
endif()

I can then call the function like so:

project( CinderGrid )
get_filename_component( CINDER_PATH "D:/Developer/Frameworks/cinder_0.9.2" ABSOLUTE )
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/" ABSOLUTE )

set(SOURCE_FILES
    ${APP_PATH}/src/main.cpp
    ${APP_PATH}/src/Layout.cpp
)

include( "${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake" )

ci_make_app(
    SOURCES     ${SOURCE_FILES}
    CINDER_PATH ${CINDER_PATH}
)

EDIT: I am just now seeing that I do have to call it as such. Oops