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.
This commit is contained in:
Brad King 2012-03-12 14:51:30 -04:00
parent 69d3d1835c
commit 5683101669
51 changed files with 148 additions and 0 deletions

View File

@ -40,5 +40,7 @@ macro(add_RunCMake_test test)
)
endmacro()
add_RunCMake_test(ObjectLibrary)
add_RunCMake_test(build_command)
add_RunCMake_test(find_package)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,8 @@
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\)

View File

@ -0,0 +1 @@
add_library(A OBJECT a.c bad.def)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,8 @@
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\)

View File

@ -0,0 +1 @@
add_library(A OBJECT a.c bad.obj)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error at BadSourceExpression1.cmake:1 \(add_library\):
Unrecognized generator expression:
\$<BAD_EXPRESSION>
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1 @@
add_library(A STATIC a.c $<BAD_EXPRESSION>)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
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\)

View File

@ -0,0 +1 @@
add_library(A STATIC a.c $<TARGET_OBJECTS:DoesNotExist>)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
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\)

View File

@ -0,0 +1,2 @@
add_library(NotObjLib STATIC a.c)
add_library(A STATIC a.c $<TARGET_OBJECTS:NotObjLib>)

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 2.8)
project(${RunCMake_TEST} C)
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
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\)

View File

@ -0,0 +1,2 @@
add_library(A OBJECT a.c)
export(TARGETS A FILE AExport.cmake)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
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\)

View File

@ -0,0 +1 @@
add_library(A OBJECT IMPORTED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
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\)

View File

@ -0,0 +1,2 @@
add_library(A OBJECT a.c)
install(TARGETS A DESTINATION lib)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
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\)

View File

@ -0,0 +1,2 @@
add_library(AnObjLib OBJECT a.c)
target_link_libraries(AnObjLib OtherLib)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
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\)

View File

@ -0,0 +1,3 @@
add_library(A STATIC a.c)
add_library(AnObjLib OBJECT a.c)
target_link_libraries(A AnObjLib)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
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\)

View File

@ -0,0 +1,3 @@
add_library(A SHARED a.c)
target_link_libraries(A AnObjLib)
add_library(AnObjLib OBJECT a.c)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
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\)

View File

@ -0,0 +1,2 @@
add_library(A OBJECT a.c)
add_library(B OBJECT $<TARGET_OBJECTS:A>)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,5 @@
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\)

View File

@ -0,0 +1,4 @@
add_library(A OBJECT a.c)
add_custom_command(TARGET A POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "A post-build"
)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,5 @@
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\)

View File

@ -0,0 +1,4 @@
add_library(A OBJECT a.c)
add_custom_command(TARGET A PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "A pre-build"
)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,5 @@
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\)

View File

@ -0,0 +1,4 @@
add_library(A OBJECT a.c)
add_custom_command(TARGET A PRE_LINK
COMMAND ${CMAKE_COMMAND} -E echo "A pre-link"
)

View File

@ -0,0 +1,17 @@
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)

View File

@ -0,0 +1 @@
int a(void) { return 0; }

View File

View File