CMakeLists.txt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. cmake_minimum_required (VERSION 2.6)
  2. cmake_policy(SET CMP0054 NEW)
  3. project(Plugin)
  4. # We need proper C++98 support from the compiler
  5. set(CMAKE_CXX_STANDARD 98)
  6. # Test per-target output directory properties.
  7. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/bin)
  8. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/plugin)
  9. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/static)
  10. # We need the dynamic loader support from KWSys to load the plugin in
  11. # the executable.
  12. set(KWSYS_NAMESPACE kwsys)
  13. set(KWSYS_HEADER_ROOT ${Plugin_BINARY_DIR}/include)
  14. set(KWSYS_USE_DynamicLoader 1)
  15. add_subdirectory(${Plugin_SOURCE_DIR}/../../Source/kwsys src/kwsys)
  16. # Configure the location of plugins.
  17. configure_file(${Plugin_SOURCE_DIR}/src/example_exe.h.in
  18. ${Plugin_BINARY_DIR}/include/example_exe.h @ONLY)
  19. # We need to include headers from the source tree and configured
  20. # headers in the build tree.
  21. include_directories(
  22. ${Plugin_BINARY_DIR}/include
  23. ${Plugin_SOURCE_DIR}/include
  24. )
  25. # Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
  26. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
  27. CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
  28. set(CMAKE_CXX_STANDARD 11)
  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. # Verify that targets export with proper IMPORTED SONAME properties.
  46. export(TARGETS example_mod_1 NAMESPACE exp_
  47. FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
  48. include(ExternalProject)
  49. ExternalProject_Add(PluginTest
  50. SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PluginTest"
  51. BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/PluginTest"
  52. DOWNLOAD_COMMAND ""
  53. INSTALL_COMMAND ""
  54. )
  55. add_dependencies(PluginTest example_mod_1)
  56. endif()
  57. # TODO:
  58. # - create a plugin that links to a static lib
  59. # - create a plugin that links to a shared lib