Revision: 70024 http://sourceforge.net/p/brlcad/code/70024 Author: starseeker Date: 2017-07-29 14:40:46 +0000 (Sat, 29 Jul 2017) Log Message: ----------- Do some refactoring of CMAKEFLAGS tracking function
Modified Paths: -------------- brlcad/trunk/misc/CMake/BRLCAD_Util.cmake Modified: brlcad/trunk/misc/CMake/BRLCAD_Util.cmake =================================================================== --- brlcad/trunk/misc/CMake/BRLCAD_Util.cmake 2017-07-29 14:39:23 UTC (rev 70023) +++ brlcad/trunk/misc/CMake/BRLCAD_Util.cmake 2017-07-29 14:40:46 UTC (rev 70024) @@ -174,94 +174,100 @@ define_property(GLOBAL PROPERTY CMAKE_IGNORE_FILES BRIEF_DOCS "distcheck ignore files" FULL_DOCS "List of files known to CMake") define_property(GLOBAL PROPERTY CMAKE_IGNORE_DIRS BRIEF_DOCS "distcheck ignore dirs" FULL_DOCS "List of directories marked as fully known to CMake") +# If the build directory is not the same as the source directory, we can +# enforce the convention that only generated files be specified with their full +# name. +function(CHECK_SOURCE_DIR_FULLPATH ITEM_PATH) + + # We can only do this if BINARY_DIR != SOURCE_DIR + if(NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") + return() + endif(NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") + + # If it's a full path in the binary dir, it's fine + IS_SUBPATH("${CMAKE_BINARY_DIR}" "${ITEM_PATH}" SUBPATH_TEST) + if(NOT"${SUBPATH_TEST}" STREQUAL "0") + return() + endif(NOT "${SUBPATH_TEST}" STREQUAL "0") + + # If it's a full path in the source dir, it's fatal + IS_SUBPATH("${CMAKE_SOURCE_DIR}" "${ITEM_PATH}" SUBPATH_TEST) + if("${SUBPATH_TEST}" STREQUAL "1") + message(FATAL_ERROR "${ITEM} is listed in \"${CMAKE_CURRENT_SOURCE_DIR}\" using its absolute path. Please specify the location of this file using a relative path.") + endif("${SUBPATH_TEST}" STREQUAL "1") + +endfunction(CHECK_SOURCE_DIR_FULLPATH ITEM_PATH) + macro(CMAKEFILES) if(NOT BRLCAD_IS_SUBBUILD) - foreach(ITEM ${ARGN}) - set(CMAKEFILES_DO_TEST 1) - # The build targets will use certain keywords for arguments - - # before we proceed to do any ignoring based on those names, - # make sure the file is there. Normally attempting to ignore - # a non-existent file is a fatal error, but these keywords - # don't necessarily refer to files. - set(TARGET_FLAGS SHARED STATIC OBJECT WIN32 UNKNOWN IMPORTED MODULE INTERFACE EXCLUDE_FROM_ALL) - foreach(TARGET_FLAG ${TARGET_FLAGS}) - if("${TARGET_FLAG}" STREQUAL "${ITEM}") - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - set(CMAKEFILES_DO_TEST 0) - endif(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - endif("${TARGET_FLAG}" STREQUAL "${ITEM}") - endforeach(TARGET_FLAG ${TARGET_FLAGS}) - set(FUZZY_TARGET_FLAGS TARGET_OBJECTS) - foreach(TARGET_FLAG ${FUZZY_TARGET_FLAGS}) - if("${ITEM}" MATCHES "${TARGET_FLAG}") - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - set(CMAKEFILES_DO_TEST 0) - endif(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - endif("${ITEM}" MATCHES "${TARGET_FLAG}") - endforeach(TARGET_FLAG ${FUZZY_TARGET_FLAGS}) + # CMake flags to add_library/add_executable aren't going to be valid filenames - just + # yank them up front. + set(ITEMS ${ARGN}) + list(REMOVE_ITEM ITEMS SHARED STATIC OBJECT WIN32 UNKNOWN IMPORTED MODULE INTERFACE EXCLUDE_FROM_ALL) + list(FILTER ITEMS EXCLUDE REGEX ".*TARGET_OBJECTS.*") + foreach(ITEM ${ITEMS}) # Handled target flags, proceeding with tests. - if(CMAKEFILES_DO_TEST) - get_filename_component(ITEM_PATH "${ITEM}" PATH) - get_filename_component(ITEM_NAME "${ITEM}" NAME) - if(NOT "${ITEM_PATH}" STREQUAL "") - # If the build directory is not the same as the source - # directory, we can enforce the convention that only - # generated files be specified with their full name. - # If this becomes a problem with the third party build - # systems at some point in the future, we may have to - # exclude src/other paths from this check. - if(NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") - IS_SUBPATH("${CMAKE_BINARY_DIR}" "${ITEM_PATH}" SUBPATH_TEST) - if("${SUBPATH_TEST}" STREQUAL "0") - IS_SUBPATH("${CMAKE_SOURCE_DIR}" "${ITEM_PATH}" SUBPATH_TEST) - if("${SUBPATH_TEST}" STREQUAL "1") - message(FATAL_ERROR "${ITEM} is listed in \"${CMAKE_CURRENT_SOURCE_DIR}\" using its absolute path. Please specify the location of this file using a relative path.") - endif("${SUBPATH_TEST}" STREQUAL "1") - endif("${SUBPATH_TEST}" STREQUAL "0") - endif(NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") - # Ignore files specified using full paths, since they - # should be generated files and are not part of the - # source code repository. - get_filename_component(ITEM_ABS_PATH "${ITEM_PATH}" ABSOLUTE) - if(NOT "${ITEM_PATH}" STREQUAL "${ITEM_ABS_PATH}") - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - message(FATAL_ERROR "Attempting to ignore non-existent file ${ITEM}, in directory \"${CMAKE_CURRENT_SOURCE_DIR}\"") - endif(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - # Append files and directories to their respective lists. - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_DIRS "${ITEM_ABS_PATH}/${ITEM_NAME}") - else(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${ITEM_ABS_PATH}/${ITEM_NAME}") - endif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${ITEM_ABS_PATH}") - # Add the parent directories of the specified file or directory as well - - # the convention is that once at least one file or directory in a path is recorded - # by the build logic, the parent directories along that path have also been recorded. - while(NOT "${ITEM_PATH}" STREQUAL "") - get_filename_component(ITEM_NAME "${ITEM_PATH}" NAME) - get_filename_component(ITEM_PATH "${ITEM_PATH}" PATH) - if(NOT "${ITEM_PATH}" STREQUAL "") - get_filename_component(ITEM_ABS_PATH "${ITEM_PATH}" ABSOLUTE) - if(NOT "${ITEM_NAME}" STREQUAL "..") - set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${ITEM_ABS_PATH}") - endif(NOT "${ITEM_NAME}" STREQUAL "..") - endif(NOT "${ITEM_PATH}" STREQUAL "") - endwhile(NOT "${ITEM_PATH}" STREQUAL "") - endif(NOT "${ITEM_PATH}" STREQUAL "${ITEM_ABS_PATH}") - else(NOT "${ITEM_PATH}" STREQUAL "") - # The easy case - no path specified, so assume the current source directory. + get_filename_component(ITEM_PATH "${ITEM}" PATH) + get_filename_component(ITEM_NAME "${ITEM}" NAME) + if(NOT "${ITEM_PATH}" STREQUAL "") + + # If this becomes a problem with the third party build + # systems at some point in the future, we may have to + # exclude src/other paths from this check. + CHECK_SOURCE_DIR_FULLPATH("${ITEM_PATH}") + + # Ignore files specified using full paths, since they + # should be generated files and are not part of the + # source code repository. + get_filename_component(ITEM_ABS_PATH "${ITEM_PATH}" ABSOLUTE) + + if(NOT "${ITEM_PATH}" STREQUAL "${ITEM_ABS_PATH}") + + # Don't list things that aren't there if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") message(FATAL_ERROR "Attempting to ignore non-existent file ${ITEM}, in directory \"${CMAKE_CURRENT_SOURCE_DIR}\"") endif(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") + + # Append files and directories to their respective lists. if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM_NAME}") + set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_DIRS "${ITEM_ABS_PATH}/${ITEM_NAME}") else(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM_NAME}") + set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${ITEM_ABS_PATH}/${ITEM_NAME}") endif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") - endif(NOT "${ITEM_PATH}" STREQUAL "") - endif(CMAKEFILES_DO_TEST) - endforeach(ITEM ${ARGN}) + set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${ITEM_ABS_PATH}") + + # Add the parent directories of the specified file or directory as well - + # the convention is that once at least one file or directory in a path is recorded + # by the build logic, the parent directories along that path have also been recorded. + while(NOT "${ITEM_PATH}" STREQUAL "") + get_filename_component(ITEM_NAME "${ITEM_PATH}" NAME) + get_filename_component(ITEM_PATH "${ITEM_PATH}" PATH) + if(NOT "${ITEM_PATH}" STREQUAL "") + get_filename_component(ITEM_ABS_PATH "${ITEM_PATH}" ABSOLUTE) + if(NOT "${ITEM_NAME}" STREQUAL "..") + set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${ITEM_ABS_PATH}") + endif(NOT "${ITEM_NAME}" STREQUAL "..") + endif(NOT "${ITEM_PATH}" STREQUAL "") + endwhile(NOT "${ITEM_PATH}" STREQUAL "") + + endif(NOT "${ITEM_PATH}" STREQUAL "${ITEM_ABS_PATH}") + + else(NOT "${ITEM_PATH}" STREQUAL "") + + # The easy case - no path specified, so assume the current source directory. + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") + message(FATAL_ERROR "Attempting to ignore non-existent file ${ITEM}, in directory \"${CMAKE_CURRENT_SOURCE_DIR}\"") + endif(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") + + if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") + set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM_NAME}") + else(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") + set_property(GLOBAL APPEND PROPERTY CMAKE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM_NAME}") + endif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}") + + endif(NOT "${ITEM_PATH}" STREQUAL "") + endforeach(ITEM ${ITEMS}) endif(NOT BRLCAD_IS_SUBBUILD) endmacro(CMAKEFILES FILESLIST) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits