2008-03-25 18:27:18 +03:00
|
|
|
cmake_minimum_required (VERSION 2.6)
|
2012-08-13 21:47:32 +04:00
|
|
|
project(Plugin)
|
2007-04-17 21:43:03 +04:00
|
|
|
|
|
|
|
# Test per-target output directory properties.
|
2012-08-13 21:47:32 +04:00
|
|
|
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)
|
2007-04-17 21:43:03 +04:00
|
|
|
|
|
|
|
# We need the dynamic loader support from KWSys to load the plugin in
|
|
|
|
# the executable.
|
2012-08-13 21:47:32 +04:00
|
|
|
set(KWSYS_NAMESPACE kwsys)
|
|
|
|
set(KWSYS_HEADER_ROOT ${Plugin_BINARY_DIR}/include)
|
|
|
|
set(KWSYS_USE_DynamicLoader 1)
|
|
|
|
add_subdirectory(${Plugin_SOURCE_DIR}/../../Source/kwsys src/kwsys)
|
2007-04-17 21:52:50 +04:00
|
|
|
|
|
|
|
# Configure the location of plugins.
|
2012-08-13 21:47:32 +04:00
|
|
|
configure_file(${Plugin_SOURCE_DIR}/src/example_exe.h.in
|
2007-04-17 21:52:50 +04:00
|
|
|
${Plugin_BINARY_DIR}/include/example_exe.h @ONLY)
|
|
|
|
|
|
|
|
# We need to include headers from the source tree and configured
|
|
|
|
# headers in the build tree.
|
2012-08-13 21:47:32 +04:00
|
|
|
include_directories(
|
2007-04-17 21:43:03 +04:00
|
|
|
${Plugin_BINARY_DIR}/include
|
|
|
|
${Plugin_SOURCE_DIR}/include
|
|
|
|
)
|
|
|
|
|
2014-04-15 20:52:30 +04:00
|
|
|
# We need proper C++98 support from the compiler
|
|
|
|
set(CMAKE_CXX_STANDARD 98)
|
|
|
|
|
|
|
|
# Those versions of the HP compiler that need a flag to get proper C++98
|
|
|
|
# template support also need a flag to use the newer C++ library.
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND
|
|
|
|
CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA")
|
|
|
|
endif ()
|
|
|
|
|
2007-04-17 21:43:03 +04:00
|
|
|
# Create an executable that exports an API for use by plugins.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(example_exe src/example_exe.cxx)
|
|
|
|
set_target_properties(example_exe PROPERTIES
|
2007-04-17 21:43:03 +04:00
|
|
|
ENABLE_EXPORTS 1
|
|
|
|
OUTPUT_NAME example
|
2009-06-15 18:55:21 +04:00
|
|
|
# Test placing exe import library in unique directory.
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/exe
|
2007-04-17 21:43:03 +04:00
|
|
|
)
|
2012-08-13 21:47:32 +04:00
|
|
|
target_link_libraries(example_exe kwsys)
|
2007-04-17 21:43:03 +04:00
|
|
|
|
|
|
|
# Create a plugin that uses the API provided by the executable.
|
|
|
|
# This module "links" to the executable to use the symbols.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_library(example_mod_1 MODULE src/example_mod_1.c)
|
|
|
|
target_link_libraries(example_mod_1 example_exe)
|
2007-04-17 21:43:03 +04:00
|
|
|
|
2012-04-23 17:53:29 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
|
2012-04-23 17:53:29 +04:00
|
|
|
"${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
|
|
|
|
# Verify that targets export with proper IMPORTED SONAME properties.
|
2015-08-20 15:13:28 +03:00
|
|
|
export(TARGETS example_mod_1 NAMESPACE exp_
|
2012-04-23 17:53:29 +04:00
|
|
|
FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
|
|
|
|
|
2012-10-07 23:47:46 +04:00
|
|
|
include(ExternalProject)
|
|
|
|
ExternalProject_Add(PluginTest
|
|
|
|
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PluginTest"
|
|
|
|
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/PluginTest"
|
|
|
|
DOWNLOAD_COMMAND ""
|
|
|
|
INSTALL_COMMAND ""
|
|
|
|
)
|
2015-08-20 15:13:28 +03:00
|
|
|
add_dependencies(PluginTest example_mod_1)
|
2012-08-13 21:47:32 +04:00
|
|
|
endif()
|
2012-04-23 17:53:29 +04:00
|
|
|
|
2007-04-17 21:43:03 +04:00
|
|
|
# TODO:
|
|
|
|
# - create a plugin that links to a static lib
|
|
|
|
# - create a plugin that links to a shared lib
|