diff --git a/CMakeLists.txt b/CMakeLists.txt index f11fe3860364f9f7310894dbbad0b0d973d79411..708673a1e1168b65765b353b6f6cca78c456a0db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,9 @@ project("${SKBUILD_PROJECT_NAME}" LANGUAGES CXX VERSION "${SKBUILD_PROJECT_VERSION}") -# include(GNUInstallDirs) -set(PYBIND11_FINDPYTHON ON) -find_package(pybind11 CONFIG REQUIRED) +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +# include(GNUInstallDirs) add_subdirectory(cpp) -add_subdirectory(src/myproj/simulation/_csrc) \ No newline at end of file +add_subdirectory(python/myproj/simulation/_csrc) \ No newline at end of file diff --git a/README.md b/README.md index 66ad80d8b1800781b00169c68d825238f1001a8e..e21ef7324c7119b5af5390992275823bc1370c4d 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,33 @@ use scikit-build-core to setup a python-cmake project that can be installed with ## Conclusion -cannot make packages like import myproj.simulation. It replaces "." with "_" +- cannot make packages like import myproj.simulation. It replaces "." with "_" +- most of the case, check following +```cmake +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/my_main.py DESTINATION .) +``` +and set +``` +[tool.scikit-build] +wheel.install-dir = "kk/ss" +``` + + +## special variable + + +- `${SKBUILD_PLATLIB_DIR}`: The original platlib directory. Anything here goes + directly to site-packages when a wheel is installed. +- `${SKBUILD_DATA_DIR}`: The data directory. Anything here goes to the root of + the environment when a wheel is installed (use with care). +- `${SKBUILD_HEADERS_DIR}`: The header directory. Anything in here gets + installed to Python's header directory. +- `${SKBUILD_SCRIPTS_DIR}`: The scripts directory. Anything placed in here will + go to `bin` (Unix) or `Scripts` (Windows). +- `${SKBUILD_METADATA_DIR}`: The dist-info directory. Licenses go in the + `licenses` subdirectory. _Note that CMake is not run in the + `prepare_metadata_\*` hooks, so anything written to this directory will only + be present when writing wheels.\_ +- `${SKBUILD_NULL_DIR}`: Anything installed here will not be placed in the + wheel. + diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 8bddd5f4832970e58894e7a8a5292c649c902c32..add648983d57b42013dc00a6f9db0e9b7790d4bf 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -2,18 +2,17 @@ add_library(hello SHARED src/hello.cc) target_include_directories(hello PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) -install( - TARGETS hello - LIBRARY DESTINATION ${SKBUILD_SCRIPTS_DIR}) +install(TARGETS hello LIBRARY DESTINATION .) add_library(complex SHARED src/complex.cc) target_include_directories(complex PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) target_link_libraries(complex PRIVATE hello) -install( - TARGETS complex - LIBRARY DESTINATION ${SKBUILD_SCRIPTS_DIR}) +install(TARGETS complex LIBRARY DESTINATION .) +set_target_properties(complex PROPERTIES + INSTALL_RPATH "$ORIGIN" +) # install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" # DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/pyproject.toml b/pyproject.toml index be223ebd70f0739e5eaeabac704ce49a437e3b4e..13ee28fe57412fb16fea4518df0fc49479abd55c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["scikit-build-core", "pybind11"] build-backend = "scikit_build_core.build" [project] -name = "myproj.simulation" +name = "myproj_simulation" version = "0.2.1" description = "A great package." readme = "README.md" @@ -36,4 +36,11 @@ Homepage = "https://github.com/organization/package" Documentation = "https://package.readthedocs.io/" "Bug Tracker" = "https://github.com/organization/package/issues" Discussions = "https://github.com/organization/package/discussions" -Changelog = "https://package.readthedocs.io/en/latest/changelog.html" \ No newline at end of file +Changelog = "https://package.readthedocs.io/en/latest/changelog.html" + +[tool.scikit-build.wheel.packages] +"myproj/simulation" = "python/myproj/simulation" + +[tool.scikit-build] +wheel.install-dir = "myproj/simulation" +wheel.exclude = ["CMakeLists.txt","*.cc","*.h"] \ No newline at end of file diff --git a/src/myproj/simulation/__init__.py b/python/myproj/simulation/__init__.py similarity index 100% rename from src/myproj/simulation/__init__.py rename to python/myproj/simulation/__init__.py diff --git a/python/myproj/simulation/_csrc/CMakeLists.txt b/python/myproj/simulation/_csrc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d5baf7b55a5fb5d13f64ff256251fc6bd17c9681 --- /dev/null +++ b/python/myproj/simulation/_csrc/CMakeLists.txt @@ -0,0 +1,9 @@ +find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) +find_package(pybind11 CONFIG REQUIRED) + +pybind11_add_module(_hello MODULE _hello_python.cc) +target_link_libraries(_hello PRIVATE hello complex) +install(TARGETS _hello DESTINATION _csrc) +set_target_properties(_hello PROPERTIES + INSTALL_RPATH "$ORIGIN/.." +) \ No newline at end of file diff --git a/src/myproj/simulation/_csrc/hello_python.cc b/python/myproj/simulation/_csrc/_hello_python.cc similarity index 89% rename from src/myproj/simulation/_csrc/hello_python.cc rename to python/myproj/simulation/_csrc/_hello_python.cc index e14360a86566933755349d8ddb3861dd5c0f0069..feaeae70c066eb587db75657d8f0757971975a5a 100644 --- a/src/myproj/simulation/_csrc/hello_python.cc +++ b/python/myproj/simulation/_csrc/_hello_python.cc @@ -4,7 +4,7 @@ namespace py = pybind11; -PYBIND11_MODULE(hello_python, m) { +PYBIND11_MODULE(_hello, m) { m.doc() = "pybind11 example plugin"; // optional module docstring m.def("add", &add, "A function which adds two numbers"); diff --git a/src/myproj/simulation/core.py b/python/myproj/simulation/core.py similarity index 100% rename from src/myproj/simulation/core.py rename to python/myproj/simulation/core.py diff --git a/src/myproj/simulation/_csrc/CMakeLists.txt b/src/myproj/simulation/_csrc/CMakeLists.txt deleted file mode 100644 index 53aa04feb150b0b15a64fb76622661f688d518f2..0000000000000000000000000000000000000000 --- a/src/myproj/simulation/_csrc/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -pybind11_add_module(_hello MODULE hello_python.cc) - -target_link_libraries(_hello PRIVATE hello complex) - -install(TARGETS _hello DESTINATION ${SKBUILD_PROJECT_NAME}) \ No newline at end of file