CMakeLists.txt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. # Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
  7. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
  8. CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
  9. set(CMAKE_CXX_STANDARD 11)
  10. endif()
  11. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
  12. CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
  13. set(CMAKE_CXX_STANDARD 14)
  14. endif()
  15. # Test per-target output directory properties.
  16. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/bin)
  17. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/plugin)
  18. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/static)
  19. # We need the dynamic loader support from KWSys to load the plugin in
  20. # the executable.
  21. set(KWSYS_NAMESPACE kwsys)
  22. set(KWSYS_HEADER_ROOT ${Plugin_BINARY_DIR}/include)
  23. set(KWSYS_USE_DynamicLoader 1)
  24. set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
  25. add_subdirectory(${Plugin_SOURCE_DIR}/../../Source/kwsys src/kwsys)
  26. # Configure the location of plugins.
  27. configure_file(${Plugin_SOURCE_DIR}/src/example_exe.h.in
  28. ${Plugin_BINARY_DIR}/include/example_exe.h @ONLY)
  29. # We need to include headers from the source tree and configured
  30. # headers in the build tree.
  31. include_directories(
  32. ${Plugin_BINARY_DIR}/include
  33. ${Plugin_SOURCE_DIR}/include
  34. )
  35. # Create an executable that exports an API for use by plugins.
  36. add_executable(example_exe src/example_exe.cxx)
  37. set_target_properties(example_exe PROPERTIES
  38. ENABLE_EXPORTS 1
  39. OUTPUT_NAME example
  40. # Test placing exe import library in unique directory.
  41. ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe
  42. )
  43. target_link_libraries(example_exe kwsys)
  44. # Create a plugin that uses the API provided by the executable.
  45. # This module "links" to the executable to use the symbols.
  46. add_library(example_mod_1 MODULE src/example_mod_1.c)
  47. target_link_libraries(example_mod_1 example_exe)
  48. if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
  49. "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
  50. # Verify that targets export with proper IMPORTED SONAME properties.
  51. export(TARGETS example_mod_1 NAMESPACE exp_
  52. FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
  53. include(ExternalProject)
  54. ExternalProject_Add(PluginTest
  55. SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PluginTest"
  56. BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/PluginTest"
  57. DOWNLOAD_COMMAND ""
  58. INSTALL_COMMAND ""
  59. )
  60. add_dependencies(PluginTest example_mod_1)
  61. endif()
  62. # TODO:
  63. # - create a plugin that links to a static lib
  64. # - create a plugin that links to a shared lib