From d3ef7bf12d34461220b947cd01e7a06d9affd4c4 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Mon, 24 Jun 2019 23:46:16 -0600 Subject: [PATCH] CMake: Avoid using continue() This is, sadly, not added until CMake 3.4. This commit avoids continue() by restructuring the loops so that the conditions previously being used for continue() are no longer needed. The alternative would've been to encase the loop bodies massive ifs, but I find that to be a poor choice for readability. --- cmake/macros/PackageConfig.cmake | 25 ++++++++++++++++++------- cmake/modules/FindFCollada.cmake | 20 ++++++++++++++------ cmake/scripts/CopyPython.cmake | 13 ++++++------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/cmake/macros/PackageConfig.cmake b/cmake/macros/PackageConfig.cmake index f3032fc832..03fb49ff2f 100644 --- a/cmake/macros/PackageConfig.cmake +++ b/cmake/macros/PackageConfig.cmake @@ -329,15 +329,26 @@ function(export_packages filename) set(history) while(stack) # Remove head item from stack - list(GET stack 0 head) - list(REMOVE_AT stack 0) + unset(head) + while(NOT DEFINED head) + if(NOT stack) + break() + endif() - # Don't visit anything twice - list(FIND history "${head}" _index) - if(_index GREATER -1) - continue() - else() + list(GET stack 0 head) + list(REMOVE_AT stack 0) + + # Don't visit anything twice + list(FIND history "${head}" _index) + if(_index GREATER -1) + unset(head) + endif() + endwhile() + + if(head) list(APPEND history "${head}") + else() + break() endif() # If head isn't a target, add it to `libraries`, else recurse diff --git a/cmake/modules/FindFCollada.cmake b/cmake/modules/FindFCollada.cmake index 8db7f1ca00..fcf4ee492d 100644 --- a/cmake/modules/FindFCollada.cmake +++ b/cmake/modules/FindFCollada.cmake @@ -48,13 +48,17 @@ if(NOT MSVC AND list(APPEND _defines "FCOLLADA_DLL") endif() -foreach(_config RELEASE DEBUG) - # Make sure we have lib/includes for this config - if(NOT FCOLLADA_${_config}_LIBRARY OR NOT FCOLLADA_INCLUDE_DIR) - continue() +# Identify the configs which we have available +set(_configs) +if(FCOLLADA_INCLUDE_DIR) + if(FCOLLADA_RELEASE_LIBRARY) + list(APPEND _configs RELEASE) + endif() + if(FCOLLADA_DEBUG_LIBRARY) + list(APPEND _configs DEBUG) endif() - if(NOT _HAS_FCOLLADA_LIBRARY) + if(_configs) set(_HAS_FCOLLADA_LIBRARY ON) add_library(FCollada::FCollada UNKNOWN IMPORTED GLOBAL) @@ -63,7 +67,10 @@ foreach(_config RELEASE DEBUG) INTERFACE_INCLUDE_DIRECTORIES "${FCOLLADA_INCLUDE_DIR}") endif() - + +endif() + +foreach(_config ${_configs}) set_property(TARGET FCollada::FCollada APPEND PROPERTY IMPORTED_CONFIGURATIONS "${_config}") @@ -72,6 +79,7 @@ foreach(_config RELEASE DEBUG) endforeach(_config) unset(_config) +unset(_configs) unset(_defines) include(FindPackageHandleStandardArgs) diff --git a/cmake/scripts/CopyPython.cmake b/cmake/scripts/CopyPython.cmake index d1b786402a..b9fad3ef92 100644 --- a/cmake/scripts/CopyPython.cmake +++ b/cmake/scripts/CopyPython.cmake @@ -32,16 +32,15 @@ if(DEFINED SOURCE_DIR) file(GLOB_RECURSE py_files RELATIVE "${SOURCE_DIR}" "${SOURCE_DIR}/*.py") foreach(py_file ${py_files}) get_filename_component(py_file_parent "${py_file}" DIRECTORY) - if(NOT EXISTS "${SOURCE_DIR}/${py_file_parent}/__init__.py") - # The source file isn't part of a Python package, even though it is a .py - # file. Skip it. - continue() - endif() - file(TIMESTAMP "${SOURCE_DIR}/${py_file}" src_stamp) file(TIMESTAMP "${OUTPUT_DIR}/${py_file}" dst_stamp) - if(NOT src_stamp STREQUAL dst_stamp) + # The file is only copied if: + # - there's an __init__.py in its dir (i.e. file belongs to a package), and + # - the modification timestamp differs (i.e. file changed or never copied) + if(EXISTS "${SOURCE_DIR}/${py_file_parent}/__init__.py" + AND NOT src_stamp STREQUAL dst_stamp) + file(COPY "${SOURCE_DIR}/${py_file}" DESTINATION "${OUTPUT_DIR}/${py_file_parent}") set(changed YES) endif()