diff --git a/CMakeLists.txt b/CMakeLists.txt index d5dffc2..d93853e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/include/ COMPONENT headers FILES_MATCHING PATTERN "*.h*") + export(EXPORT cytnx_targets FILE ${CMAKE_CURRENT_BINARY_DIR}/CytnxTargets.cmake NAMESPACE cytnx_core::) export(PACKAGE cytnx_core) @@ -80,8 +81,13 @@ export(PACKAGE cytnx_core) set(PYBIND11_FINDPYTHON ON) find_package(pybind11 CONFIG REQUIRED) -pybind11_add_module(pycytnx MODULE src/cpp/pybind/main.cpp) -target_link_libraries(pycytnx PUBLIC cytnx_core) +pybind11_add_module(_core MODULE src/cpp/pybind/main.cpp) +target_link_libraries(_core PUBLIC cytnx_core) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/cytnx_core + DESTINATION ${CMAKE_INSTALL_PREFIX} +) +install(TARGETS _core LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/cytnx_core) #install(TARGETS pycytnx DESTINATION ${SKBUILD_PROJECT_NAME}) -install(TARGETS pycytnx DESTINATION ${CMAKE_INSTALL_PREFIX}/cytnx_core) message(STATUS " skbuild Installation Prefix: ${SKBUILD_PROJECT_NAME}") +message(STATUS " skbuild Installation Prefix: ${SKBUILD_HEADERS_DIR}") diff --git a/README.md b/README.md index 84b6a64..2286d8d 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,12 @@ Running pytest: - cmake 3.15+ (see CMakeList.txt, default 3.20) * most of the deps should be able to install via pypi. + + +## Compile directly the C++ package + +```bash + $mkdir build + $cd build + $cmake ../ -DCMAKE_INSTALL_PREFIX= +``` diff --git a/pyproject.toml b/pyproject.toml index 956df6e..d0c3dd3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ dependencies = [] [tool.scikit-build] minimum-version = "build-system.requires" build-dir = "build/{wheel_tag}" +build.tool-args = ["-j4"] [tool.black] line-length = 88 diff --git a/src/cpp/include/test.hpp b/src/cpp/include/cytnx_core/test.hpp similarity index 52% rename from src/cpp/include/test.hpp rename to src/cpp/include/cytnx_core/test.hpp index e8345bc..de09796 100644 --- a/src/cpp/include/test.hpp +++ b/src/cpp/include/cytnx_core/test.hpp @@ -1,9 +1,9 @@ #pragma once -#include +#include namespace cytnx_core { -void test(); +std::string test(); } diff --git a/src/cpp/pybind/main.cpp b/src/cpp/pybind/main.cpp index 9a57ecd..de76e29 100644 --- a/src/cpp/pybind/main.cpp +++ b/src/cpp/pybind/main.cpp @@ -1,10 +1,12 @@ +#include #include +#include -std::string hello_from_bin() { return "Hello from Kai!"; } +std::string hello_from_bin() { return cytnx_core::test(); } namespace py = pybind11; -PYBIND11_MODULE(pycytnx, m) { +PYBIND11_MODULE(_core, m) { m.doc() = "pybind11 hello module"; m.def("hello_from_bin", &hello_from_bin, R"pbdoc( diff --git a/src/cpp/src/CMakeLists.txt b/src/cpp/src/CMakeLists.txt index 7c96618..762a393 100644 --- a/src/cpp/src/CMakeLists.txt +++ b/src/cpp/src/CMakeLists.txt @@ -1,6 +1,5 @@ target_sources_local(cytnx_core PRIVATE - # put cpp files here test.cpp diff --git a/src/cpp/src/test.cpp b/src/cpp/src/test.cpp index c3e8fcb..5167bb1 100644 --- a/src/cpp/src/test.cpp +++ b/src/cpp/src/test.cpp @@ -1,4 +1,7 @@ -#include "test.hpp" +#include #include +#include -void test() { std::cout << "Hello from test" << std::endl; } +namespace cytnx_core { +std::string test() { return "Hello from test"; } +} // namespace cytnx_core diff --git a/src/cytnx_core/__init__.py b/src/cytnx_core/__init__.py index b919c0f..e581d39 100644 --- a/src/cytnx_core/__init__.py +++ b/src/cytnx_core/__init__.py @@ -1,4 +1,4 @@ -from cytnx_core.pycytnx import hello_from_bin +from cytnx_core._core import hello_from_bin def hello() -> str: