CMakeLists.txt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. cmake_minimum_required (VERSION 2.6)
  2. project(Plugin)
  3. # Test per-target output directory properties.
  4. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/bin)
  5. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/plugin)
  6. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/static)
  7. # We need the dynamic loader support from KWSys to load the plugin in
  8. # the executable.
  9. set(KWSYS_NAMESPACE kwsys)
  10. set(KWSYS_HEADER_ROOT ${Plugin_BINARY_DIR}/include)
  11. set(KWSYS_USE_DynamicLoader 1)
  12. add_subdirectory(${Plugin_SOURCE_DIR}/../../Source/kwsys src/kwsys)
  13. # Configure the location of plugins.
  14. configure_file(${Plugin_SOURCE_DIR}/src/example_exe.h.in
  15. ${Plugin_BINARY_DIR}/include/example_exe.h @ONLY)
  16. # We need to include headers from the source tree and configured
  17. # headers in the build tree.
  18. include_directories(
  19. ${Plugin_BINARY_DIR}/include
  20. ${Plugin_SOURCE_DIR}/include
  21. )
  22. # Create an executable that exports an API for use by plugins.
  23. add_executable(example_exe src/example_exe.cxx)
  24. set_target_properties(example_exe PROPERTIES
  25. ENABLE_EXPORTS 1
  26. OUTPUT_NAME example
  27. # Test placing exe import library in unique directory.
  28. ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe
  29. )
  30. target_link_libraries(example_exe kwsys)
  31. # Create a plugin that uses the API provided by the executable.
  32. # This module "links" to the executable to use the symbols.
  33. add_library(example_mod_1 MODULE src/example_mod_1.c)
  34. target_link_libraries(example_mod_1 example_exe)
  35. if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
  36. "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
  37. # Add a second plugin that should not have any soname.
  38. add_library(example_mod_2 MODULE src/example_mod_1.c)
  39. target_link_libraries(example_mod_2 example_exe)
  40. set_property(TARGET example_mod_2 PROPERTY NO_SONAME 1)
  41. # Verify that targets export with proper IMPORTED SONAME properties.
  42. export(TARGETS example_mod_1 example_mod_2 NAMESPACE exp_
  43. FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
  44. include(ExternalProject)
  45. ExternalProject_Add(PluginTest
  46. SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PluginTest"
  47. BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/PluginTest"
  48. DOWNLOAD_COMMAND ""
  49. INSTALL_COMMAND ""
  50. )
  51. add_dependencies(PluginTest example_mod_1 example_mod_2)
  52. endif()
  53. # TODO:
  54. # - create a plugin that links to a static lib
  55. # - create a plugin that links to a shared lib