1
cmake_minimum_required(VERSION 2.8)
2
project(ObjectLibrary C)
7
add_library(Cstatic STATIC c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
8
add_executable(UseCstatic main.c)
9
target_link_libraries(UseCstatic Cstatic)
11
add_library(Cshared SHARED c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
12
add_executable(UseCshared main.c)
13
set_property(TARGET UseCshared PROPERTY COMPILE_DEFINITIONS SHARED_C)
14
target_link_libraries(UseCshared Cshared)
16
add_executable(UseCinternal main.c c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
18
if("${CMAKE_GENERATOR}" MATCHES "^Visual Studio (6|7|7 .NET 2003)$")
19
# VS 6 and 7 generators do not add objects as sources so we need a
20
# dummy object to convince the IDE to build the targets below.
21
set(dummy dummy.obj) # In MinGW: gcc -c dummy.c -o dummy.obj
22
elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
23
# Xcode does not seem to support targets without sources.
27
# Test static library without its own sources.
28
add_library(ABstatic STATIC ${dummy} $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>)
29
add_executable(UseABstatic mainAB.c)
30
target_link_libraries(UseABstatic ABstatic)
32
# Test module definition file to export object library symbols in the test
33
# below if the platform needs and supports it.
34
set(ABshared_SRCS $<TARGET_OBJECTS:A>)
35
if(CMAKE_LINK_DEF_FILE_FLAG OR NOT WIN32)
36
list(APPEND ABshared_SRCS $<TARGET_OBJECTS:B> AB.def)
39
list(APPEND ABshared_SRCS $<TARGET_OBJECTS:Bexport>)
42
# Test shared library without its own sources.
43
add_library(ABshared SHARED ${dummy} ${ABshared_SRCS})
44
add_executable(UseABshared mainAB.c)
45
set_property(TARGET UseABshared PROPERTY COMPILE_DEFINITIONS SHARED_B ${NO_A})
46
target_link_libraries(UseABshared ABshared)
48
# Test executable without its own sources.
49
add_library(ABmain OBJECT mainAB.c)
50
add_executable(UseABinternal ${dummy}
51
$<TARGET_OBJECTS:ABmain> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>