Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
CMake
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3,189
Issues
3,189
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
External Wiki
External Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CMake
CMake
Commits
aabcf981
Commit
aabcf981
authored
Apr 17, 2007
by
Brad King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Added test for executables with plugins that use an API exported by the executable itself.
parent
c50dabff
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
0 deletions
+128
-0
Tests/Plugin/CMakeLists.txt
Tests/Plugin/CMakeLists.txt
+34
-0
Tests/Plugin/include/example.h
Tests/Plugin/include/example.h
+25
-0
Tests/Plugin/src/example_exe.cxx
Tests/Plugin/src/example_exe.cxx
+53
-0
Tests/Plugin/src/example_mod_1.c
Tests/Plugin/src/example_mod_1.c
+16
-0
No files found.
Tests/Plugin/CMakeLists.txt
0 → 100644
View file @
aabcf981
PROJECT
(
Plugin
)
# Test per-target output directory properties.
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
)
# We need the dynamic loader support from KWSys to load the plugin in
# the executable.
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
)
INCLUDE_DIRECTORIES
(
${
Plugin_BINARY_DIR
}
/include
${
Plugin_SOURCE_DIR
}
/include
)
# Create an executable that exports an API for use by plugins.
ADD_EXECUTABLE
(
example_exe src/example_exe.cxx
)
SET_TARGET_PROPERTIES
(
example_exe PROPERTIES
ENABLE_EXPORTS 1
OUTPUT_NAME example
)
TARGET_LINK_LIBRARIES
(
example_exe kwsys
)
# Create a plugin that uses the API provided by the executable.
# This module "links" to the executable to use the symbols.
ADD_LIBRARY
(
example_mod_1 MODULE src/example_mod_1.c
)
TARGET_LINK_LIBRARIES
(
example_mod_1 example_exe
)
# TODO:
# - create a plugin that links to a static lib
# - create a plugin that links to a shared lib
Tests/Plugin/include/example.h
0 → 100644
View file @
aabcf981
#ifndef example_h
#define example_h
#if defined(_WIN32)
# if defined(example_exe_EXPORTS)
# define EXAMPLE_EXPORT __declspec(dllexport)
# else
# define EXAMPLE_EXPORT __declspec(dllimport)
# endif
#else
# define EXAMPLE_EXPORT
#endif
#ifdef __cplusplus
extern
"C"
{
#endif
EXAMPLE_EXPORT
int
example_exe_function
(
void
);
#ifdef __cplusplus
}
#endif
#endif
Tests/Plugin/src/example_exe.cxx
0 → 100644
View file @
aabcf981
#include <example.h>
#include <kwsys/DynamicLoader.hxx>
#include <kwsys/ios/iostream>
#include <kwsys/stl/string>
#include <stdio.h>
// Implement the ABI used by plugins.
extern
"C"
int
example_exe_function
()
{
kwsys_ios
::
cout
<<
"hello"
<<
kwsys_ios
::
endl
;
return
123
;
}
#ifdef CMAKE_INTDIR
# define CONFIG_DIR "/" CMAKE_INTDIR
#else
# define CONFIG_DIR ""
#endif
int
main
()
{
kwsys_stl
::
string
libName
=
"lib/plugin"
CONFIG_DIR
"/"
;
libName
+=
kwsys
::
DynamicLoader
::
LibPrefix
();
libName
+=
"example_mod_1"
;
libName
+=
kwsys
::
DynamicLoader
::
LibExtension
();
kwsys
::
DynamicLoader
::
LibraryHandle
handle
=
kwsys
::
DynamicLoader
::
OpenLibrary
(
libName
.
c_str
());
if
(
!
handle
)
{
kwsys_ios
::
cerr
<<
"Could not open plugin
\"
"
<<
libName
<<
"
\"
!"
<<
kwsys_ios
::
endl
;
return
1
;
}
kwsys
::
DynamicLoader
::
SymbolPointer
sym
=
kwsys
::
DynamicLoader
::
GetSymbolAddress
(
handle
,
"example_mod_1_function"
);
if
(
!
sym
)
{
kwsys_ios
::
cerr
<<
"Could not get plugin symbol
\"
example_mod_1_function
\"
!"
<<
kwsys_ios
::
endl
;
return
1
;
}
int
(
*
f
)()
=
reinterpret_cast
<
int
(
*
)()
>
(
sym
);
if
(
f
()
!=
(
123
+
456
))
{
kwsys_ios
::
cerr
<<
"Incorrect return value from plugin!"
<<
kwsys_ios
::
endl
;
return
1
;
}
return
0
;
}
Tests/Plugin/src/example_mod_1.c
0 → 100644
View file @
aabcf981
#include <example.h>
#include <stdio.h>
#if defined(_WIN32)
# define MODULE_EXPORT __declspec(dllexport)
#else
# define MODULE_EXPORT
#endif
MODULE_EXPORT
int
example_mod_1_function
()
{
int
result
=
example_exe_function
()
+
456
;
printf
(
"world
\n
"
);
return
result
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment