CMakeLists.txt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. # We need proper C++98 support from the compiler
  23. set(CMAKE_CXX_STANDARD 98)
  24. # Those versions of the HP compiler that need a flag to get proper C++98
  25. # template support also need a flag to use the newer C++ library.
  26. if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
  27. CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
  28. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
  29. endif ()
  30. # Create an executable that exports an API for use by plugins.
  31. add_executable(example_exe src/example_exe.cxx)
  32. set_target_properties(example_exe PROPERTIES
  33. ENABLE_EXPORTS 1
  34. OUTPUT_NAME example
  35. # Test placing exe import library in unique directory.
  36. ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe
  37. )
  38. target_link_libraries(example_exe kwsys)
  39. # Create a plugin that uses the API provided by the executable.
  40. # This module "links" to the executable to use the symbols.
  41. add_library(example_mod_1 MODULE src/example_mod_1.c)
  42. target_link_libraries(example_mod_1 example_exe)
  43. if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
  44. "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
  45. # Add a second plugin that should not have any soname.
  46. add_library(example_mod_2 MODULE src/example_mod_1.c)
  47. target_link_libraries(example_mod_2 example_exe)
  48. set_property(TARGET example_mod_2 PROPERTY NO_SONAME 1)
  49. # Verify that targets export with proper IMPORTED SONAME properties.
  50. export(TARGETS example_mod_1 example_mod_2 NAMESPACE exp_
  51. FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
  52. include(ExternalProject)
  53. ExternalProject_Add(PluginTest
  54. SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PluginTest"
  55. BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/PluginTest"
  56. DOWNLOAD_COMMAND ""
  57. INSTALL_COMMAND ""
  58. )
  59. add_dependencies(PluginTest example_mod_1 example_mod_2)
  60. endif()
  61. # TODO:
  62. # - create a plugin that links to a static lib
  63. # - create a plugin that links to a shared lib