Skip to content

Commit

Permalink
Factor out tribits_add_test_example_directories_assert_call_context() (
Browse files Browse the repository at this point in the history
…TriBITSPub#200)

This eliminates a lot of dupication, reduces the number of lines of code, and
removes a bunch of clutter from the functions tribits_add_test_directories()
and tribits_add_example_directories().  Win, win, win.

I noticed this while working on TriBITSPub#510.
  • Loading branch information
bartlettroscoe committed Aug 11, 2022
1 parent bfd9b6f commit 7128677
Showing 1 changed file with 26 additions and 47 deletions.
73 changes: 26 additions & 47 deletions tribits/core/package_arch/TribitsPackageMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -408,40 +408,8 @@ endmacro()
#
macro(tribits_add_test_directories)

if (CURRENTLY_PROCESSING_SUBPACKAGE)

# This is a subpackage being processed

if(NOT ${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_subpackage() before tribits_add_test_directories()"
" in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
endif()

if(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_add_test_directories() before"
" tribits_subpackage_postprocess() in"
" ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
endif()

else()

# This is a package being processed

if(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_DECL_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_package() or tribits_package_decl() before"
" tribits_add_test_directories() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
endif()

if(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_add_test_directories() before "
" tribits_package_postprocess() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
endif()

endif()
tribits_add_test_example_directories_assert_call_context(
tribits_add_test_directories)

if(${PACKAGE_NAME}_ENABLE_TESTS OR ${PARENT_PACKAGE_NAME}_ENABLE_TESTS)
foreach(TEST_DIR ${ARGN})
Expand Down Expand Up @@ -563,46 +531,57 @@ endmacro()
#
macro(tribits_add_example_directories)

tribits_add_test_example_directories_assert_call_context(
tribits_add_example_directories)

if(${PACKAGE_NAME}_ENABLE_EXAMPLES OR ${PARENT_PACKAGE_NAME}_ENABLE_EXAMPLES)
foreach(EXAMPLE_DIR ${ARGN})
tribits_trace_file_processing(PACKAGE ADD_SUBDIR
"${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_DIR}/CMakeLists.txt")
add_subdirectory(${EXAMPLE_DIR})
endforeach()
endif()

endmacro()


macro(tribits_add_test_example_directories_assert_call_context macroName)

if (CURRENTLY_PROCESSING_SUBPACKAGE)

# This is a subpackage being processed

if(NOT ${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_subpackage() before tribits_add_example_directories()"
"Must call tribits_subpackage() before ${macroName}()"
" in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
endif()

if(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_add_example_directories() before "
" tribits_subpackage_postprocess() in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
"Must call ${macroName}() before"
" tribits_subpackage_postprocess() in"
" ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
endif()

else()

# This is a package being processed

if(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_DECL_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_package() or tribits_package_decl() before"
" tribits_add_example_directories() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
" ${macroName}() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
endif()

if(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
tribits_report_invalid_tribits_usage(
"Must call tribits_add_example_directories() before "
"Must call ${macroName}() before "
" tribits_package_postprocess() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
endif()

endif()

if(${PACKAGE_NAME}_ENABLE_EXAMPLES OR ${PARENT_PACKAGE_NAME}_ENABLE_EXAMPLES)
foreach(EXAMPLE_DIR ${ARGN})
tribits_trace_file_processing(PACKAGE ADD_SUBDIR
"${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_DIR}/CMakeLists.txt")
add_subdirectory(${EXAMPLE_DIR})
endforeach()
endif()

endmacro()


Expand Down

0 comments on commit 7128677

Please sign in to comment.