Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,37 @@ link_directories(/opt/homebrew/lib)

# extism-cpp library
project(extism-cpp VERSION 1.0.0 DESCRIPTION "C++ bindings for libextism")
add_library(extism-cpp SHARED src/manifest.cpp src/current_plugin.cpp src/plugin.cpp src/function.cpp src/extism.cpp)
set(extism-cpp-srcs src/manifest.cpp src/current_plugin.cpp src/plugin.cpp src/function.cpp src/extism.cpp)

# SHARED
add_library(extism-cpp SHARED ${extism-cpp-srcs})
set_target_properties(extism-cpp PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(extism-cpp PROPERTIES PUBLIC_HEADER src/extism.hpp)
target_include_directories(extism-cpp PUBLIC src)
target_link_libraries(extism-cpp PUBLIC extism jsoncpp)
set_target_properties(extism-cpp
PROPERTIES NO_SONAME 1
)
configure_file(extism-cpp.pc.in extism-cpp.pc @ONLY)

# STATIC
add_library(extism-cpp-static STATIC ${extism-cpp-srcs})
set_target_properties(extism-cpp-static PROPERTIES OUTPUT_NAME extism-cpp)
set_target_properties(extism-cpp-static PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(extism-cpp-static PROPERTIES PUBLIC_HEADER src/extism.hpp)
target_include_directories(extism-cpp-static PUBLIC src)
target_link_libraries(extism-cpp-static PUBLIC libextism.a jsoncpp)
configure_file(extism-cpp-static.pc.in extism-cpp-static.pc @ONLY)

include(GNUInstallDirs)
install(TARGETS extism-cpp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS extism-cpp-static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/extism-cpp.pc ${CMAKE_CURRENT_BINARY_DIR}/extism-cpp-static.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

# Example
add_executable(
Expand All @@ -29,6 +49,16 @@ target_link_libraries(
extism-cpp
)

# Static-ish example
add_executable(
example-static
example.cpp
)
target_link_libraries(
example-static
extism-cpp-static
)

# Tests
enable_testing()
add_executable(
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ C++ Host SDK for Extism
- Debian: `sudo apt install libjsoncpp-dev`
- macOS: `brew install jsoncpp`

If you wish to link libextism-cpp with its deps statically, to make a binary
with only system deps, instead of installing `jsoncpp` from your system
package manager, you must build and install it from source. This is needed to
get the static library `libjsoncpp.a`.

```shell
git clone https://github.com/open-source-parsers/jsoncpp
cd jsoncpp
cmake -B build && cmake --build build -j
make -C build install
```

## Building

```shell
Expand All @@ -38,3 +50,16 @@ After building, run the following from the build directory:
$ sudo make install
```

## Usage

After installing, `pkg-config` may be used to get needed linking flags.

### Dynamic
```shell
$ pkg-config --libs extism-cpp
```

### Static
```shell
$ pkg-config --static --libs extism-cpp-static
```
10 changes: 10 additions & 0 deletions extism-cpp-static.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Version: @PROJECT_VERSION@
Name: Extism cpp-sdk
Description: C++ Host SDK for Extism
Requires.private: extism-static
Libs: -L${libdir} -l:libextism-cpp.a -l:libjsoncpp.a
Cflags: -I${includedir}
10 changes: 10 additions & 0 deletions extism-cpp.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Version: @PROJECT_VERSION@
Name: Extism cpp-sdk
Description: C++ Host SDK for Extism
Requires.private: extism
Libs: -L${libdir} -lextism-cpp -ljsoncpp
Cflags: -I${includedir}