CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. cmake_minimum_required (VERSION 2.7.20090711)
  2. project(Export C CXX)
  3. # Pretend that RelWithDebInfo should link to debug libraries to test
  4. # the DEBUG_CONFIGURATIONS property.
  5. set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug RelWithDebInfo)
  6. add_library(testExe1lib STATIC testExe1lib.c) # not exported
  7. add_executable(testExe1 testExe1.c)
  8. target_link_libraries(testExe1 testExe1lib)
  9. set_property(TARGET testExe1 PROPERTY VERSION 4)
  10. add_library(testExe2libImp SHARED testExe2libImp.c)
  11. set_property(TARGET testExe2libImp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
  12. add_library(testExe2lib SHARED testExe2lib.c)
  13. target_link_libraries(testExe2lib testExe2libImp)
  14. set_property(TARGET testExe2lib PROPERTY LINK_INTERFACE_LIBRARIES "")
  15. add_executable(testExe2 testExe2.c)
  16. set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
  17. set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
  18. add_library(testLib1 STATIC testLib1.c)
  19. add_library(testLib2 STATIC testLib2.c)
  20. target_link_libraries(testLib2 testLib1)
  21. add_library(testLib3Imp SHARED testLib3Imp.c)
  22. set_property(TARGET testLib3Imp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
  23. add_library(testLib3 SHARED testLib3.c)
  24. target_link_libraries(testLib3 testLib3Imp)
  25. set_property(TARGET testLib3 PROPERTY LINK_INTERFACE_LIBRARIES "")
  26. set_property(TARGET testLib3 PROPERTY VERSION 1.2)
  27. set_property(TARGET testLib3 PROPERTY SOVERSION 3)
  28. # Test <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME[_<CONFIG>] properties.
  29. set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_DEBUG testLib3dll-d)
  30. set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_RELEASE testLib3dll-r)
  31. set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME testLib3dll)
  32. set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_DEBUG testLib3lib-d)
  33. set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_RELEASE testLib3lib-r)
  34. set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME testLib3lib)
  35. set_property(TARGET testLib3 PROPERTY ARCHIVE_OUTPUT_NAME testLib3import)
  36. add_library(testLib4 SHARED testLib4.c)
  37. set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)
  38. add_library(testLib5 SHARED testLib5.c)
  39. add_library(testLib6 STATIC testLib6.cxx testLib6c.c)
  40. # Work-around: Visual Studio 6 does not support per-target object files.
  41. set(VS6)
  42. if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  43. set(VS6 1)
  44. endif("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  45. # Test using the target_link_libraries command to set the
  46. # LINK_INTERFACE_LIBRARIES* properties. We construct two libraries
  47. # providing the same two symbols. In each library one of the symbols
  48. # will work and the other one will fail to link. The import part of
  49. # this test will try to use the symbol corresponding to the
  50. # configuration in which it is built. If the proper library is not
  51. # used via the link interface the import test will fail to link.
  52. add_library(testLib4lib STATIC testLib4lib.c)
  53. add_library(testLib4libdbg STATIC testLib4libopt.c testLib4libdbg${VS6}.c)
  54. add_library(testLib4libopt STATIC testLib4libdbg.c testLib4libopt${VS6}.c)
  55. set_property(TARGET testLib4libdbg PROPERTY COMPILE_DEFINITIONS LIB_DBG)
  56. set_property(TARGET testLib4libopt PROPERTY COMPILE_DEFINITIONS LIB_OPT)
  57. target_link_libraries(testLib4
  58. LINK_INTERFACE_LIBRARIES
  59. testLib4lib debug testLib4libdbg optimized testLib4libopt
  60. )
  61. add_executable(testExe3 testExe3.c)
  62. set_property(TARGET testExe3 PROPERTY MACOSX_BUNDLE 1)
  63. # Test cyclic dependencies.
  64. add_library(testLibCycleA STATIC
  65. testLibCycleA1.c testLibCycleA2.c testLibCycleA3.c)
  66. add_library(testLibCycleB STATIC
  67. testLibCycleB1.c testLibCycleB2.c testLibCycleB3.c)
  68. target_link_libraries(testLibCycleA testLibCycleB)
  69. target_link_libraries(testLibCycleB testLibCycleA)
  70. set_property(TARGET testLibCycleA PROPERTY LINK_INTERFACE_MULTIPLICITY 3)
  71. # Install and export from install tree.
  72. install(
  73. TARGETS
  74. testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3
  75. testExe2lib testLib4lib testLib4libdbg testLib4libopt
  76. testLib6
  77. testLibCycleA testLibCycleB
  78. EXPORT exp
  79. RUNTIME DESTINATION bin
  80. LIBRARY DESTINATION lib NAMELINK_SKIP
  81. ARCHIVE DESTINATION lib
  82. FRAMEWORK DESTINATION Frameworks
  83. BUNDLE DESTINATION Applications
  84. )
  85. install(
  86. TARGETS
  87. testExe2libImp testLib3Imp
  88. EXPORT exp
  89. RUNTIME DESTINATION bin
  90. LIBRARY DESTINATION lib/impl
  91. ARCHIVE DESTINATION lib/impl
  92. )
  93. install(
  94. TARGETS testLib5
  95. EXPORT exp
  96. # Leave out RUNTIME DESTINATION to test implib-only export.
  97. LIBRARY DESTINATION lib
  98. ARCHIVE DESTINATION lib
  99. )
  100. install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
  101. # Install testLib5.dll outside the export.
  102. if(WIN32)
  103. install(TARGETS testLib5 RUNTIME DESTINATION bin)
  104. endif(WIN32)
  105. # Export from build tree.
  106. export(TARGETS testExe1 testLib1 testLib2 testLib3
  107. testExe2libImp testLib3Imp
  108. NAMESPACE bld_
  109. FILE ExportBuildTree.cmake
  110. )
  111. export(TARGETS testExe2 testLib4 testLib5 testLib6 testExe3 testExe2lib
  112. testLib4lib testLib4libdbg testLib4libopt
  113. testLibCycleA testLibCycleB
  114. NAMESPACE bld_
  115. APPEND FILE ExportBuildTree.cmake
  116. )