CMakeLists.txt 4.48 KB
Newer Older
1
2
cmake_minimum_required (VERSION 2.7.20090711)
project(Export C CXX)
3

4
5
6
7
# Pretend that RelWithDebInfo should link to debug libraries to test
# the DEBUG_CONFIGURATIONS property.
set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug RelWithDebInfo)

8
add_library(testExe1lib STATIC testExe1lib.c) # not exported
9
add_executable(testExe1 testExe1.c)
10
target_link_libraries(testExe1 testExe1lib)
11
set_property(TARGET testExe1 PROPERTY VERSION 4)
12

13
add_library(testExe2libImp SHARED testExe2libImp.c)
14
set_property(TARGET testExe2libImp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
15
16
17
add_library(testExe2lib SHARED testExe2lib.c)
target_link_libraries(testExe2lib testExe2libImp)
set_property(TARGET testExe2lib PROPERTY LINK_INTERFACE_LIBRARIES "")
18
19
add_executable(testExe2 testExe2.c)
set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
20
set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
21
22
23
24
25

add_library(testLib1 STATIC testLib1.c)
add_library(testLib2 STATIC testLib2.c)
target_link_libraries(testLib2 testLib1)

26
add_library(testLib3Imp SHARED testLib3Imp.c)
27
set_property(TARGET testLib3Imp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
28
add_library(testLib3 SHARED testLib3.c)
29
30
target_link_libraries(testLib3 testLib3Imp)
set_property(TARGET testLib3 PROPERTY LINK_INTERFACE_LIBRARIES "")
31
32
set_property(TARGET testLib3 PROPERTY VERSION 1.2)
set_property(TARGET testLib3 PROPERTY SOVERSION 3)
33

34
35
36
37
38
39
40
41
42
# Test <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME[_<CONFIG>] properties.
set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_DEBUG testLib3dll-d)
set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_RELEASE testLib3dll-r)
set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME testLib3dll)
set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_DEBUG testLib3lib-d)
set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_RELEASE testLib3lib-r)
set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME testLib3lib)
set_property(TARGET testLib3 PROPERTY ARCHIVE_OUTPUT_NAME testLib3import)

43
44
45
add_library(testLib4 SHARED testLib4.c)
set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)

46
47
add_library(testLib5 SHARED testLib5.c)

48
49
add_library(testLib6 STATIC testLib6.cxx testLib6.c)

Brad King's avatar
Brad King committed
50
51
52
53
54
55
# Work-around: Visual Studio 6 does not support per-target object files.
set(VS6)
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  set(VS6 1)
endif("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")

56
57
58
59
60
61
62
63
# Test using the target_link_libraries command to set the
# LINK_INTERFACE_LIBRARIES* properties.  We construct two libraries
# providing the same two symbols.  In each library one of the symbols
# will work and the other one will fail to link.  The import part of
# this test will try to use the symbol corresponding to the
# configuration in which it is built.  If the proper library is not
# used via the link interface the import test will fail to link.
add_library(testLib4lib STATIC testLib4lib.c)
Brad King's avatar
Brad King committed
64
65
add_library(testLib4libdbg STATIC testLib4libopt.c testLib4libdbg${VS6}.c)
add_library(testLib4libopt STATIC testLib4libdbg.c testLib4libopt${VS6}.c)
66
67
68
set_property(TARGET testLib4libdbg PROPERTY COMPILE_DEFINITIONS LIB_DBG)
set_property(TARGET testLib4libopt PROPERTY COMPILE_DEFINITIONS LIB_OPT)
target_link_libraries(testLib4
69
70
  LINK_INTERFACE_LIBRARIES
  testLib4lib debug testLib4libdbg optimized testLib4libopt
71
72
  )

73
74
75
add_executable(testExe3 testExe3.c)
set_property(TARGET testExe3 PROPERTY MACOSX_BUNDLE 1)

76
# Install and export from install tree.
77
78
install(
  TARGETS
79
  testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3
80
  testExe2lib testLib4lib testLib4libdbg testLib4libopt
81
  testLib6
82
83
  EXPORT exp
  RUNTIME DESTINATION bin
84
  LIBRARY DESTINATION lib NAMELINK_SKIP
85
  ARCHIVE DESTINATION lib
86
  FRAMEWORK DESTINATION Frameworks
87
  BUNDLE DESTINATION Applications
88
  )
89
90
91
92
93
94
95
96
install(
  TARGETS
  testExe2libImp testLib3Imp
  EXPORT exp
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib/impl
  ARCHIVE DESTINATION lib/impl
  )
97
98
99
100
101
102
103
install(
  TARGETS testLib5
  EXPORT exp
  # Leave out RUNTIME DESTINATION to test implib-only export.
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  )
104
105
install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)

106
107
108
109
110
# Install testLib5.dll outside the export.
if(WIN32)
  install(TARGETS testLib5 RUNTIME DESTINATION bin)
endif(WIN32)

111
# Export from build tree.
112
export(TARGETS testExe1 testLib1 testLib2 testLib3
113
  testExe2libImp testLib3Imp
114
115
116
  NAMESPACE bld_
  FILE ExportBuildTree.cmake
  )
117
export(TARGETS testExe2 testLib4 testLib5 testLib6 testExe3 testExe2lib
118
  testLib4lib testLib4libdbg testLib4libopt
119
120
121
  NAMESPACE bld_
  APPEND FILE ExportBuildTree.cmake
  )