diff --git a/CMakeLists.txt b/CMakeLists.txt index a55cafa3..07102206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -368,6 +368,7 @@ set(CMAKE_EXE_LINKER_FLAGS \"-lstdc++ -lgcc -lrt\" CACHE STRING \"Initial cache\ UPDATE_COMMAND "" CMAKE_CACHE_ARGS -D${PROJECT_NAME}_SUPERBUILD:BOOL=0 + -DSKBUILD_SCRIPTS_DIR:PATH=${SKBUILD_SCRIPTS_DIR} -DBUILD_CMAKE_FROM_SOURCE:BOOL=${BUILD_CMAKE_FROM_SOURCE} -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} ${${PROJECT_NAME}_CMAKE_CACHE_ARG} @@ -448,5 +449,12 @@ include\(\"${CMakeProject_BINARY_DIR}/cmake_install.cmake\") endif() install(${type} ${file} DESTINATION "${relative_directory}" ${_permissions}) endforeach() - endif() + + endif() + # Prepare entry points + foreach(program IN ITEMS cmake ctest cpack ccmake) + configure_file(scripts/entry-point.py.in "${CMAKE_CURRENT_BINARY_DIR}/bin/${program}") + message(STATUS "INSTALLING TO: ${SKBUILD_SCRIPTS_DIR}") + install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/bin/${program}" DESTINATION "${SKBUILD_SCRIPTS_DIR}") + endforeach() endif() diff --git a/pyproject.toml b/pyproject.toml index 253bfc4e..509aabe4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,12 +38,6 @@ Source = "https://github.com/scikit-build/cmake-python-distributions" "Mailing list" = "https://groups.google.com/forum/#!forum/scikit-build" "Bug Tracker" = "https://github.com/scikit-build/cmake-python-distributions/issues" -[project.scripts] -ccmake = "cmake:ccmake" -cmake = "cmake:cmake" -cpack = "cmake:cpack" -ctest = "cmake:ctest" - [dependency-groups] test = [ diff --git a/scripts/entry-point.py.in b/scripts/entry-point.py.in new file mode 100644 index 00000000..c02e633d --- /dev/null +++ b/scripts/entry-point.py.in @@ -0,0 +1,21 @@ +#!python + +import os +import sys +import sysconfig + +# Scripts can be broken by pip's build isolation hacks +# See: https://github.com/pypa/pip/blob/102d8187a1f5a4cd5de7a549fd8a9af34e89a54f/src/pip/_internal/build_env.py#L87 +pl = sysconfig.get_paths()['platlib'] +if pl not in sys.path: + sys.path.append(pl) + +from cmake import ${program} + +if __name__ == '__main__': + if sys.argv[0].endswith('-script.pyw'): + sys.argv[0] = sys.argv[0][: -11] + elif sys.argv[0].endswith('.exe'): + sys.argv[0] = sys.argv[0][: -4] + + sys.exit(${program}())