diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h index 9ca9cbe1c..b1ae20289 100644 --- a/Source/cmAddLibraryCommand.h +++ b/Source/cmAddLibraryCommand.h @@ -112,6 +112,26 @@ public: "(and its per-configuration version IMPORTED_LOCATION_) " "which specifies the location of the main library file on disk. " "See documentation of the IMPORTED_* properties for more information." + "\n" + "The signature\n" + " add_library( OBJECT ...)\n" + "creates a special \"object library\" target. " + "An object library compiles source files but does not archive or link " + "their object files into a library. " + "Instead other targets created by add_library or add_executable may " + "reference the objects using an expression of the form " + "$ as a source, where \"objlib\" is the " + "object library name. " + "For example:\n" + " add_library(... $ ...)\n" + " add_executable(... $ ...)\n" + "will include objlib's object files in a library and an executable " + "along with those compiled from their own sources. " + "Object libraries may contain only sources (and headers) that compile " + "to object files. " + "They may contain custom commands generating such sources, but not " + "PRE_BUILD, PRE_LINK, or POST_BUILD commands. " + "Object libraries cannot be imported, exported, installed, or linked." ; } diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 5f125a42f..c0b7cd617 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -199,6 +199,7 @@ IF(BUILD_TESTING) ADD_TEST_MACRO(CxxOnly CxxOnly) ADD_TEST_MACRO(IPO COnly/COnly) ADD_TEST_MACRO(OutDir runtime/OutDir) + ADD_TEST_MACRO(ObjectLibrary UseCshared) ADD_TEST_MACRO(NewlineArgs NewlineArgs) ADD_TEST_MACRO(SetLang SetLang) ADD_TEST_MACRO(ExternalOBJ ExternalOBJ) diff --git a/Tests/ObjectLibrary/A/CMakeLists.txt b/Tests/ObjectLibrary/A/CMakeLists.txt new file mode 100644 index 000000000..e0a620e5c --- /dev/null +++ b/Tests/ObjectLibrary/A/CMakeLists.txt @@ -0,0 +1,17 @@ +# Add -fPIC so objects can be used in shared libraries. +# TODO: Need property for this. +if(CMAKE_SHARED_LIBRARY_C_FLAGS) + set(CMAKE_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_C_FLAGS}") +endif() + +add_definitions(-DA) + +add_custom_command( + OUTPUT a1.c + DEPENDS a1.c.in + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/a1.c.in + ${CMAKE_CURRENT_BINARY_DIR}/a1.c + ) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +add_library(A OBJECT a1.c a2.c) diff --git a/Tests/ObjectLibrary/A/a.h b/Tests/ObjectLibrary/A/a.h new file mode 100644 index 000000000..6bfbc82a0 --- /dev/null +++ b/Tests/ObjectLibrary/A/a.h @@ -0,0 +1,6 @@ +#ifndef A +# error "A not defined" +#endif +#ifdef B +# error "B must not be defined" +#endif diff --git a/Tests/ObjectLibrary/A/a1.c.in b/Tests/ObjectLibrary/A/a1.c.in new file mode 100644 index 000000000..d1eaf58fd --- /dev/null +++ b/Tests/ObjectLibrary/A/a1.c.in @@ -0,0 +1,2 @@ +#include "a.h" +int a1(void) { return 0; } diff --git a/Tests/ObjectLibrary/A/a2.c b/Tests/ObjectLibrary/A/a2.c new file mode 100644 index 000000000..d8f225eb7 --- /dev/null +++ b/Tests/ObjectLibrary/A/a2.c @@ -0,0 +1,2 @@ +#include "a.h" +int a2(void) { return 0; } diff --git a/Tests/ObjectLibrary/AB.def b/Tests/ObjectLibrary/AB.def new file mode 100644 index 000000000..3f2b5c054 --- /dev/null +++ b/Tests/ObjectLibrary/AB.def @@ -0,0 +1,5 @@ +EXPORTS +a1 +a2 +b1 +b2 diff --git a/Tests/ObjectLibrary/B/CMakeLists.txt b/Tests/ObjectLibrary/B/CMakeLists.txt new file mode 100644 index 000000000..498d45df1 --- /dev/null +++ b/Tests/ObjectLibrary/B/CMakeLists.txt @@ -0,0 +1,15 @@ +if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6") + # VS 6 generator does not use per-target object locations. + set(vs6 _vs6) +endif() + +# Add -fPIC so objects can be used in shared libraries. +# TODO: Need property for this. +if(CMAKE_SHARED_LIBRARY_C_FLAGS) + set(CMAKE_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_C_FLAGS}") +endif() + +add_definitions(-DB) +add_library(B OBJECT b1.c b2.c) +add_library(Bexport OBJECT b1${vs6}.c b2${vs6}.c) +set_property(TARGET Bexport PROPERTY COMPILE_DEFINITIONS Bexport) diff --git a/Tests/ObjectLibrary/B/b.h b/Tests/ObjectLibrary/B/b.h new file mode 100644 index 000000000..632004dd9 --- /dev/null +++ b/Tests/ObjectLibrary/B/b.h @@ -0,0 +1,11 @@ +#ifdef A +# error "A must not be defined" +#endif +#ifndef B +# error "B not defined" +#endif +#if defined(_WIN32) && defined(Bexport) +# define EXPORT_B __declspec(dllexport) +#else +# define EXPORT_B +#endif diff --git a/Tests/ObjectLibrary/B/b1.c b/Tests/ObjectLibrary/B/b1.c new file mode 100644 index 000000000..fdeffe491 --- /dev/null +++ b/Tests/ObjectLibrary/B/b1.c @@ -0,0 +1,2 @@ +#include "b.h" +EXPORT_B int b1(void) { return 0; } diff --git a/Tests/ObjectLibrary/B/b1_vs6.c b/Tests/ObjectLibrary/B/b1_vs6.c new file mode 100644 index 000000000..b606e10e6 --- /dev/null +++ b/Tests/ObjectLibrary/B/b1_vs6.c @@ -0,0 +1 @@ +#include "b1.c" diff --git a/Tests/ObjectLibrary/B/b2.c b/Tests/ObjectLibrary/B/b2.c new file mode 100644 index 000000000..6e0d17cbe --- /dev/null +++ b/Tests/ObjectLibrary/B/b2.c @@ -0,0 +1,2 @@ +#include "b.h" +EXPORT_B int b2(void) { return 0; } diff --git a/Tests/ObjectLibrary/B/b2_vs6.c b/Tests/ObjectLibrary/B/b2_vs6.c new file mode 100644 index 000000000..d96a43e04 --- /dev/null +++ b/Tests/ObjectLibrary/B/b2_vs6.c @@ -0,0 +1 @@ +#include "b2.c" diff --git a/Tests/ObjectLibrary/CMakeLists.txt b/Tests/ObjectLibrary/CMakeLists.txt new file mode 100644 index 000000000..87234159f --- /dev/null +++ b/Tests/ObjectLibrary/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 2.8) +project(ObjectLibrary C) + +add_subdirectory(A) +add_subdirectory(B) + +add_library(Cstatic STATIC c.c $ $) +add_executable(UseCstatic main.c) +target_link_libraries(UseCstatic Cstatic) + +add_library(Cshared SHARED c.c $ $) +add_executable(UseCshared main.c) +set_property(TARGET UseCshared PROPERTY COMPILE_DEFINITIONS SHARED_C) +target_link_libraries(UseCshared Cshared) + +add_executable(UseCinternal main.c c.c $ $) + +if("${CMAKE_GENERATOR}" MATCHES "^Visual Studio (6|7|7 .NET 2003)$") + # VS 6 and 7 generators do not add objects as sources so we need a + # dummy object to convince the IDE to build the targets below. + set(dummy dummy.obj) # In MinGW: gcc -c dummy.c -o dummy.obj +elseif("${CMAKE_GENERATOR}" MATCHES "Xcode") + # Xcode does not seem to support targets without sources. + set(dummy dummy.c) +endif() + +# Test static library without its own sources. +add_library(ABstatic STATIC ${dummy} $ $) +add_executable(UseABstatic mainAB.c) +target_link_libraries(UseABstatic ABstatic) + +# Test module definition file to export object library symbols in the test +# below if the platform needs and supports it. +set(ABshared_SRCS $) +if(CMAKE_LINK_DEF_FILE_FLAG OR NOT WIN32) + list(APPEND ABshared_SRCS $ AB.def) +else() + set(NO_A NO_A) + list(APPEND ABshared_SRCS $) +endif() + +# Test shared library without its own sources. +add_library(ABshared SHARED ${dummy} ${ABshared_SRCS}) +add_executable(UseABshared mainAB.c) +set_property(TARGET UseABshared PROPERTY COMPILE_DEFINITIONS SHARED_B ${NO_A}) +target_link_libraries(UseABshared ABshared) + +# Test executable without its own sources. +add_library(ABmain OBJECT mainAB.c) +add_executable(UseABinternal ${dummy} + $ $ $ + ) diff --git a/Tests/ObjectLibrary/c.c b/Tests/ObjectLibrary/c.c new file mode 100644 index 000000000..968095b8b --- /dev/null +++ b/Tests/ObjectLibrary/c.c @@ -0,0 +1,19 @@ +#if defined(_WIN32) && defined(Cshared_EXPORTS) +# define EXPORT_C __declspec(dllexport) +#else +# define EXPORT_C +#endif + +extern int a1(void); +extern int a2(void); +extern int b1(void); +extern int b2(void); +EXPORT_C int c(void) +{ + return 0 + + a1() + + a2() + + b1() + + b2() + ; +} diff --git a/Tests/ObjectLibrary/dummy.c b/Tests/ObjectLibrary/dummy.c new file mode 100644 index 000000000..2b17d816d --- /dev/null +++ b/Tests/ObjectLibrary/dummy.c @@ -0,0 +1 @@ +int dummy(void) {return 0;} diff --git a/Tests/ObjectLibrary/dummy.obj b/Tests/ObjectLibrary/dummy.obj new file mode 100644 index 000000000..77f6f2f1b Binary files /dev/null and b/Tests/ObjectLibrary/dummy.obj differ diff --git a/Tests/ObjectLibrary/main.c b/Tests/ObjectLibrary/main.c new file mode 100644 index 000000000..6819f1c6d --- /dev/null +++ b/Tests/ObjectLibrary/main.c @@ -0,0 +1,16 @@ +#if defined(_WIN32) && defined(SHARED_C) +# define IMPORT_C __declspec(dllimport) +#else +# define IMPORT_C +#endif +extern IMPORT_C int b1(void); +extern IMPORT_C int b2(void); +extern IMPORT_C int c(void); +int main(void) +{ + return 0 + + c() + + b1() + + b2() + ; +} diff --git a/Tests/ObjectLibrary/mainAB.c b/Tests/ObjectLibrary/mainAB.c new file mode 100644 index 000000000..556898b83 --- /dev/null +++ b/Tests/ObjectLibrary/mainAB.c @@ -0,0 +1,22 @@ +#if defined(_WIN32) && defined(SHARED_B) +# define IMPORT_B __declspec(dllimport) +#else +# define IMPORT_B +#endif +extern IMPORT_B int b1(void); +extern IMPORT_B int b2(void); +#ifndef NO_A +extern int a1(void); +extern int a2(void); +#endif +int main(void) +{ + return 0 +#ifndef NO_A + + a1() + + a2() +#endif + + b1() + + b2() + ; +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 63fc9f8f3..0b79efa6a 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -40,5 +40,7 @@ macro(add_RunCMake_test test) ) endmacro() +add_RunCMake_test(ObjectLibrary) + add_RunCMake_test(build_command) add_RunCMake_test(find_package) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt new file mode 100644 index 000000000..b31225b48 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake b/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake new file mode 100644 index 000000000..aa3514d90 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake @@ -0,0 +1 @@ +add_library(A OBJECT a.c bad.def) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt new file mode 100644 index 000000000..906cf0b64 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake b/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake new file mode 100644 index 000000000..7957c99f2 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake @@ -0,0 +1 @@ +add_library(A OBJECT a.c bad.obj) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt new file mode 100644 index 000000000..a1cac36fa --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at BadSourceExpression1.cmake:1 \(add_library\): + Unrecognized generator expression: + + \$ +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake new file mode 100644 index 000000000..020c9a00f --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake @@ -0,0 +1 @@ +add_library(A STATIC a.c $) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt new file mode 100644 index 000000000..f1fcbe85f --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake new file mode 100644 index 000000000..ed5dc4335 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake @@ -0,0 +1 @@ +add_library(A STATIC a.c $) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt new file mode 100644 index 000000000..ad14a3513 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake new file mode 100644 index 000000000..c3d9a622d --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake @@ -0,0 +1,2 @@ +add_library(NotObjLib STATIC a.c) +add_library(A STATIC a.c $) diff --git a/Tests/RunCMake/ObjectLibrary/CMakeLists.txt b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt new file mode 100644 index 000000000..a7f077912 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} C) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/ObjectLibrary/Export-result.txt b/Tests/RunCMake/ObjectLibrary/Export-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Export-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/Export-stderr.txt b/Tests/RunCMake/ObjectLibrary/Export-stderr.txt new file mode 100644 index 000000000..bdadca488 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Export-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/Export.cmake b/Tests/RunCMake/ObjectLibrary/Export.cmake new file mode 100644 index 000000000..a3f104e29 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Export.cmake @@ -0,0 +1,2 @@ +add_library(A OBJECT a.c) +export(TARGETS A FILE AExport.cmake) diff --git a/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake b/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake new file mode 100644 index 000000000..0796c21ba --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake @@ -0,0 +1,15 @@ +enable_language(CXX) +add_library(A OBJECT a.cxx) +add_library(B STATIC a.c $) + +# Verify that object library languages are propagated. +export(TARGETS B NAMESPACE Exp FILE BExport.cmake) +include(${CMAKE_CURRENT_BINARY_DIR}/BExport.cmake) +get_property(configs TARGET ExpB PROPERTY IMPORTED_CONFIGURATIONS) +foreach(c ${configs}) + get_property(langs TARGET ExpB PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES_${c}) + list(FIND langs CXX pos) + if(${pos} LESS 0) + message(FATAL_ERROR "Target export does not list object library languages.") + endif() +endforeach() diff --git a/Tests/RunCMake/ObjectLibrary/Import-result.txt b/Tests/RunCMake/ObjectLibrary/Import-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Import-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/Import-stderr.txt b/Tests/RunCMake/ObjectLibrary/Import-stderr.txt new file mode 100644 index 000000000..74b496ab8 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Import-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/Import.cmake b/Tests/RunCMake/ObjectLibrary/Import.cmake new file mode 100644 index 000000000..806b44a25 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Import.cmake @@ -0,0 +1 @@ +add_library(A OBJECT IMPORTED) diff --git a/Tests/RunCMake/ObjectLibrary/Install-result.txt b/Tests/RunCMake/ObjectLibrary/Install-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Install-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/Install-stderr.txt b/Tests/RunCMake/ObjectLibrary/Install-stderr.txt new file mode 100644 index 000000000..d2f9f4a37 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Install-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/Install.cmake b/Tests/RunCMake/ObjectLibrary/Install.cmake new file mode 100644 index 000000000..c1d214bd4 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Install.cmake @@ -0,0 +1,2 @@ +add_library(A OBJECT a.c) +install(TARGETS A DESTINATION lib) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt new file mode 100644 index 000000000..90e828bdb --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake new file mode 100644 index 000000000..5d7831a23 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake @@ -0,0 +1,2 @@ +add_library(AnObjLib OBJECT a.c) +target_link_libraries(AnObjLib OtherLib) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt new file mode 100644 index 000000000..8809f8933 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake new file mode 100644 index 000000000..113d6a841 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake @@ -0,0 +1,3 @@ +add_library(A STATIC a.c) +add_library(AnObjLib OBJECT a.c) +target_link_libraries(A AnObjLib) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt new file mode 100644 index 000000000..3295fcac3 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake new file mode 100644 index 000000000..616372949 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake @@ -0,0 +1,3 @@ +add_library(A SHARED a.c) +target_link_libraries(A AnObjLib) +add_library(AnObjLib OBJECT a.c) diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt new file mode 100644 index 000000000..d67b4ae32 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake b/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake new file mode 100644 index 000000000..d0ef34bfe --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake @@ -0,0 +1,2 @@ +add_library(A OBJECT a.c) +add_library(B OBJECT $) diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt b/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt b/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt new file mode 100644 index 000000000..4b067bbc3 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild.cmake b/Tests/RunCMake/ObjectLibrary/PostBuild.cmake new file mode 100644 index 000000000..dea9a099e --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PostBuild.cmake @@ -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" + ) diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt b/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt b/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt new file mode 100644 index 000000000..3b27a6da5 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild.cmake b/Tests/RunCMake/ObjectLibrary/PreBuild.cmake new file mode 100644 index 000000000..e4424c100 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreBuild.cmake @@ -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" + ) diff --git a/Tests/RunCMake/ObjectLibrary/PreLink-result.txt b/Tests/RunCMake/ObjectLibrary/PreLink-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreLink-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt b/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt new file mode 100644 index 000000000..947b9f177 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/ObjectLibrary/PreLink.cmake b/Tests/RunCMake/ObjectLibrary/PreLink.cmake new file mode 100644 index 000000000..b88905511 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreLink.cmake @@ -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" + ) diff --git a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake new file mode 100644 index 000000000..55db14dfd --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake @@ -0,0 +1,18 @@ +include(RunCMake) + +run_cmake(BadSourceExpression1) +run_cmake(BadSourceExpression2) +run_cmake(BadSourceExpression3) +run_cmake(BadObjSource1) +run_cmake(BadObjSource2) +run_cmake(Export) +run_cmake(ExportLanguages) +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) diff --git a/Tests/RunCMake/ObjectLibrary/a.c b/Tests/RunCMake/ObjectLibrary/a.c new file mode 100644 index 000000000..af20d3ff6 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/a.c @@ -0,0 +1 @@ +int a(void) { return 0; } diff --git a/Tests/RunCMake/ObjectLibrary/a.cxx b/Tests/RunCMake/ObjectLibrary/a.cxx new file mode 100644 index 000000000..ae9c87c49 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/a.cxx @@ -0,0 +1 @@ +extern "C" int acxx(void) { return 0; } diff --git a/Tests/RunCMake/ObjectLibrary/bad.def b/Tests/RunCMake/ObjectLibrary/bad.def new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/RunCMake/ObjectLibrary/bad.obj b/Tests/RunCMake/ObjectLibrary/bad.obj new file mode 100644 index 000000000..e69de29bb