CMakeLists.txt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 ansi C support.
  8. IF(CMAKE_ANSI_CFLAGS)
  9. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
  10. ENDIF(CMAKE_ANSI_CFLAGS)
  11. # We need the dynamic loader support from KWSys to load the plugin in
  12. # the executable.
  13. SET(KWSYS_NAMESPACE kwsys)
  14. SET(KWSYS_HEADER_ROOT ${Plugin_BINARY_DIR}/include)
  15. SET(KWSYS_USE_DynamicLoader 1)
  16. ADD_SUBDIRECTORY(${Plugin_SOURCE_DIR}/../../Source/kwsys src/kwsys)
  17. # Configure the location of plugins.
  18. CONFIGURE_FILE(${Plugin_SOURCE_DIR}/src/example_exe.h.in
  19. ${Plugin_BINARY_DIR}/include/example_exe.h @ONLY)
  20. # We need to include headers from the source tree and configured
  21. # headers in the build tree.
  22. INCLUDE_DIRECTORIES(
  23. ${Plugin_BINARY_DIR}/include
  24. ${Plugin_SOURCE_DIR}/include
  25. )
  26. # Create an executable that exports an API for use by plugins.
  27. ADD_EXECUTABLE(example_exe src/example_exe.cxx)
  28. SET_TARGET_PROPERTIES(example_exe PROPERTIES
  29. ENABLE_EXPORTS 1
  30. OUTPUT_NAME example
  31. # Test placing exe import library in unique directory.
  32. ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe
  33. )
  34. TARGET_LINK_LIBRARIES(example_exe kwsys)
  35. # Create a plugin that uses the API provided by the executable.
  36. # This module "links" to the executable to use the symbols.
  37. ADD_LIBRARY(example_mod_1 MODULE src/example_mod_1.c)
  38. TARGET_LINK_LIBRARIES(example_mod_1 example_exe)
  39. # TODO:
  40. # - create a plugin that links to a static lib
  41. # - create a plugin that links to a shared lib