From 69d3d1835c5f4bdf9fbe5e920517a74d82482455 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 12 Mar 2012 14:41:34 -0400 Subject: Test OBJECT library success cases Add "ObjectLibrary" test to build and use OBJECT libraries. Build multiple object libraries in separate directories with different flags. Use a custom command to generate a source file in one OBJECT library. Reference the OBJECT libraries for inclusion in a STATIC library, a SHARED library, and an EXECUTABLE target. Use the static and shared libraries each in executables that end up using the object library symbols. Verify that object library symbols are exported from the shared library. --- Tests/CMakeLists.txt | 1 + Tests/ObjectLibrary/A/CMakeLists.txt | 17 +++++++++++++++++ Tests/ObjectLibrary/A/a.h | 6 ++++++ Tests/ObjectLibrary/A/a1.c.in | 2 ++ Tests/ObjectLibrary/A/a2.c | 2 ++ Tests/ObjectLibrary/B/CMakeLists.txt | 15 +++++++++++++++ Tests/ObjectLibrary/B/b.h | 11 +++++++++++ Tests/ObjectLibrary/B/b1.c | 2 ++ Tests/ObjectLibrary/B/b1_vs6.c | 1 + Tests/ObjectLibrary/B/b2.c | 2 ++ Tests/ObjectLibrary/B/b2_vs6.c | 1 + Tests/ObjectLibrary/CMakeLists.txt | 16 ++++++++++++++++ Tests/ObjectLibrary/c.c | 19 +++++++++++++++++++ Tests/ObjectLibrary/main.c | 16 ++++++++++++++++ 14 files changed, 111 insertions(+) create mode 100644 Tests/ObjectLibrary/A/CMakeLists.txt create mode 100644 Tests/ObjectLibrary/A/a.h create mode 100644 Tests/ObjectLibrary/A/a1.c.in create mode 100644 Tests/ObjectLibrary/A/a2.c create mode 100644 Tests/ObjectLibrary/B/CMakeLists.txt create mode 100644 Tests/ObjectLibrary/B/b.h create mode 100644 Tests/ObjectLibrary/B/b1.c create mode 100644 Tests/ObjectLibrary/B/b1_vs6.c create mode 100644 Tests/ObjectLibrary/B/b2.c create mode 100644 Tests/ObjectLibrary/B/b2_vs6.c create mode 100644 Tests/ObjectLibrary/CMakeLists.txt create mode 100644 Tests/ObjectLibrary/c.c create mode 100644 Tests/ObjectLibrary/main.c diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index cf4dc44..7baed2c 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 0000000..e0a620e --- /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 0000000..6bfbc82 --- /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 0000000..d1eaf58 --- /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 0000000..d8f225e --- /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/B/CMakeLists.txt b/Tests/ObjectLibrary/B/CMakeLists.txt new file mode 100644 index 0000000..498d45d --- /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 0000000..632004d --- /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 0000000..fdeffe4 --- /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 0000000..b606e10 --- /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 0000000..6e0d17c --- /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 0000000..d96a43e --- /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 0000000..1a07d1d --- /dev/null +++ b/Tests/ObjectLibrary/CMakeLists.txt @@ -0,0 +1,16 @@ +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 $ $) diff --git a/Tests/ObjectLibrary/c.c b/Tests/ObjectLibrary/c.c new file mode 100644 index 0000000..968095b --- /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/main.c b/Tests/ObjectLibrary/main.c new file mode 100644 index 0000000..6819f1c --- /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() + ; +} -- cgit v0.12 From 5683101669e677b5b8d7b50d817da54156afd626 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 12 Mar 2012 14:51:30 -0400 Subject: 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 $ expressions are diagnosed. --- Tests/RunCMake/CMakeLists.txt | 2 ++ Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt | 1 + Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt | 8 ++++++++ Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake | 1 + Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt | 1 + Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt | 8 ++++++++ Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake | 1 + .../ObjectLibrary/BadSourceExpression1-result.txt | 1 + .../ObjectLibrary/BadSourceExpression1-stderr.txt | 6 ++++++ Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake | 1 + .../ObjectLibrary/BadSourceExpression2-result.txt | 1 + .../ObjectLibrary/BadSourceExpression2-stderr.txt | 4 ++++ Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake | 1 + .../ObjectLibrary/BadSourceExpression3-result.txt | 1 + .../ObjectLibrary/BadSourceExpression3-stderr.txt | 4 ++++ Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake | 2 ++ Tests/RunCMake/ObjectLibrary/CMakeLists.txt | 3 +++ Tests/RunCMake/ObjectLibrary/Export-result.txt | 1 + Tests/RunCMake/ObjectLibrary/Export-stderr.txt | 4 ++++ Tests/RunCMake/ObjectLibrary/Export.cmake | 2 ++ Tests/RunCMake/ObjectLibrary/Import-result.txt | 1 + Tests/RunCMake/ObjectLibrary/Import-stderr.txt | 4 ++++ Tests/RunCMake/ObjectLibrary/Import.cmake | 1 + Tests/RunCMake/ObjectLibrary/Install-result.txt | 1 + Tests/RunCMake/ObjectLibrary/Install-stderr.txt | 4 ++++ Tests/RunCMake/ObjectLibrary/Install.cmake | 2 ++ Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt | 1 + Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt | 4 ++++ Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake | 2 ++ Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt | 1 + Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt | 6 ++++++ Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake | 3 +++ Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt | 1 + Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt | 6 ++++++ Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake | 3 +++ Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt | 1 + Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt | 4 ++++ Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake | 2 ++ Tests/RunCMake/ObjectLibrary/PostBuild-result.txt | 1 + Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt | 5 +++++ Tests/RunCMake/ObjectLibrary/PostBuild.cmake | 4 ++++ Tests/RunCMake/ObjectLibrary/PreBuild-result.txt | 1 + Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt | 5 +++++ Tests/RunCMake/ObjectLibrary/PreBuild.cmake | 4 ++++ Tests/RunCMake/ObjectLibrary/PreLink-result.txt | 1 + Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt | 5 +++++ Tests/RunCMake/ObjectLibrary/PreLink.cmake | 4 ++++ Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake | 17 +++++++++++++++++ Tests/RunCMake/ObjectLibrary/a.c | 1 + Tests/RunCMake/ObjectLibrary/bad.def | 0 Tests/RunCMake/ObjectLibrary/bad.obj | 0 51 files changed, 148 insertions(+) create mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/CMakeLists.txt create mode 100644 Tests/RunCMake/ObjectLibrary/Export-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/Export-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/Export.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/Import-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/Import-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/Import.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/Install-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/Install-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/Install.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/PostBuild-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/PostBuild.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/PreBuild-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/PreBuild.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/PreLink-result.txt create mode 100644 Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt create mode 100644 Tests/RunCMake/ObjectLibrary/PreLink.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/a.c create mode 100644 Tests/RunCMake/ObjectLibrary/bad.def create mode 100644 Tests/RunCMake/ObjectLibrary/bad.obj diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 63fc9f8..0b79efa 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 0000000..d00491f --- /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 0000000..b31225b --- /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 0000000..aa3514d --- /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 0000000..d00491f --- /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 0000000..906cf0b --- /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 0000000..7957c99 --- /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 0000000..d00491f --- /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 0000000..a1cac36 --- /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 0000000..020c9a0 --- /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 0000000..d00491f --- /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 0000000..f1fcbe8 --- /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 0000000..ed5dc43 --- /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 0000000..d00491f --- /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 0000000..ad14a35 --- /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 0000000..c3d9a62 --- /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 0000000..a7f0779 --- /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 0000000..d00491f --- /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 0000000..bdadca4 --- /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 0000000..a3f104e --- /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/Import-result.txt b/Tests/RunCMake/ObjectLibrary/Import-result.txt new file mode 100644 index 0000000..d00491f --- /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 0000000..74b496a --- /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 0000000..806b44a --- /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 0000000..d00491f --- /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 0000000..d2f9f4a --- /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 0000000..c1d214b --- /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 0000000..d00491f --- /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 0000000..90e828b --- /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 0000000..5d7831a --- /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 0000000..d00491f --- /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 0000000..8809f89 --- /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 0000000..113d6a8 --- /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 0000000..d00491f --- /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 0000000..3295fca --- /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 0000000..6163729 --- /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 0000000..d00491f --- /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 0000000..d67b4ae --- /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 0000000..d0ef34b --- /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 0000000..d00491f --- /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 0000000..4b067bb --- /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 0000000..dea9a09 --- /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 0000000..d00491f --- /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 0000000..3b27a6d --- /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 0000000..e4424c1 --- /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 0000000..d00491f --- /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 0000000..947b9f1 --- /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 0000000..b889055 --- /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 0000000..a74eaa8 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/ObjectLibrary/a.c b/Tests/RunCMake/ObjectLibrary/a.c new file mode 100644 index 0000000..af20d3f --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/a.c @@ -0,0 +1 @@ +int a(void) { return 0; } diff --git a/Tests/RunCMake/ObjectLibrary/bad.def b/Tests/RunCMake/ObjectLibrary/bad.def new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/ObjectLibrary/bad.obj b/Tests/RunCMake/ObjectLibrary/bad.obj new file mode 100644 index 0000000..e69de29 -- cgit v0.12 From db7ef82402bed3d941bea73d266ac5919f4eee15 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 12 Mar 2012 15:02:42 -0400 Subject: Test OBJECT library language propagation Teach the RunCMake.ObjectLibrary test to verify that languages used in an OBJECT library are propagated to targets that use it so that the languages can be included in link analysis. --- Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake | 15 +++++++++++++++ Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake | 1 + Tests/RunCMake/ObjectLibrary/a.cxx | 1 + 3 files changed, 17 insertions(+) create mode 100644 Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake create mode 100644 Tests/RunCMake/ObjectLibrary/a.cxx diff --git a/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake b/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake new file mode 100644 index 0000000..0796c21 --- /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/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake index a74eaa8..55db14d 100644 --- a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake +++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(BadSourceExpression3) run_cmake(BadObjSource1) run_cmake(BadObjSource2) run_cmake(Export) +run_cmake(ExportLanguages) run_cmake(Import) run_cmake(Install) run_cmake(LinkObjLHS) diff --git a/Tests/RunCMake/ObjectLibrary/a.cxx b/Tests/RunCMake/ObjectLibrary/a.cxx new file mode 100644 index 0000000..ae9c87c --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/a.cxx @@ -0,0 +1 @@ +extern "C" int acxx(void) { return 0; } -- cgit v0.12 From c3242500b62c3f81af46e086cc2225b53c023167 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 14 Mar 2012 09:24:26 -0400 Subject: Test OBJECT library use without other sources Reference OBJECT libraries for inclusion in targets that have no other sources to verify that the linker language propagates correctly from the object libraries. Test with a STATIC library, a SHARED library, and an EXECUTABLE target. Use the static and shared libraries each in executables that end up using the object library symbols. In VS 6, 7, and 7.1 add a dummy object file to convince the IDE to build the targets without sources. In Xcode add a dummy source file to convince it to build targets without sources. --- Tests/ObjectLibrary/AB.def | 5 +++++ Tests/ObjectLibrary/CMakeLists.txt | 36 ++++++++++++++++++++++++++++++++++++ Tests/ObjectLibrary/dummy.c | 1 + Tests/ObjectLibrary/dummy.obj | Bin 0 -> 498 bytes Tests/ObjectLibrary/mainAB.c | 22 ++++++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 Tests/ObjectLibrary/AB.def create mode 100644 Tests/ObjectLibrary/dummy.c create mode 100644 Tests/ObjectLibrary/dummy.obj create mode 100644 Tests/ObjectLibrary/mainAB.c diff --git a/Tests/ObjectLibrary/AB.def b/Tests/ObjectLibrary/AB.def new file mode 100644 index 0000000..3f2b5c0 --- /dev/null +++ b/Tests/ObjectLibrary/AB.def @@ -0,0 +1,5 @@ +EXPORTS +a1 +a2 +b1 +b2 diff --git a/Tests/ObjectLibrary/CMakeLists.txt b/Tests/ObjectLibrary/CMakeLists.txt index 1a07d1d..8723415 100644 --- a/Tests/ObjectLibrary/CMakeLists.txt +++ b/Tests/ObjectLibrary/CMakeLists.txt @@ -14,3 +14,39 @@ 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/dummy.c b/Tests/ObjectLibrary/dummy.c new file mode 100644 index 0000000..2b17d81 --- /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 0000000..77f6f2f Binary files /dev/null and b/Tests/ObjectLibrary/dummy.obj differ diff --git a/Tests/ObjectLibrary/mainAB.c b/Tests/ObjectLibrary/mainAB.c new file mode 100644 index 0000000..556898b --- /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() + ; +} -- cgit v0.12 From cd146c650e092dcbf91adf60ef697608c2ac7fa2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 15 Mar 2012 08:53:27 -0400 Subject: Document OBJECT library type in add_library command Describe the OBJECT library signature of add_library and the $ expressions needed to use object libraries. Also document the what is not allowed for object library targets. --- Source/cmAddLibraryCommand.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h index 9ca9cbe..b1ae202 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." ; } -- cgit v0.12