Skip to content

Commit

Permalink
unparsed arguments after CMAKE_PARSE_ARGUMENTS() will cause an error(#…
Browse files Browse the repository at this point in the history
…200)

There is a new macro defined in TribitsGlobalMacros.cmake called
"TRIBITS_PARSE_UNPARSED_ARGS" that checks to see if there are any
unparsed arguments and throws an error if there are.

Build/Test Cases Summary
Enabled Packages:
Enabled all Packages
0) MPI_DEBUG => passed: passed=252,notpassed=0 (0.66 min)
1) SERIAL_RELEASE => passed: passed=252,notpassed=0 (0.61 min)
2) MPI_DEBUG_CMAKE-3.6.2 => passed: passed=273,notpassed=0 (0.62 min)
3) SERIAL_RELEASE_CMAKE-3.6.2 => passed: passed=273,notpassed=0 (0.67 min)
  • Loading branch information
fryeguy52 authored and bartlettroscoe committed Aug 30, 2017
1 parent 526c008 commit 3559d6b
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 6 deletions.
83 changes: 81 additions & 2 deletions test/core/ExamplesUnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_ALL_NoFortran_WrapExternal_Verb
OVERALL_NUM_MPI_PROCS 1

TEST_0
MESSSAGE "Do a verbose configure and check that the packages coupling variables are correct."
MESSAGE "Do a verbose configure and check that the packages coupling variables are correct."
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
Expand Down Expand Up @@ -1835,7 +1835,7 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_ALL_NoFortran_OverridePackageSo
ARGS -r TribitsExampleProject/packages/with_subpackages/

TEST_3
MESSSAGE "Override with_packages/ source dir and configure"
MESSAGE "Override with_packages/ source dir and configure"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
Expand Down Expand Up @@ -3205,3 +3205,82 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithUserErrors_TARGETS_AFTER
ALWAYS_FAIL_ON_ZERO_RETURN

)

TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithUserErrors_UNPARSED_ARGS
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1

TEST_0
MESSAGE "Copy TribitsExampleProject so that we can copy in PkgWithUserErrors."
CMND cp
ARGS -r ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .

TEST_1
MESSAGE "Copy PkgWithUserErrors to base dir."
CMND cp
ARGS -r ${CMAKE_CURRENT_SOURCE_DIR}/PkgWithUserErrors
TribitsExampleProject/.

TEST_2
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DPkgWithUserErrors_UNPARSED_ARGS_DEFINE_DEPENDENCIES=ON
-DTribitsExProj_ENABLE_TESTS=ON
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"CMake Error at.*TribitsGeneralMacros.cmake:"
"Arguments are being passed in but not used. UNPARSED_ARGUMENTS ="
"nonsense_jdslkfhlskd"
"TRIBITS_READ_PACKAGE_DEPENDENCIES"
"-- Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

TEST_3
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DPkgWithUserErrors_UNPARSED_ARGS_DEFINE_DEPENDENCIES=OFF
-DPkgWithUserErrors_UNPARSED_ARGS_ADD_LIBRARY=ON
-DTribitsExProj_ENABLE_TESTS=ON
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"CMake Error at.*TribitsGeneralMacros.cmake:"
"Arguments are being passed in but not used. UNPARSED_ARGUMENTS ="
"this_shouldnt_be_here"
"PkgWithUserErrors/CMakeLists.txt.*TRIBITS_ADD_LIBRARY"
"-- Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

TEST_4
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DPkgWithUserErrors_UNPARSED_ARGS_DEFINE_DEPENDENCIES=OFF
-DPkgWithUserErrors_UNPARSED_ARGS_ADD_LIBRARY=OFF
-DPkgWithUserErrors_UNPARSED_ARGS_ADD_EXECUTABLE=ON
-DTribitsExProj_ENABLE_TESTS=ON
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"CMake Error at.*TribitsGeneralMacros.cmake:"
"Arguments are being passed in but not used. UNPARSED_ARGUMENTS ="
"misspelled_argument"
"PkgWithUserErrors/CMakeLists.txt.*TRIBITS_ADD_EXECUTABLE"
"-- Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN
)
21 changes: 21 additions & 0 deletions test/core/ExamplesUnitTests/PkgWithUserErrors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ IF(${PACKAGE_NAME}_ADD_LIBRARY_BEFORE_POST_PROCESS)
)
ENDIF()

# Not added by defult
IF(${PACKAGE_NAME}_UNPARSED_ARGS_ADD_LIBRARY)
TRIBITS_ADD_LIBRARY(
pkgwithusererrors
this_shouldnt_be_here
HEADERS PkgWithUserErrorsLib.hpp
SOURCES PkgWithUserErrorsLib.cpp
)
ENDIF()

# Not added by defult
IF(${PACKAGE_NAME}_ADD_EXECUTABLE_BEFORE_POST_PROCESS)
MESSAGE("building exectuable")
Expand All @@ -24,6 +34,17 @@ IF(${PACKAGE_NAME}_ADD_EXECUTABLE_BEFORE_POST_PROCESS)
)
ENDIF()

# Not added by defult
IF(${PACKAGE_NAME}_UNPARSED_ARGS_ADD_EXECUTABLE)
MESSAGE("building exectuable")
TRIBITS_ADD_EXECUTABLE(
usererrorexec
misspelled_argument
SOURCES PkgWithUserErrorsEX.cpp
SPORCOOS some_file.cpp
)
ENDIF()

IF(NOT ${PACKAGE_NAME}_SKIP_PACKAGE_TESTS)
TRIBITS_ADD_TEST_DIRECTORIES(test)
ENDIF()
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES()
IF(PkgWithUserErrors_UNPARSED_ARGS_DEFINE_DEPENDENCIES)

TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
nonsense_jdslkfhlskd
)

ELSE()
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES()
ENDIF()
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsAddAdvancedTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ FUNCTION(TRIBITS_ADD_ADVANCED_TEST TEST_NAME_IN)
${PARSE_TEST_${TEST_CMND_IDX}}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

# Write the command

SET(ARGS_STR ${PARSE_ARGS})
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsAddExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF(PARSE_ADDED_EXE_TARGET_NAME_OUT)
SET(${PARSE_ADDED_EXE_TARGET_NAME_OUT} PARENT_SCOPE)
ENDIF()
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsAddExecutableAndTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE_AND_TEST EXE_NAME)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF(${PROJECT_NAME}_VERBOSE_CONFIGURE)
MESSAGE("")
MESSAGE("TRIBITS_ADD_EXECUTABLE_AND_TEST: ${EXE_NAME} ${ARGN}")
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsAddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ FUNCTION(TRIBITS_ADD_TEST EXE_NAME)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF (PARSE_ARGS)
LIST(LENGTH PARSE_ARGS NUM_PARSE_ARGS)
ELSEIF (PARSE_POSTFIX_AND_ARGS_0)
Expand Down
3 changes: 2 additions & 1 deletion tribits/core/package_arch/TribitsAdjustPackageEnables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ MACRO(TRIBITS_PACKAGE_DEFINE_DEPENDENCIES)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

SET(LIB_REQUIRED_DEP_PACKAGES ${PARSE_LIB_REQUIRED_PACKAGES})
SET(LIB_OPTIONAL_DEP_PACKAGES ${PARSE_LIB_OPTIONAL_PACKAGES})
SET(TEST_REQUIRED_DEP_PACKAGES ${PARSE_TEST_REQUIRED_PACKAGES})
Expand All @@ -499,7 +501,6 @@ MACRO(TRIBITS_PACKAGE_DEFINE_DEPENDENCIES)
ENDMACRO()



MACRO(TRIBITS_SAVE_OFF_DEPENENCIES_VARS POSTFIX)

SET(LIB_REQUIRED_DEP_PACKAGES_${POSTFIX} ${LIB_REQUIRED_DEP_PACKAGES})
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ FUNCTION(TRIBITS_COPY_FILES_TO_BINARY_DIR TARGET_NAME)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

SET(ADD_THE_TEST FALSE)
TRIBITS_ADD_TEST_PROCESS_CATEGORIES(ADD_THE_TEST)
IF (NOT ADD_THE_TEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ FUNCTION(TRIBITS_CREATE_CLIENT_TEMPLATE_HEADERS BASE_DIR)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

#
# B) Get the names of the extensions
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ FUNCTION(TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF (PARSE_SHOW_MOST_RECENT_FILES)
SET(PARSE_SHOW_OVERALL_MOST_RECENT_FILE ON)
ENDIF()
Expand Down Expand Up @@ -333,6 +335,8 @@ FUNCTION(TRIBITS_FIND_MOST_RECENT_SOURCE_FILE_TIMESTAMP)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

#
# B) Call the function TRIBITS_FIND_MOST_RECENT_FILE_TIMESTAMP()
#
Expand Down Expand Up @@ -418,6 +422,8 @@ FUNCTION(TRIBITS_FIND_MOST_RECENT_BINARY_FILE_TIMESTAMP)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

#
# B) Define filters for binary files we know are not significant
#
Expand Down Expand Up @@ -550,6 +556,8 @@ FUNCTION(TRIBITS_DETERMINE_IF_CURRENT_PACKAGE_NEEDS_REBUILT)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

# Get pass through print level options
SET(SHOW_MOST_RECENT_FILES_ARGS)
IF (PARSE_SHOW_MOST_RECENT_FILES)
Expand Down
14 changes: 13 additions & 1 deletion tribits/core/package_arch/TribitsGeneralMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,16 @@ FUNCTION(TRIBITS_TRACE_FILE_PROCESSING TYPE_IN PROCESSING_TYPE_IN FILE_PATH)

ENDIF()

ENDFUNCTION()
ENDFUNCTION()

#
# Check to see if there are unparsed arguments after calling CMAKE_PARSE_ARGUMENTS
#

MACRO(TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS)

IF( NOT "${PARSE_UNPARSED_ARGUMENTS}" STREQUAL "")
MESSAGE(FATAL_ERROR "Arguments are being passed in but not used. UNPARSED_ARGUMENTS = ${PARSE_UNPARSED_ARGUMENTS}")
ENDIF()

ENDMACRO()
1 change: 0 additions & 1 deletion tribits/core/package_arch/TribitsIncludeDirectories.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ MACRO(TRIBITS_INCLUDE_DIRECTORIES)
${ARGN}
)


IF(NOT ${PROJECT_NAME}_ENABLE_INSTALLATION_TESTING OR PARSE_REQUIRED_DURING_INSTALLATION_TESTING)
_INCLUDE_DIRECTORIES(${PARSE_UNPARSED_ARGUMENTS})
ENDIF()
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsInstallHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ FUNCTION(TRIBITS_INSTALL_HEADERS)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

# ToDo: Assert PARSE_HEADERS has at least one argument!
# ToDo: Assert PARSE_INSTALL_DIR has 0 or 1 argumnets!
# ToDo: Assert PARSE_COMONENT has 0 or 1 argumnets!
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsLibraryMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ FUNCTION(TRIBITS_ADD_LIBRARY LIBRARY_NAME_IN)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

# ToDo: Assert that HEADERS_INSTALL_SUBDIR has 0 or 1 entries!
# ToDo: Assert that ADDED_LIB_TARGET_NAME_OUT as 0 or 1 entries!

Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsPackageMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ MACRO(TRIBITS_PACKAGE_DECL PACKAGE_NAME_IN)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

#
# B) Assert that the global and local package names are the same!
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ FUNCTION(TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES TPL_NAME)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF (${PROJECT_NAME}_VERBOSE_CONFIGURE)
SET(TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE TRUE)
ENDIF()
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsWriteClientExportFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ FUNCTION(TRIBITS_WRITE_FLEXIBLE_PACKAGE_CLIENT_EXPORT_FILES)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF (NOT ${PROJECT_NAME}_GENERATE_EXPORT_FILE_DEPENDENCIES)
MESSAGE(SEND_ERROR "Error: Can't generate export depenency files because"
" ${PROJECT_NAME}_GENERATE_EXPORT_FILE_DEPENDENCIES is not ON!")
Expand Down
4 changes: 4 additions & 0 deletions tribits/core/utils/CMakeOverrides.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ FUNCTION(TRIBITS_INCLUDE_DIRECTORIES)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF(NOT ${PROJECT_NAME}_ENABLE_INSTALLATION_TESTING OR PARSE_REQUIRED_DURING_INSTALLATION_TESTING)
_INCLUDE_DIRECTORIES(${PARSE_DEFAULT_ARGS})
ENDIF()
Expand Down Expand Up @@ -107,6 +109,8 @@ FUNCTION(INCLUDE_DIRECTORIES)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

IF(NOT ${PROJECT_NAME}_ENABLE_INSTALLATION_TESTING OR PARSE_REQUIRED_DURING_INSTALLATION_TESTING)
_INCLUDE_DIRECTORIES(${PARSE_DEFAULT_ARGS})
ENDIF()
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/utils/CombinedOption.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ FUNCTION(COMBINED_OPTION COMBINED_OPTION_NAME)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

# ToDo: Assert that the right input was passed in!

SET(DEFAULT_VAL ON)
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/utils/FindProgramPlus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ FUNCTION(FIND_PROGRAM_PLUS PROG_VAR)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

PRINT_NONEMPTY_VAR(${PROG_VAR})

IF (IS_ABSOLUTE ${PROG_VAR})
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/utils/UnitTestHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ FUNCTION(UNITTEST_STRING_REGEX INPUT_STRING)
${ARGN}
)

TRIBITS_CHECK_FOR_UNPARSED_ARGUMENTS()

FOREACH(REGEX ${PARSE_REGEX_STRINGS})

MATH( EXPR NUMRUN ${UNITTEST_OVERALL_NUMRUN}+1 )
Expand Down

0 comments on commit 3559d6b

Please sign in to comment.