CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. cmake_minimum_required (VERSION 2.6)
  2. project(Export C)
  3. # We need ansi C support.
  4. if(CMAKE_ANSI_CFLAGS)
  5. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
  6. endif(CMAKE_ANSI_CFLAGS)
  7. # Pretend that RelWithDebInfo should link to debug libraries to test
  8. # the DEBUG_CONFIGURATIONS property.
  9. set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug RelWithDebInfo)
  10. add_library(testExe1lib STATIC testExe1lib.c) # not exported
  11. add_executable(testExe1 testExe1.c)
  12. target_link_libraries(testExe1 testExe1lib)
  13. set_property(TARGET testExe1 PROPERTY VERSION 4)
  14. add_library(testExe2libImp SHARED testExe2libImp.c)
  15. set_property(TARGET testExe2libImp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
  16. add_library(testExe2lib SHARED testExe2lib.c)
  17. target_link_libraries(testExe2lib testExe2libImp)
  18. set_property(TARGET testExe2lib PROPERTY LINK_INTERFACE_LIBRARIES "")
  19. add_executable(testExe2 testExe2.c)
  20. set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
  21. set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
  22. add_library(testLib1 STATIC testLib1.c)
  23. add_library(testLib2 STATIC testLib2.c)
  24. target_link_libraries(testLib2 testLib1)
  25. add_library(testLib3Imp SHARED testLib3Imp.c)
  26. set_property(TARGET testLib3Imp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
  27. add_library(testLib3 SHARED testLib3.c)
  28. target_link_libraries(testLib3 testLib3Imp)
  29. set_property(TARGET testLib3 PROPERTY LINK_INTERFACE_LIBRARIES "")
  30. set_property(TARGET testLib3 PROPERTY VERSION 1.2)
  31. set_property(TARGET testLib3 PROPERTY SOVERSION 3)
  32. add_library(testLib4 SHARED testLib4.c)
  33. set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)
  34. # Work-around: Visual Studio 6 does not support per-target object files.
  35. set(VS6)
  36. if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  37. set(VS6 1)
  38. endif("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  39. # Test using the target_link_libraries command to set the
  40. # LINK_INTERFACE_LIBRARIES* properties. We construct two libraries
  41. # providing the same two symbols. In each library one of the symbols
  42. # will work and the other one will fail to link. The import part of
  43. # this test will try to use the symbol corresponding to the
  44. # configuration in which it is built. If the proper library is not
  45. # used via the link interface the import test will fail to link.
  46. add_library(testLib4lib STATIC testLib4lib.c)
  47. add_library(testLib4libdbg STATIC testLib4libopt.c testLib4libdbg${VS6}.c)
  48. add_library(testLib4libopt STATIC testLib4libdbg.c testLib4libopt${VS6}.c)
  49. set_property(TARGET testLib4libdbg PROPERTY COMPILE_DEFINITIONS LIB_DBG)
  50. set_property(TARGET testLib4libopt PROPERTY COMPILE_DEFINITIONS LIB_OPT)
  51. target_link_libraries(testLib4
  52. LINK_INTERFACE_LIBRARIES
  53. testLib4lib debug testLib4libdbg optimized testLib4libopt
  54. )
  55. add_executable(testExe3 testExe3.c)
  56. set_property(TARGET testExe3 PROPERTY MACOSX_BUNDLE 1)
  57. # Install and export from install tree.
  58. install(
  59. TARGETS
  60. testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3
  61. testExe2lib testLib4lib testLib4libdbg testLib4libopt
  62. EXPORT exp
  63. RUNTIME DESTINATION bin
  64. LIBRARY DESTINATION lib NAMELINK_SKIP
  65. ARCHIVE DESTINATION lib
  66. FRAMEWORK DESTINATION Frameworks
  67. BUNDLE DESTINATION Applications
  68. )
  69. install(
  70. TARGETS
  71. testExe2libImp testLib3Imp
  72. EXPORT exp
  73. RUNTIME DESTINATION bin
  74. LIBRARY DESTINATION lib/impl
  75. ARCHIVE DESTINATION lib/impl
  76. )
  77. install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
  78. # Export from build tree.
  79. export(TARGETS testExe1 testLib1 testLib2 testLib3
  80. testExe2libImp testLib3Imp
  81. NAMESPACE bld_
  82. FILE ExportBuildTree.cmake
  83. )
  84. export(TARGETS testExe2 testLib4 testExe3 testExe2lib
  85. testLib4lib testLib4libdbg testLib4libopt
  86. NAMESPACE bld_
  87. APPEND FILE ExportBuildTree.cmake
  88. )