1# 2# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6 7cmake_minimum_required(VERSION 3.8.2) 8 9include_guard(GLOBAL) 10 11# Function for declaring target object files that are produced by an external project. This adds a custom_command 12# that forces a stale check on the object file after the External projects install step. 13# external_proj_target: Target name of the external project 14# external_prog_output_dir: Location of binary or install directory for external project 15# FILES: List of object files that exist in the external project 16function(DeclareExternalProjObjectFiles external_proj_target external_proj_output_dir) 17 # Parse the given files object files 18 cmake_parse_arguments(PARSE_ARGV 2 EXT_OBJECT "" "" "FILES") 19 if(NOT "${EXT_OBJECT_UNPARSED_ARGUMENTS}" STREQUAL "") 20 message(FATAL_ERROR "Unknown arguments to DeclareExternalProjObjectFiles") 21 endif() 22 # Necessary for FILES to be passed 23 if(NOT EXT_OBJECT_FILES) 24 message(FATAL_ERROR "NO FILES declared for ${external_proj_target}") 25 endif() 26 # Get external project binary and stamp dir properties 27 ExternalProject_Get_property(${external_proj_target} STAMP_DIR) 28 foreach(obj_file IN LISTS EXT_OBJECT_FILES) 29 # Generate a unique name based on the object files location 30 set(file_path ${external_proj_output_dir}/${obj_file}) 31 list(APPEND objfiles ${file_path}) 32 endforeach() 33 if(NOT (TARGET ${external_proj_target}-install)) 34 ExternalProject_Add_StepTargets(${external_proj_target} install) 35 endif() 36 add_custom_command( 37 OUTPUT ${objfiles} 38 COMMAND true 39 DEPENDS ${external_proj_target}-install ${STAMP_DIR}/${external_proj_target}-install 40 ) 41endfunction(DeclareExternalProjObjectFiles) 42