Commit 56831016 authored by Brad King's avatar Brad King

Test OBJECT library failure cases

Add "RunCMake.ObjectLibrary" test to verify that unsupported use cases
are rejected with errors:

* An OBJECT library may not reference another object library
* An OBJECT library may not be referenced in target_link_libraries
* An OBJECT library may not contain non-compiling sources
* An OBJECT library may not have pre/post build/link commands
* An OBJECT library may not be installed, exported, or imported

Also verify that invalid $<TARGET_OBJECTS:...> expressions are
diagnosed.
parent 69d3d183
......@@ -40,5 +40,7 @@ macro(add_RunCMake_test test)
)
endmacro()
add_RunCMake_test(ObjectLibrary)
add_RunCMake_test(build_command)
add_RunCMake_test(find_package)
CMake Error at BadObjSource1.cmake:1 \(add_library\):
OBJECT library "A" contains:
bad.def
but may contain only headers and sources that compile.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
CMake Error at BadObjSource2.cmake:1 \(add_library\):
OBJECT library "A" contains:
bad.obj
but may contain only headers and sources that compile.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
CMake Error at BadSourceExpression1.cmake:1 \(add_library\):
Unrecognized generator expression:
\$<BAD_EXPRESSION>
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A STATIC a.c $<BAD_EXPRESSION>)
CMake Error at BadSourceExpression2.cmake:1 \(add_library\):
Objects of target "DoesNotExist" referenced but no such target exists.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A STATIC a.c $<TARGET_OBJECTS:DoesNotExist>)
CMake Error at BadSourceExpression3.cmake:2 \(add_library\):
Objects of target "NotObjLib" referenced but is not an OBJECT library.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(NotObjLib STATIC a.c)
add_library(A STATIC a.c $<TARGET_OBJECTS:NotObjLib>)
cmake_minimum_required(VERSION 2.8)
project(${RunCMake_TEST} C)
include(${RunCMake_TEST}.cmake)
CMake Error at Export.cmake:2 \(export\):
export given OBJECT library "A" which may not be exported.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A OBJECT a.c)
export(TARGETS A FILE AExport.cmake)
CMake Error at Import.cmake:1 \(add_library\):
The OBJECT library type may not be used for IMPORTED libraries.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A OBJECT IMPORTED)
CMake Error at Install.cmake:2 \(install\):
install TARGETS given OBJECT library "A" which may not be installed.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A OBJECT a.c)
install(TARGETS A DESTINATION lib)
CMake Error at LinkObjLHS.cmake:2 \(target_link_libraries\):
Object library target "AnObjLib" may not link to anything.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(AnObjLib OBJECT a.c)
target_link_libraries(AnObjLib OtherLib)
CMake Error at LinkObjRHS1.cmake:3 \(target_link_libraries\):
Target "AnObjLib" of type OBJECT_LIBRARY may not be linked into another
target. One may link only to STATIC or SHARED libraries, or to executables
with the ENABLE_EXPORTS property set.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A STATIC a.c)
add_library(AnObjLib OBJECT a.c)
target_link_libraries(A AnObjLib)
CMake Error at LinkObjRHS2.cmake:1 \(add_library\):
Target "A" links to OBJECT library "AnObjLib" but this is not allowed. One
may link only to STATIC or SHARED libraries, or to executables with the
ENABLE_EXPORTS property set.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A SHARED a.c)
target_link_libraries(A AnObjLib)
add_library(AnObjLib OBJECT a.c)
CMake Error at ObjWithObj.cmake:2 \(add_library\):
Only executables and non-OBJECT libraries may reference target objects.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A OBJECT a.c)
add_library(B OBJECT $<TARGET_OBJECTS:A>)
CMake Error at PostBuild.cmake:2 \(add_custom_command\):
Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or
POST_BUILD commands.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A OBJECT a.c)
add_custom_command(TARGET A POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "A post-build"
)
CMake Error at PreBuild.cmake:2 \(add_custom_command\):
Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or
POST_BUILD commands.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A OBJECT a.c)
add_custom_command(TARGET A PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "A pre-build"
)
CMake Error at PreLink.cmake:2 \(add_custom_command\):
Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or
POST_BUILD commands.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
add_library(A OBJECT a.c)
add_custom_command(TARGET A PRE_LINK
COMMAND ${CMAKE_COMMAND} -E echo "A pre-link"
)
include(RunCMake)
run_cmake(BadSourceExpression1)
run_cmake(BadSourceExpression2)
run_cmake(BadSourceExpression3)
run_cmake(BadObjSource1)
run_cmake(BadObjSource2)
run_cmake(Export)
run_cmake(Import)
run_cmake(Install)
run_cmake(LinkObjLHS)
run_cmake(LinkObjRHS1)
run_cmake(LinkObjRHS2)
run_cmake(ObjWithObj)
run_cmake(PostBuild)
run_cmake(PreBuild)
run_cmake(PreLink)
int a(void) { return 0; }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment