Skip to content

Commit

Permalink
updated CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
soblin committed Mar 3, 2022
1 parent 929779b commit ee6aca6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(
)

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 REQUIRED)
find_package(pybind11 2.4.3 REQUIRED)

set(matplotlibcpp17_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")

Expand All @@ -25,9 +25,8 @@ function(add_demo name path)
target_include_directories(${name} PUBLIC
${Python3_INCLUDE_DIRS}
${matplotlibcpp17_INCLUDE_DIRS}
${xtensor_INCLUDE_DIRS}
)
target_link_libraries(${name} ${Python3_LIBRARIES} pybind11::embed)
target_link_libraries(${name} ${Python3_LIBRARIES} pybind11::embed xtensor)
endfunction()

if(${ADD_DEMO})
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ $ (make uninstall)

For using matplotlibcpp17 from CMakeLists.txt, see [hello_world](https://github.com/soblin/matplotlibcpp17/tree/master/hello_world) example.

```bash
find_package(matplotlibcpp17)
...
target_link_libraries(a.out matplotlibcpp17::matplotlibcpp17)
```

Or you could just add include path to `include` directory and compile your codes as descibed in [minimal example](#minimal-example).

## Syntax
Expand Down
6 changes: 3 additions & 3 deletions tests/test_shared_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ add_library(test_shared_lib SHARED
test_lib.cpp
)
target_compile_options(test_shared_lib PUBLIC "-fPIC")
target_include_directories(test_shared_lib PUBLIC ${pybind11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} ${matplotlibcpp17_INCLUDE_DIRS})
target_link_libraries(test_shared_lib ${PYTHON_LIBRARY} pybind11::embed)
target_include_directories(test_shared_lib PUBLIC ${Python3_INCLUDE_DIRS} ${matplotlibcpp17_INCLUDE_DIRS})
target_link_libraries(test_shared_lib ${Python3_LIBRARIES} pybind11::embed)
# link it
add_executable(test_lib_main test_lib_main.cpp)
target_link_libraries(test_lib_main ${PYTHON_LIBRARY} pybind11::embed test_shared_lib)
target_link_libraries(test_lib_main test_shared_lib)
6 changes: 3 additions & 3 deletions tests/test_static_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ add_library(test_static_lib STATIC
test_lib.cpp
)
target_compile_options(test_static_lib PUBLIC "-fPIC")
target_include_directories(test_static_lib PUBLIC ${pybind11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} ${matplotlibcpp17_INCLUDE_DIRS})
target_link_libraries(test_static_lib ${PYTHON_LIBRARY} pybind11::embed)
target_include_directories(test_static_lib PUBLIC ${Python3_INCLUDE_DIRS} ${matplotlibcpp17_INCLUDE_DIRS})
target_link_libraries(test_static_lib ${Python3_LIBRARIES} pybind11::embed)
# link it
add_executable(test_lib_static_main test_lib_main.cpp)
target_link_libraries(test_lib_static_main ${PYTHON_LIBRARY} pybind11::embed test_static_lib)
target_link_libraries(test_lib_static_main test_static_lib)

0 comments on commit ee6aca6

Please sign in to comment.