Brad King wrote: > The full solution is to refactor things enough that a new kind of > try_compile can be implemented. It should push the configuration > process state on a stack, run more CMake code in the isolated state > to add some targets, and then generate the build system for them > directly out of the temporary configuration state. Finally the > configuration stack would be popped back to the try_compile call and > the result variable would be set. This would allow the full state > of the main project to be used for generation of a try_compile, > including imported targets.
Are you sure? It seems to me it would be much easier and less duplicative to add a way to specify TARGETS in try_compile, and in cmCoreTryCompile, generate the IMPORTED targets there with whatever properties they have. cmake_minimum_required(VERSION 2.8) project(iface) find_package(Qt4 REQUIRED) include(CMakeParseArguments) macro(CHECK_CXX_SOURCE_COMPILES_COPY SOURCE) set(oneValueArgs VAR) set(multiValueArgs TARGETS) cmake_parse_arguments(_CSC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) if(NOT "${_CSC_VAR}" MATCHES "^${_CSC_VAR}$") return() endif() file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" "${SOURCE}\n") message(STATUS "Performing Test ${_CSC_VAR}") try_compile(${_CSC_VAR} ${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" # NOTE: This is new! TARGETS ${_CSC_TARGETS} OUTPUT_VARIABLE OUTPUT) foreach(_regex ${_FAIL_REGEX}) if("${OUTPUT}" MATCHES "${_regex}") set(${VAR} 0) endif() endforeach() if(${_CSC_VAR}) set(${_CSC_VAR} 1 CACHE INTERNAL "Test ${_CSC_VAR}") message(STATUS "Performing Test ${_CSC_VAR} - Success") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing C++ SOURCE FILE Test ${_CSC_VAR} succeded with the following output:\n" "${OUTPUT}\n" "Source file was:\n${SOURCE}\n") else() message(STATUS "Performing Test ${_CSC_VAR} - Failed") set(${_CSC_VAR} "" CACHE INTERNAL "Test ${_CSC_VAR}") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing C++ SOURCE FILE Test ${_CSC_VAR} failed with the following output:\n" "${OUTPUT}\n" "Source file was:\n${SOURCE}\n") endif() endmacro() CHECK_CXX_SOURCE_COMPILES_COPY( "#include <QApplication> #ifndef QT_GUI_LIB #error Expected QT_GUI_LIB #endif #ifndef QT_CORE_LIB #error Expected QT_CORE_LIB #endif int main(int argc, char **argv) { QApplication app(argc, argv); app.instance(); return 0; } " VAR TC_RESULT TARGETS Qt4::QtGui Qt4::QtCore ) message("TC_RESULT : ${TC_RESULT}") I pushed the try_compile_targets topic to my clone as a proof of concept, but it would likely need to be reworked from scratch (eg a cmExportFileGenerator subclass which can re-export imported targets). Any reason not to do it that way? Thanks, Steve. -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers