CMakeLists.txt 2.17 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
cmake_minimum_required (VERSION 2.6)
2
cmake_policy(SET CMP0054 NEW)
3
project(Plugin)
4

5 6 7
# We need proper C++98 support from the compiler
set(CMAKE_CXX_STANDARD 98)

8
# Test per-target output directory properties.
9 10 11
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/plugin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/static)
12

13
# Configure the location of plugins.
14
configure_file(${Plugin_SOURCE_DIR}/src/example_exe.h.in
15 16 17 18
               ${Plugin_BINARY_DIR}/include/example_exe.h @ONLY)

# We need to include headers from the source tree and configured
# headers in the build tree.
19
include_directories(
20 21 22 23
  ${Plugin_BINARY_DIR}/include
  ${Plugin_SOURCE_DIR}/include
  )

24 25 26 27 28 29
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
    CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
  set(CMAKE_CXX_STANDARD 11)
endif()

30
# Create an executable that exports an API for use by plugins.
31
add_executable(example_exe src/example_exe.cxx src/DynamicLoader.cxx)
32
set_target_properties(example_exe PROPERTIES
33 34
  ENABLE_EXPORTS 1
  OUTPUT_NAME example
35 36
  # Test placing exe import library in unique directory.
  ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe
37
  )
38
target_link_libraries(example_exe ${CMAKE_DL_LIBS})
39 40 41

# Create a plugin that uses the API provided by the executable.
# This module "links" to the executable to use the symbols.
42 43
add_library(example_mod_1 MODULE src/example_mod_1.c)
target_link_libraries(example_mod_1 example_exe)
44

45

46
if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
47 48
    "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
  # Verify that targets export with proper IMPORTED SONAME properties.
49
  export(TARGETS example_mod_1 NAMESPACE exp_
50 51
    FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)

52 53 54 55 56 57 58
  include(ExternalProject)
  ExternalProject_Add(PluginTest
    SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PluginTest"
    BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/PluginTest"
    DOWNLOAD_COMMAND ""
    INSTALL_COMMAND ""
  )
59
  add_dependencies(PluginTest example_mod_1)
60
endif()
61

62 63 64
# TODO:
#  - create a plugin that links to a static lib
#  - create a plugin that links to a shared lib