CMakeLists.txt 3.94 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
cmake_minimum_required (VERSION 2.6)
2
3
4
5
6
7
8
project(Export C)

# We need ansi C support.
if(CMAKE_ANSI_CFLAGS)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
endif(CMAKE_ANSI_CFLAGS)

9
10
11
12
# Pretend that RelWithDebInfo should link to debug libraries to test
# the DEBUG_CONFIGURATIONS property.
set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug RelWithDebInfo)

13
add_library(testExe1lib STATIC testExe1lib.c) # not exported
14
add_executable(testExe1 testExe1.c)
15
target_link_libraries(testExe1 testExe1lib)
16
set_property(TARGET testExe1 PROPERTY VERSION 4)
17

18
add_library(testExe2libImp SHARED testExe2libImp.c)
19
set_property(TARGET testExe2libImp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
20
21
22
add_library(testExe2lib SHARED testExe2lib.c)
target_link_libraries(testExe2lib testExe2libImp)
set_property(TARGET testExe2lib PROPERTY LINK_INTERFACE_LIBRARIES "")
23
24
add_executable(testExe2 testExe2.c)
set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
25
set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
26
27
28
29
30

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

31
add_library(testLib3Imp SHARED testLib3Imp.c)
32
set_property(TARGET testLib3Imp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
33
add_library(testLib3 SHARED testLib3.c)
34
35
target_link_libraries(testLib3 testLib3Imp)
set_property(TARGET testLib3 PROPERTY LINK_INTERFACE_LIBRARIES "")
36
37
set_property(TARGET testLib3 PROPERTY VERSION 1.2)
set_property(TARGET testLib3 PROPERTY SOVERSION 3)
38

39
40
41
add_library(testLib4 SHARED testLib4.c)
set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)

42
43
add_library(testLib5 SHARED testLib5.c)

Brad King's avatar
Brad King committed
44
45
46
47
48
49
# 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")

50
51
52
53
54
55
56
57
# 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
58
59
add_library(testLib4libdbg STATIC testLib4libopt.c testLib4libdbg${VS6}.c)
add_library(testLib4libopt STATIC testLib4libdbg.c testLib4libopt${VS6}.c)
60
61
62
set_property(TARGET testLib4libdbg PROPERTY COMPILE_DEFINITIONS LIB_DBG)
set_property(TARGET testLib4libopt PROPERTY COMPILE_DEFINITIONS LIB_OPT)
target_link_libraries(testLib4
63
64
  LINK_INTERFACE_LIBRARIES
  testLib4lib debug testLib4libdbg optimized testLib4libopt
65
66
  )

67
68
69
add_executable(testExe3 testExe3.c)
set_property(TARGET testExe3 PROPERTY MACOSX_BUNDLE 1)

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

99
100
101
102
103
# Install testLib5.dll outside the export.
if(WIN32)
  install(TARGETS testLib5 RUNTIME DESTINATION bin)
endif(WIN32)

104
# Export from build tree.
105
export(TARGETS testExe1 testLib1 testLib2 testLib3
106
  testExe2libImp testLib3Imp
107
108
109
  NAMESPACE bld_
  FILE ExportBuildTree.cmake
  )
110
export(TARGETS testExe2 testLib4 testLib5 testExe3 testExe2lib
111
  testLib4lib testLib4libdbg testLib4libopt
112
113
114
  NAMESPACE bld_
  APPEND FILE ExportBuildTree.cmake
  )