Skip to content

Commit

Permalink
Slight macro clean up and update developers
Browse files Browse the repository at this point in the history
  • Loading branch information
white238 committed Oct 25, 2017
1 parent 33b5245 commit 9fe2ff9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 60 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Aaron Black ([email protected])
David A. Beckingsale ([email protected])
Richard Hornung ([email protected])
Randolph Settgast ([email protected])
Peter Robinson ([email protected])

LLNL-CODE-725085.

Expand Down
73 changes: 28 additions & 45 deletions cmake/BLTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -664,65 +664,51 @@ macro(blt_append_custom_compiler_flag)
endmacro(blt_append_custom_compiler_flag)




##------------------------------------------------------------------------------
## blt_find_libraries( FOUND_LIBS <FOUND_LIBS>
## REQUIRED_NAMES [libname1 [libname2 ...]]
## OPTIONAL_NAMES [libname1 [libname2 ...]]
## blt_find_libraries( FOUND_LIBS <FOUND_LIBS variable name>
## NAMES [libname1 [libname2 ...]]
## OPTIONAL [TRUE | FALSE ]
## PATHS [path1 [path2 ...]] )
##
## This command is used to find a list of libraries. A cache entry named by <FOUND_LIBS>
## 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}
Expand All @@ -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)
53 changes: 38 additions & 15 deletions cmake/SetupCodeChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -75,21 +75,26 @@ 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()

blt_add_uncrustify_check(CFG_FILE ${cfg_file} SRC_FILES ${_filt_sources})
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 <uncrusify_configuration_file>
## blt_add_uncrustify_check( CFG_FILE <uncrustify_configuration_file>
## FLAGS <additional_flags_to_uncrustify>
## COMMENT <additional_comment_for_target_invocation>
## WORKING_DIRECTORY <working_directory>
## REDIRECT <redirection_commands>
## SRC_FILES <list_of_src_files_to_uncrustify> )
##
##------------------------------------------------------------------------------
Expand All @@ -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}")
Expand All @@ -117,7 +129,11 @@ endmacro(blt_add_uncrustify_check)
##------------------------------------------------------------------------------
## - Macro for invoking uncrustify to apply formatting inplace
##
## blt_add_uncrustify_inplace(CFG_FILE <uncrusify_configuration_file>
## blt_add_uncrustify_inplace(CFG_FILE <uncrustify_configuration_file>
## FLAGS <additional_flags_to_uncrustify>
## COMMENT <additional_comment_for_target_invocation>
## WORKING_DIRECTORY <working_directory>
## REDIRECT <redirection_commands>
## SRC_FILES <list_of_src_files_to_uncrustify> )
##
##------------------------------------------------------------------------------
Expand All @@ -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}")
Expand Down

0 comments on commit 9fe2ff9

Please sign in to comment.