2009-07-11 18:10:51 +04:00
|
|
|
cmake_minimum_required (VERSION 2.7.20090711)
|
|
|
|
project(Export C CXX)
|
2008-01-28 16:40:21 +03:00
|
|
|
|
2008-09-05 01:34:25 +04:00
|
|
|
# Pretend that RelWithDebInfo should link to debug libraries to test
|
|
|
|
# the DEBUG_CONFIGURATIONS property.
|
|
|
|
set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug RelWithDebInfo)
|
|
|
|
|
2008-01-28 21:37:59 +03:00
|
|
|
add_library(testExe1lib STATIC testExe1lib.c) # not exported
|
2008-01-28 16:40:21 +03:00
|
|
|
add_executable(testExe1 testExe1.c)
|
2008-01-28 21:37:59 +03:00
|
|
|
target_link_libraries(testExe1 testExe1lib)
|
2008-02-06 22:20:36 +03:00
|
|
|
set_property(TARGET testExe1 PROPERTY VERSION 4)
|
2008-01-28 16:40:21 +03:00
|
|
|
|
2008-01-31 01:26:09 +03:00
|
|
|
add_library(testExe2libImp SHARED testExe2libImp.c)
|
2008-02-01 17:57:47 +03:00
|
|
|
set_property(TARGET testExe2libImp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
|
2008-01-31 01:26:09 +03:00
|
|
|
add_library(testExe2lib SHARED testExe2lib.c)
|
|
|
|
target_link_libraries(testExe2lib testExe2libImp)
|
|
|
|
set_property(TARGET testExe2lib PROPERTY LINK_INTERFACE_LIBRARIES "")
|
2008-01-28 16:40:21 +03:00
|
|
|
add_executable(testExe2 testExe2.c)
|
|
|
|
set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
|
2008-01-31 01:26:09 +03:00
|
|
|
set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
|
2008-01-28 16:40:21 +03:00
|
|
|
|
|
|
|
add_library(testLib1 STATIC testLib1.c)
|
|
|
|
add_library(testLib2 STATIC testLib2.c)
|
|
|
|
target_link_libraries(testLib2 testLib1)
|
|
|
|
|
2011-12-14 20:28:42 +04:00
|
|
|
# Test library with empty link interface. Link it to an implementation
|
|
|
|
# dependency that itself links to dependencies publicly.
|
|
|
|
add_library(testLib3ImpDep SHARED testLib3ImpDep.c)
|
|
|
|
set_property(TARGET testLib3ImpDep PROPERTY LIBRARY_OUTPUT_DIRECTORY impl/dep)
|
2008-01-31 01:26:09 +03:00
|
|
|
add_library(testLib3Imp SHARED testLib3Imp.c)
|
2008-02-01 17:57:47 +03:00
|
|
|
set_property(TARGET testLib3Imp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
|
2011-12-14 20:28:42 +04:00
|
|
|
target_link_libraries(testLib3Imp testLib3ImpDep)
|
2008-01-28 16:40:21 +03:00
|
|
|
add_library(testLib3 SHARED testLib3.c)
|
2008-01-31 01:26:09 +03:00
|
|
|
target_link_libraries(testLib3 testLib3Imp)
|
|
|
|
set_property(TARGET testLib3 PROPERTY LINK_INTERFACE_LIBRARIES "")
|
2008-02-06 22:20:36 +03:00
|
|
|
set_property(TARGET testLib3 PROPERTY VERSION 1.2)
|
|
|
|
set_property(TARGET testLib3 PROPERTY SOVERSION 3)
|
2008-01-28 16:40:21 +03:00
|
|
|
|
2009-05-01 17:45:43 +04:00
|
|
|
# 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)
|
|
|
|
|
2008-01-28 21:06:17 +03:00
|
|
|
add_library(testLib4 SHARED testLib4.c)
|
|
|
|
set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)
|
|
|
|
|
2009-04-09 00:29:04 +04:00
|
|
|
add_library(testLib5 SHARED testLib5.c)
|
|
|
|
|
2009-07-13 17:20:36 +04:00
|
|
|
add_library(testLib6 STATIC testLib6.cxx testLib6c.c)
|
2009-07-11 18:10:51 +04:00
|
|
|
|
2008-08-13 01:27:48 +04:00
|
|
|
# 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")
|
|
|
|
|
2008-08-12 00:23:10 +04:00
|
|
|
# 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)
|
2008-08-13 01:27:48 +04:00
|
|
|
add_library(testLib4libdbg STATIC testLib4libopt.c testLib4libdbg${VS6}.c)
|
|
|
|
add_library(testLib4libopt STATIC testLib4libdbg.c testLib4libopt${VS6}.c)
|
2008-08-12 00:23:10 +04:00
|
|
|
set_property(TARGET testLib4libdbg PROPERTY COMPILE_DEFINITIONS LIB_DBG)
|
|
|
|
set_property(TARGET testLib4libopt PROPERTY COMPILE_DEFINITIONS LIB_OPT)
|
|
|
|
target_link_libraries(testLib4
|
2008-08-18 18:11:29 +04:00
|
|
|
LINK_INTERFACE_LIBRARIES
|
|
|
|
testLib4lib debug testLib4libdbg optimized testLib4libopt
|
2008-08-12 00:23:10 +04:00
|
|
|
)
|
|
|
|
|
2008-01-28 22:46:16 +03:00
|
|
|
add_executable(testExe3 testExe3.c)
|
|
|
|
set_property(TARGET testExe3 PROPERTY MACOSX_BUNDLE 1)
|
|
|
|
|
2009-09-01 18:38:36 +04:00
|
|
|
# Test cyclic dependencies.
|
|
|
|
add_library(testLibCycleA STATIC
|
|
|
|
testLibCycleA1.c testLibCycleA2.c testLibCycleA3.c)
|
|
|
|
add_library(testLibCycleB STATIC
|
|
|
|
testLibCycleB1.c testLibCycleB2.c testLibCycleB3.c)
|
|
|
|
target_link_libraries(testLibCycleA testLibCycleB)
|
|
|
|
target_link_libraries(testLibCycleB testLibCycleA)
|
|
|
|
set_property(TARGET testLibCycleA PROPERTY LINK_INTERFACE_MULTIPLICITY 3)
|
|
|
|
|
2008-01-28 16:40:21 +03:00
|
|
|
# Install and export from install tree.
|
2008-02-01 17:57:47 +03:00
|
|
|
install(
|
|
|
|
TARGETS
|
2008-01-31 23:45:31 +03:00
|
|
|
testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3
|
2008-08-12 00:23:10 +04:00
|
|
|
testExe2lib testLib4lib testLib4libdbg testLib4libopt
|
2009-07-11 18:10:51 +04:00
|
|
|
testLib6
|
2009-09-01 18:38:36 +04:00
|
|
|
testLibCycleA testLibCycleB
|
2008-01-28 16:40:21 +03:00
|
|
|
EXPORT exp
|
|
|
|
RUNTIME DESTINATION bin
|
2008-02-06 22:20:36 +03:00
|
|
|
LIBRARY DESTINATION lib NAMELINK_SKIP
|
2008-01-28 16:40:21 +03:00
|
|
|
ARCHIVE DESTINATION lib
|
2008-01-28 21:06:17 +03:00
|
|
|
FRAMEWORK DESTINATION Frameworks
|
2008-01-28 22:46:16 +03:00
|
|
|
BUNDLE DESTINATION Applications
|
2008-01-28 16:40:21 +03:00
|
|
|
)
|
2008-02-01 21:08:12 +03:00
|
|
|
install(
|
|
|
|
TARGETS
|
|
|
|
testExe2libImp testLib3Imp
|
|
|
|
EXPORT exp
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib/impl
|
|
|
|
ARCHIVE DESTINATION lib/impl
|
|
|
|
)
|
2011-12-14 20:28:42 +04:00
|
|
|
install(
|
|
|
|
TARGETS
|
|
|
|
testLib3ImpDep
|
|
|
|
EXPORT exp
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib/impl/dep
|
|
|
|
ARCHIVE DESTINATION lib/impl/dep
|
|
|
|
)
|
2009-04-09 00:29:04 +04:00
|
|
|
install(
|
|
|
|
TARGETS testLib5
|
|
|
|
EXPORT exp
|
|
|
|
# Leave out RUNTIME DESTINATION to test implib-only export.
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
)
|
2008-01-28 16:40:21 +03:00
|
|
|
install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
|
|
|
|
|
2009-04-09 00:29:04 +04:00
|
|
|
# Install testLib5.dll outside the export.
|
|
|
|
if(WIN32)
|
|
|
|
install(TARGETS testLib5 RUNTIME DESTINATION bin)
|
|
|
|
endif(WIN32)
|
|
|
|
|
2008-01-28 16:40:21 +03:00
|
|
|
# Export from build tree.
|
2008-01-31 01:26:09 +03:00
|
|
|
export(TARGETS testExe1 testLib1 testLib2 testLib3
|
2011-12-14 20:28:42 +04:00
|
|
|
testExe2libImp testLib3Imp testLib3ImpDep
|
2008-01-28 16:40:21 +03:00
|
|
|
NAMESPACE bld_
|
|
|
|
FILE ExportBuildTree.cmake
|
|
|
|
)
|
2009-07-11 18:10:51 +04:00
|
|
|
export(TARGETS testExe2 testLib4 testLib5 testLib6 testExe3 testExe2lib
|
2008-08-12 00:23:10 +04:00
|
|
|
testLib4lib testLib4libdbg testLib4libopt
|
2009-09-01 18:38:36 +04:00
|
|
|
testLibCycleA testLibCycleB
|
2008-01-28 21:21:42 +03:00
|
|
|
NAMESPACE bld_
|
|
|
|
APPEND FILE ExportBuildTree.cmake
|
|
|
|
)
|