mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-22 06:59:01 -06:00
ENH: Add if(TARGET) command
It is useful to be able to test if a target has been created. Often targets are created only inside conditions. Rather than storing the result of the condition manually for testing by other parts of the project, it is much easier for the other parts to just test for the target's existence. This will also be useful when find-modules start reporting results with IMPORTED targets and projects want to test if a certain target is available.
This commit is contained in:
@@ -16,6 +16,23 @@ IF(COMPLEX_TEST_CMAKELIB)
|
||||
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmtar)
|
||||
ENDIF(COMPLEX_TEST_CMAKELIB)
|
||||
|
||||
# Create an imported target for if(TARGET) test below.
|
||||
ADD_LIBRARY(ExeImportedTarget UNKNOWN IMPORTED)
|
||||
|
||||
# Test if(TARGET) command.
|
||||
IF(NOT TARGET CMakeTestLibrary)
|
||||
MESSAGE(FATAL_ERROR "IF(NOT TARGET CMakeTestLibrary) returned true!")
|
||||
ENDIF(NOT TARGET CMakeTestLibrary)
|
||||
IF(NOT TARGET ExeImportedTarget)
|
||||
MESSAGE(FATAL_ERROR "IF(NOT TARGET ExeImportedTarget) returned true!")
|
||||
ENDIF(NOT TARGET ExeImportedTarget)
|
||||
IF(TARGET LibImportedTarget)
|
||||
MESSAGE(FATAL_ERROR "IF(TARGET LibImportedTarget) returned true!")
|
||||
ENDIF(TARGET LibImportedTarget)
|
||||
IF(TARGET NotATarget)
|
||||
MESSAGE(FATAL_ERROR "IF(TARGET NotATarget) returned true!")
|
||||
ENDIF(TARGET NotATarget)
|
||||
|
||||
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
||||
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
||||
LINK_LIBRARIES(${COMPLEX_LIBS})
|
||||
|
||||
Reference in New Issue
Block a user