Skip to content

Commit

Permalink
WIP: Add TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE() (#200)
Browse files Browse the repository at this point in the history
This will allow adding other modes.
  • Loading branch information
bartlettroscoe committed May 8, 2019
1 parent 5c135bc commit 5bb1101
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 101 deletions.
11 changes: 6 additions & 5 deletions test/core/ExamplesUnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4306,7 +4306,8 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithSubpkgsWithUserErrors_SU
-DsubPackageA_DOUBLE_SUBPACKAGE_INIT=TRUE
.
PASS_REGULAR_EXPRESSION_ALL
"Already called TRIBITS_SUBPACKGE[(][)] for thePkgWithSubpkgsWithUserErrors"
"Already called TRIBITS_SUBPACKGE[(][)] for the PkgWithSubpkgsWithUserErrors"
"subpackage A"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

Expand All @@ -4317,8 +4318,8 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithSubpkgsWithUserErrors_SU
-DsubPAckageA_DOUBLE_SUBPACKAGE_POSTPROCESS=TRUE
.
PASS_REGULAR_EXPRESSION_ALL
"Already called TRIBITS_SUBPACKGE_POSTPROCESS[(][)] for"
"thePkgWithSubpkgsWithUserErrors subpackage A"
"Already called TRIBITS_SUBPACKGE_POSTPROCESS[(][)] for the"
"PkgWithSubpkgsWithUserErrors subpackage A"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

Expand All @@ -4329,8 +4330,8 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithSubpkgsWithUserErrors_SU
-DsubPAckageA_DOUBLE_SUBPACKAGE_POSTPROCESS=FALSE
.
PASS_REGULAR_EXPRESSION_ALL
"TRIBITS_SUBPACKAGE[(][)] must be called before"
"TRIBITS_SUBPACKAGE_POSTPROCESS[(][)]for the PkgWithSubpkgsWithUserErrors"
"TRIBITS_SUBPACKAGE[(][)] must be called before TRIBITS_SUBPACKAGE_POSTPROCESS[(][)]"
" for the PkgWithSubpkgsWithUserErrors"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

Expand Down
46 changes: 27 additions & 19 deletions tribits/core/package_arch/TribitsAddExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ INCLUDE(TribitsAddExecutableTestHelpers)
INCLUDE(TribitsCommonArgsHelpers)
INCLUDE(TribitsAddTestHelpers)
INCLUDE(TribitsGeneralMacros)
INCLUDE(TribitsAssertCorrectTribitsUsage)

INCLUDE(PrintVar)
INCLUDE(AppendSet)
Expand Down Expand Up @@ -344,12 +345,14 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
# This is a subpackage being processed

IF(NOT ${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_EXECUTABLE()"
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_EXECUTABLE()"
" in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_EXECUTABLE() before "
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_ADD_EXECUTABLE() before "
" TRIBITS_SUBPACKAGE_POSTPROCESS() in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand All @@ -358,12 +361,14 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
# This is a package being processed

IF(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_DECL_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
" TRIBITS_ADD_EXECUTABLE() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_EXECUTABLE() before "
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_ADD_EXECUTABLE() before "
" TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand Down Expand Up @@ -488,25 +493,28 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
FOREACH(IMPORTEDLIB ${PARSE_IMPORTEDLIBS})
SET(PREFIXED_LIB "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}${IMPORTEDLIB}")
IF (${PREFIXED_LIB}_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is not allowed to be a TESTONLY lib!"
" Use TESTONLYLIBS instead!" )
MESSAGE(FATAL_ERROR
"ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is not allowed to be a TESTONLY lib!"
" Use TESTONLYLIBS instead!" )
ENDIF()
LIST(FIND ${PACKAGE_NAME}_LIBRARIES ${PREFIXED_LIB} FOUND_IDX)
IF (NOT FOUND_IDX EQUAL -1)
MESSAGE(FATAL_ERROR "ERROR: Lib '${IMPORTEDLIB}' in IMPORTEDLIBS is in"
" this SE package and is *not* an external lib!"
" TriBITS takes care of linking against libs the current"
" SE package automatically. Please remove '${IMPORTEDLIB}' from IMPORTEDLIBS!")
MESSAGE(FATAL_ERROR
"ERROR: Lib '${IMPORTEDLIB}' in IMPORTEDLIBS is in"
" this SE package and is *not* an external lib!"
" TriBITS takes care of linking against libs the current"
" SE package automatically. Please remove '${IMPORTEDLIB}' from IMPORTEDLIBS!")
ELSEIF (TARGET ${PREFIXED_LIB})
MESSAGE(FATAL_ERROR "ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is *not* an external library but instead is a library"
" defined in this CMake project!"
" TriBITS takes care of linking against libraries in dependent upstream"
" SE packages. If you want to link to a library in an upstream SE"
" package then add the SE package name for that library to the appropriate"
" list in this SE package's dependencies file"
" ${${PACKAGE_NAME}_SOURCE_DIR}/cmake/Dependencies.cmake")
MESSAGE(FATAL_ERROR
"ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is *not* an external library but instead is a library"
" defined in this CMake project!"
" TriBITS takes care of linking against libraries in dependent upstream"
" SE packages. If you want to link to a library in an upstream SE"
" package then add the SE package name for that library to the appropriate"
" list in this SE package's dependencies file"
" ${${PACKAGE_NAME}_SOURCE_DIR}/cmake/Dependencies.cmake")
ENDIF()
ENDFOREACH()

Expand Down
85 changes: 85 additions & 0 deletions tribits/core/package_arch/TribitsAssertCorrectTribitsUsage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# @HEADER
# ************************************************************************
#
# TriBITS: Tribal Build, Integrate, and Test System
# Copyright 2013 Sandia Corporation
#
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the Corporation nor the names of the
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ************************************************************************
# @HEADER

IF (__TribitsAssertCorrectTribitsUsage_INCLUDED__)
RETURN()
ELSE()
SET(__TribitsAssertCorrectTribitsUsage_INCLUDED__ TRUE)
ENDIF()

# Called to report incorrect usage
#
# Usage:
#
# TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE("<err_msg0>" "<err_msg1>" ...)
#
# Depending on the value of ${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE, this
# function will:
#
# * FATAL_ERROR: Calls MESSAGE(FATAL_ERROR "<error_message>")
# * SEND_ERROR: Calls MESSAGE(SEND_ERROR "<error_message>")
# * WARNING: Calls MESSAGE(WARNING "<error_message>")
# * IGNORE: Does not call MESSAGE() at all and is silent
#
# If '${${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE}' is empty on call, then
# `FATAL_ERROR` will be used.
#
FUNCTION(TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE)
IF ("${${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE}" STREQUAL "")
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE FATAL_ERROR)
ENDIF()
SET(PRINT_ERR_MSG)
IF (${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE STREQUAL "FATAL_ERROR")
SET(PRINT_ERR_MSG FATAL_ERROR)
ELSEIF (${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE STREQUAL "SEND_ERROR")
SET(PRINT_ERR_MSG SEND_ERROR)
ELSEIF (${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE STREQUAL "WARNING")
SET(PRINT_ERR_MSG WARNING)
ELSEIF (${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE STREQUAL "IGNORE")
SET(PRINT_ERR_MSG)
ELSE()
MESSAGE(FATAL_ERROR "Error, invalid value for"
" ${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE ="
" '${${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE}'!"
" Value values include 'FATAL_ERROR', 'SEND_ERROR', 'WARNING', and 'IGNORE'!")
ENDIF()
IF (PRINT_ERR_MSG)
MESSAGE(${PRINT_ERR_MSG} ${ARGN})
ENDIF()
ENDFUNCTION()
13 changes: 9 additions & 4 deletions tribits/core/package_arch/TribitsLibraryMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ INCLUDE(AppendStringVar)
INCLUDE(PrependGlobalSet)
INCLUDE(RemoveGlobalDuplicates)
INCLUDE(TribitsGeneralMacros)
INCLUDE(TribitsAssertCorrectTribitsUsage)
INCLUDE(SetAndIncDirs)

###
Expand Down Expand Up @@ -483,12 +484,14 @@ FUNCTION(TRIBITS_ADD_LIBRARY LIBRARY_NAME_IN)
# This is a subpackage being processed

IF(NOT ${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_LIBRARY()"
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_LIBRARY()"
" in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_LIBRARY() before "
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_ADD_LIBRARY() before "
" TRIBITS_SUBPACKAGE_POSTPROCESS() in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand All @@ -497,12 +500,14 @@ FUNCTION(TRIBITS_ADD_LIBRARY LIBRARY_NAME_IN)
# This is a package being processed

IF(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_DECL_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
" TRIBITS_ADD_LIBRARY() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_LIBRARY() before "
TRIBITS_ASSERT_CORRECT_TRIBITS_USAGE(
"Must call TRIBITS_ADD_LIBRARY() before "
" TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand Down
Loading

0 comments on commit 5bb1101

Please sign in to comment.