From 9fe2ff996a86e1f8ae14e0856d86628d5e8e84f9 Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 25 Oct 2017 11:47:21 -0700 Subject: [PATCH] Slight macro clean up and update developers --- LICENSE | 1 + cmake/BLTMacros.cmake | 73 ++++++++++++++----------------------- cmake/SetupCodeChecks.cmake | 53 +++++++++++++++++++-------- 3 files changed, 67 insertions(+), 60 deletions(-) diff --git a/LICENSE b/LICENSE index b2697122a..323d403b2 100644 --- a/LICENSE +++ b/LICENSE @@ -13,6 +13,7 @@ Aaron Black (black27@llnl.gov) David A. Beckingsale (beckingsale1@llnl.gov) Richard Hornung (hornung1@llnl.gov) Randolph Settgast (settgast1@llnl.gov) +Peter Robinson (robinson96@llnl.gov) LLNL-CODE-725085. diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index f78bd5e00..8ef675e09 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -664,65 +664,51 @@ macro(blt_append_custom_compiler_flag) endmacro(blt_append_custom_compiler_flag) - - ##------------------------------------------------------------------------------ -## blt_find_libraries( FOUND_LIBS -## REQUIRED_NAMES [libname1 [libname2 ...]] -## OPTIONAL_NAMES [libname1 [libname2 ...]] +## blt_find_libraries( FOUND_LIBS +## NAMES [libname1 [libname2 ...]] +## OPTIONAL [TRUE | FALSE ] ## PATHS [path1 [path2 ...]] ) ## -## This command is used to find a list of libraries. A cache entry named by -## is created to store the result of this command. If the libraries are found the -## results are stored in FOUND_LIBS. -## -## REQUIRED_NAMES lists the names of the libraries that are required to be found. +## This command is used to find a list of libraries. +## +## If the libraries are found the results are appended to the given FOUND_LIBS variable name. ## -## OPTIONAL_NAMES lists the names of the optional libraries to be found. +## NAMES lists the names of the libraries that will be searched for in the given PATHS. ## -## PATH lists the paths in which to search for NAMES. +## If OPTIONAL is set to TRUE, BLT will not produce an error message if any of the +## given libraries that are not found. The default value is FALSE. ## +## PATH lists the paths in which to search for NAMES. No system paths will be searched. ## ##------------------------------------------------------------------------------ macro(blt_find_libraries) - set(singleValueArgs FOUND_LIBS ) - - - set(multiValueArgs REQUIRED_NAMES - OPTIONAL_NAMES - PATHS ) + set(options ) + set(singleValueArgs FOUND_LIBS OPTIONAL) + set(multiValueArgs NAMES PATHS ) ## parse the arguments cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) - if ( NOT DEFINED arg_REQUIRED_NAMES ) - message(FATAL_ERROR "blt_find_libraries requires that the input variable REQUIRED_NAMES specify the library names you are searching for") + if ( NOT DEFINED arg_FOUND_LIBS ) + message(FATAL_ERROR "The blt_find_libraries required parameter FOUND_LIBS specifies the list that found libraries will be appended to.") + endif() + + if ( NOT DEFINED arg_NAMES ) + message(FATAL_ERROR "The blt_find_libraries required parameter NAMES specifies the library names you are searching for.") endif() if ( NOT DEFINED arg_PATHS ) - message(FATAL_ERROR "blt_find_libraries requires that the input variable PATHS specify the paths to search for NAMES") + message(FATAL_ERROR "The blt_find_libraries required parameter PATHS specifies the paths to search for NAMES.") endif() - foreach( lib ${arg_REQUIRED_NAMES} ) - unset( temp CACHE ) - find_library( temp NAMES ${lib} - PATHS ${arg_PATHS} - NO_DEFAULT_PATH - NO_CMAKE_ENVIRONMENT_PATH - NO_CMAKE_PATH - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) - if( temp ) - list( APPEND TEMP_LIBS ${temp} ) - else() - message(FATAL_ERROR "REQUIRED_NAMES entry ${lib} not found. These are not the libs you are looking for.") - endif() - endforeach() - - - foreach( lib ${arg_OPTIONAL_NAMES} ) + if ( NOT DEFINED arg_OPTIONAL) + set(arg_OPTIONAL FALSE) + endif() + + foreach( lib ${arg_NAMES} ) unset( temp CACHE ) find_library( temp NAMES ${lib} PATHS ${arg_PATHS} @@ -732,13 +718,10 @@ macro(blt_find_libraries) NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) if( temp ) - list( APPEND TEMP_LIBS ${temp} ) - else() - message( WARNING "OPTIONAL_NAMES entry ${lib} not found.") + list( APPEND ${arg_FOUND_LIBS} ${temp} ) + else if (${arg_OPTIONAL}) + message(FATAL_ERROR "NAMES entry ${lib} not found. These are not the libs you are looking for.") endif() endforeach() - - - set( ${arg_FOUND_LIBS} ${TEMP_LIBS} ) endmacro(blt_find_libraries) diff --git a/cmake/SetupCodeChecks.cmake b/cmake/SetupCodeChecks.cmake index b1657dc33..c44b722d9 100644 --- a/cmake/SetupCodeChecks.cmake +++ b/cmake/SetupCodeChecks.cmake @@ -66,7 +66,7 @@ macro(blt_add_code_check_targets cfg_file) if(UNCRUSTIFY_FOUND) # Only run uncrustify on C and C++ files # Note, we can later extend this by passing in a list of valid types to the macro - set(_fileTypes ".cpp" ".hpp" ".c" ".h") + set(_fileTypes ".cpp" ".hpp" ".cxx" ".hxx" ".cc" ".c" ".h" ".hh") # generate the filtered list of source files set(_filt_sources) @@ -75,7 +75,8 @@ macro(blt_add_code_check_targets cfg_file) list(FIND _fileTypes "${_ext}" _index) if(_index GREATER -1) - list(APPEND _filt_sources ${_file}) + file(RELATIVE_PATH _relpath ${CMAKE_CURRENT_BINARY_DIR} ${_file}) + list(APPEND _filt_sources ${_relpath}) endif() endforeach() @@ -83,13 +84,17 @@ macro(blt_add_code_check_targets cfg_file) blt_add_uncrustify_inplace(CFG_FILE ${cfg_file} SRC_FILES ${_filt_sources}) endif() -endmacro(blt_add_code_check_targets) +endmacro() ##------------------------------------------------------------------------------ ## - Macro for invoking uncrustify to check code formatting ## -## blt_add_uncrustify_check( CFG_FILE +## blt_add_uncrustify_check( CFG_FILE +## FLAGS +## COMMENT +## WORKING_DIRECTORY +## REDIRECT ## SRC_FILES ) ## ##------------------------------------------------------------------------------ @@ -99,15 +104,22 @@ macro(blt_add_uncrustify_check) ## parse the arguments to the macro set(options) - set(singleValueArgs CFG_FILE) - set(multiValueArgs SRC_FILES) + set(singleValueArgs CFG_FILE COMMENT WORKING_DIRECTORY) + set(multiValueArgs SRC_FILES FLAGS REDIRECT) cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + if(${arg_WORKING_DIRECTORY}) + set(_wd ${arg_WORKING_DIRECTORY}) + else() + set(_wd ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + add_custom_target("uncrustify_check_${PROJECT_NAME}" - ${UNCRUSTIFY_EXECUTABLE} - -c ${CMAKE_CURRENT_SOURCE_DIR}/${arg_CFG_FILE} --check ${arg_SRC_FILES} - COMMENT "Running uncrustify source code formatting checks.") + ${UNCRUSTIFY_EXECUTABLE} ${arg_FLAGS} + -c ${arg_CFG_FILE} --check ${arg_SRC_FILES} ${arg_REDIRECT} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running uncrustify source code formatting checks.") # hook our new target into the check dependency chain add_dependencies(uncrustify_check "uncrustify_check_${PROJECT_NAME}") @@ -117,7 +129,11 @@ endmacro(blt_add_uncrustify_check) ##------------------------------------------------------------------------------ ## - Macro for invoking uncrustify to apply formatting inplace ## -## blt_add_uncrustify_inplace(CFG_FILE +## blt_add_uncrustify_inplace(CFG_FILE +## FLAGS +## COMMENT +## WORKING_DIRECTORY +## REDIRECT ## SRC_FILES ) ## ##------------------------------------------------------------------------------ @@ -127,15 +143,22 @@ macro(blt_add_uncrustify_inplace) ## parse the arguments to the macro set(options) - set(singleValueArgs CFG_FILE) - set(multiValueArgs SRC_FILES) + set(singleValueArgs CFG_FILE COMMENT WORKING_DIRECTORY) + set(multiValueArgs SRC_FILES FLAGS REDIRECT) cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + if(${arg_WORKING_DIRECTORY}) + set(_wd ${arg_WORKING_DIRECTORY}) + else() + set(_wd ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + add_custom_target("uncrustify_inplace_${PROJECT_NAME}" - ${UNCRUSTIFY_EXECUTABLE} - -c ${CMAKE_CURRENT_SOURCE_DIR}/${arg_CFG_FILE} --no-backup ${arg_SRC_FILES} - COMMENT "Running uncrustify to apply code formatting settings.") + ${UNCRUSTIFY_EXECUTABLE} ${arg_FLAGS} + -c ${arg_CFG_FILE} --no-backup ${arg_SRC_FILES} ${arg_REDIRECT} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running uncrustify to apply code formatting settings.") # hook our new target into the uncrustify_inplace dependency chain add_dependencies(uncrustify_inplace "uncrustify_inplace_${PROJECT_NAME}")