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.
This commit is contained in:
Sam Edwards 2019-06-24 23:46:16 -06:00
parent 1a237670e3
commit d3ef7bf12d
3 changed files with 38 additions and 20 deletions

View File

@ -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

View File

@ -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)

View File

@ -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()