CMakeLists.txt 2.7 KB

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