Skip to content

Commit 43c4dee

Browse files
committed
cleanup
1 parent d90a1da commit 43c4dee

File tree

7 files changed

+110
-68
lines changed

7 files changed

+110
-68
lines changed

.dockerignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
ci/Makefile
1010
#ci/docker
1111
**/Dockerfile
12+
**/Vagrantfile
1213
ci/docs
1314
ci/cache
1415
ci/export
@@ -18,7 +19,10 @@ CONTRIBUTING.md
1819
CONTRIBUTORS
1920
LICENSE
2021
README.md
21-
doc
22+
docs/
23+
tools/Makefile
24+
tools/export
25+
tools/**/*.Dockerfile
2226

2327
# Native cmake build
2428
build/

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ add_subdirectory(cmake/dependencies dependencies)
7474
option(FETCH_PYTHON_DEPS "Install python required modules if not available" ON)
7575
message(STATUS "Python fetch dependencies: ${FETCH_PYTHON_DEPS}")
7676

77+
option(VENV_USE_SYSTEM_SITE_PACKAGES "Python venv can use system site packages" OFF)
78+
message(STATUS "Python: Allow venv to use system site packages: ${VENV_USE_SYSTEM_SITE_PACKAGES}")
79+
7780
include(deps)
7881
include(python)
7982

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
Github-CI:<br>
2-
[![Build Status][github_linux_status]][github_linux_link]
3-
[![Build Status][github_macos_status]][github_macos_link]
4-
[![Build Status][github_windows_status]][github_windows_link]<br>
2+
[![Build Status][github_amd64_linux_status]][github_amd64_linux_link]
3+
[![Build Status][github_amd64_macos_status]][github_amd64_macos_link]
4+
[![Build Status][github_arm64_macos_status]][github_arm64_macos_link]
5+
[![Build Status][github_amd64_windows_status]][github_amd64_windows_link]<br>
56
[![Build Status][github_amd64_docker_status]][github_amd64_docker_link]
67
[![Build Status][github_arm64_docker_status]][github_arm64_docker_link]
7-
8-
[github_linux_status]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_linux.yml/badge.svg
9-
[github_linux_link]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_linux.yml
10-
[github_macos_status]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_macos.yml/badge.svg
11-
[github_macos_link]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_macos.yml
12-
[github_windows_status]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_windows.yml/badge.svg
13-
[github_windows_link]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_windows.yml
14-
[github_amd64_docker_status]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_docker.yml/badge.svg
15-
[github_amd64_docker_link]: https://github.com/Mizux/cmake-pybind11/actions/workflows/amd64_docker.yml
16-
[github_arm64_docker_status]: https://github.com/Mizux/cmake-pybind11/actions/workflows/arm64_docker.yml/badge.svg
17-
[github_arm64_docker_link]: https://github.com/Mizux/cmake-pybind11/actions/workflows/arm64_docker.yml
8+
[![Build Status][github_riscv64_docker_status]][github_riscv64_docker_link]
9+
10+
[github_amd64_linux_status]: ./../../actions/workflows/amd64_linux.yml/badge.svg
11+
[github_amd64_linux_link]: ./../../actions/workflows/amd64_linux.yml
12+
[github_amd64_macos_status]: ./../../actions/workflows/amd64_macos.yml/badge.svg
13+
[github_amd64_macos_link]: ./../../actions/workflows/amd64_macos.yml
14+
[github_arm64_macos_status]: ./../../actions/workflows/arm64_macos.yml/badge.svg
15+
[github_arm64_macos_link]: ./../../actions/workflows/arm64_macos.yml
16+
[github_amd64_windows_status]: ./../../actions/workflows/amd64_windows.yml/badge.svg
17+
[github_amd64_windows_link]: ./../../actions/workflows/amd64_windows.yml
18+
[github_amd64_docker_status]: ./../../actions/workflows/amd64_docker.yml/badge.svg
19+
[github_amd64_docker_link]: ./../../actions/workflows/amd64_docker.yml
20+
[github_arm64_docker_status]: ./../../actions/workflows/arm64_docker.yml/badge.svg
21+
[github_arm64_docker_link]: ./../../actions/workflows/arm64_docker.yml
22+
[github_riscv64_docker_status]: ./../../actions/workflows/riscv64_docker.yml/badge.svg
23+
[github_riscv64_docker_link]: ./../../actions/workflows/riscv64_docker.yml
1824

1925
# Introduction
2026
<nav for="project"> |

ci/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ make --directory=ci
2626
```
2727

2828
### Example
29+
2930
For example to test inside an `Alpine` container:
3031
```sh
3132
make alpine_test
@@ -38,6 +39,7 @@ Dockerfile is splitted in several stages.
3839
![docker](docs/deps.svg)
3940

4041
### Run arm64v8 image on amd64 machine
42+
4143
You can build and run `arm64v8` (i.e. `aarch64`) docker container on a `amd64` host (`x86_64`) by enabling qemu support:
4244
```sh
4345
docker run --pull always --rm --privileged multiarch/qemu-user-static --reset -p yes
@@ -51,6 +53,7 @@ docker run --rm -it arm64v8/ubuntu
5153
ref: https://github.com/docker-library/official-images#architectures-other-than-amd64
5254

5355
### Docker buildx
56+
5457
ref: https://docs.docker.com/buildx/working-with-buildx/
5558

5659
Once you enable QEMU support (see above), you can list available platform using:
@@ -71,29 +74,33 @@ To control the version of CMake, instead of using the
7174
* Install it using the [pypi package cmake](https://pypi.org/project/cmake/) (need a python stack)
7275

7376
### Install prebuilt
77+
7478
The recommended and faster way is to use the prebuilt version:
79+
7580
```Dockerfile
76-
# Install CMake 3.21.4
77-
RUN wget "https://cmake.org/files/v3.21/cmake-3.21.4-linux-x86_64.sh" \
78-
&& chmod a+x cmake-3.21.4-linux-x86_64.sh \
79-
&& ./cmake-3.21.4-linux-x86_64.sh --prefix=/usr/local/ --skip-license \
80-
&& rm cmake-3.21.4-linux-x86_64.sh
81+
# Install CMake 3.26.4
82+
RUN wget "https://cmake.org/files/v3.26/cmake-3.26.4-linux-x86_64.sh" \
83+
&& chmod a+x cmake-3.26.4-linux-x86_64.sh \
84+
&& ./cmake-3.26.4-linux-x86_64.sh --prefix=/usr/local/ --skip-license \
85+
&& rm cmake-3.26.4-linux-x86_64.sh
8186
```
8287

8388
**warning**: Since [CMake 3.20](https://cmake.org/files/v3.20/) Kitware use a lowercase `linux` instead of `Linux`.
8489

8590
### Build from source
91+
8692
To build from source you can use the following snippet:
93+
8794
```Dockerfile
88-
# Install CMake 3.21.4
89-
RUN wget "https://cmake.org/files/v3.21/cmake-3.21.4.tar.gz" \
90-
&& tar xzf cmake-3.21.4.tar.gz \
91-
&& rm cmake-3.21.4.tar.gz \
92-
&& cd cmake-3.21.4 \
95+
# Install CMake 3.26.4
96+
RUN wget "https://cmake.org/files/v3.26/cmake-3.26.4.tar.gz" \
97+
&& tar xzf cmake-3.26.4.tar.gz \
98+
&& rm cmake-3.26.4.tar.gz \
99+
&& cd cmake-3.26.4 \
93100
&& ./bootstrap --prefix=/usr/local/ \
94101
&& make \
95102
&& make install \
96103
&& cd .. \
97-
&& rm -rf cmake-3.21.4
104+
&& rm -rf cmake-3.26.4
98105
```
99106

ci/vagrant/netbsd/Vagrantfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Vagrant.configure("2") do |config|
8686
pkgin upgrade
8787
pkgin -y install git cmake
8888
pkgin -y install mozilla-rootcerts-openssl
89+
pkgin -y install python312 py312-wheel py312-pip py312-pytest-virtualenv
90+
pkgin -y install py312-numpy py312-pandas py312-matplotlib
8991
SHELL
9092

9193
config.vm.provision "gcc14", type: "shell", inline:<<-SHELL

ci/vagrant/openbsd/Vagrantfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ Vagrant.configure("2") do |config|
9393
set -x
9494
pkg_add -u
9595
pkg_add git cmake
96+
pkg_add python-3.11 py3-pip py3-wheel py3-setuptools py3-virtualenv
97+
pkg_add py3-numpy py3-pandas py3-matplotlib
9698
SHELL
9799

98100
config.vm.provision "file", source: "../../../CMakeLists.txt", destination: "$HOME/project/"

cmake/python.cmake

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function(search_python_module)
4141
OUTPUT_VARIABLE MODULE_VERSION
4242
ERROR_QUIET
4343
OUTPUT_STRIP_TRAILING_WHITESPACE
44-
)
44+
)
4545
endif()
4646
if(${_RESULT} STREQUAL "0")
4747
message(STATUS "Found python module: \"${MODULE_NAME}\" (found version \"${MODULE_VERSION}\")")
@@ -51,7 +51,8 @@ function(search_python_module)
5151
execute_process(
5252
COMMAND ${Python3_EXECUTABLE} -m pip install --user ${MODULE_PACKAGE}
5353
OUTPUT_STRIP_TRAILING_WHITESPACE
54-
)
54+
COMMAND_ERROR_IS_FATAL ANY
55+
)
5556
else()
5657
message(FATAL_ERROR "Can't find python module: \"${MODULE_NAME}\", please install it using your system package manager.")
5758
endif()
@@ -88,6 +89,47 @@ function(search_python_internal_module)
8889
endif()
8990
endfunction()
9091

92+
###################
93+
## Python Test ##
94+
###################
95+
if(BUILD_TESTING)
96+
#search_python_module(NAME virtualenv PACKAGE virtualenv)
97+
# venv not working on github windows runners
98+
search_python_internal_module(NAME venv)
99+
# Testing using a vitual environment
100+
#set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m virtualenv)
101+
set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m venv)
102+
set(VENV_DIR ${CMAKE_CURRENT_BINARY_DIR}/python/venv)
103+
if(WIN32)
104+
set(VENV_Python3_EXECUTABLE ${VENV_DIR}/Scripts/python.exe)
105+
else()
106+
set(VENV_Python3_EXECUTABLE ${VENV_DIR}/bin/python)
107+
endif()
108+
endif()
109+
110+
if(BUILD_TESTING)
111+
# add_python_test()
112+
# CMake function to generate and build python test.
113+
# Parameters:
114+
# the python filename
115+
# e.g.:
116+
# add_python_test(foo.py)
117+
function(add_python_test FILE_NAME)
118+
message(STATUS "Configuring test ${FILE_NAME} ...")
119+
get_filename_component(TEST_NAME ${FILE_NAME} NAME_WE)
120+
add_test(
121+
NAME python_test_${TEST_NAME}
122+
COMMAND ${VENV_Python3_EXECUTABLE} -m pytest ${FILE_NAME}
123+
WORKING_DIRECTORY ${VENV_DIR})
124+
message(STATUS "Configuring test ${FILE_NAME} done")
125+
endfunction()
126+
endif()
127+
128+
#######################
129+
## PYTHON WRAPPERS ##
130+
#######################
131+
list(APPEND CMAKE_SWIG_FLAGS "-I${PROJECT_SOURCE_DIR}")
132+
91133
set(PYTHON_PROJECT cmakepybind11)
92134
message(STATUS "Python project: ${PYTHON_PROJECT}")
93135
set(PYTHON_PROJECT_DIR ${PROJECT_BINARY_DIR}/python/${PYTHON_PROJECT})
@@ -103,6 +145,7 @@ endforeach()
103145
#######################
104146
#file(MAKE_DIRECTORY python/${PYTHON_PROJECT})
105147
file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/__init__.py CONTENT "__version__ = \"${PROJECT_VERSION}\"\n")
148+
106149
file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/foo/__init__.py CONTENT "")
107150
file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/bar/__init__.py CONTENT "")
108151
file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/foobar/__init__.py CONTENT "")
@@ -123,7 +166,7 @@ file(GENERATE
123166
# COMMAND ${CMAKE_COMMAND} -E copy setup.py setup.py
124167
# WORKING_DIRECTORY python)
125168

126-
# Look for python module wheel
169+
# Look for python modules
127170
search_python_module(
128171
NAME setuptools
129172
PACKAGE setuptools)
@@ -132,7 +175,7 @@ search_python_module(
132175
PACKAGE wheel)
133176

134177
add_custom_command(
135-
OUTPUT python/dist/timestamp
178+
OUTPUT python/dist_timestamp
136179
COMMAND ${CMAKE_COMMAND} -E remove_directory dist
137180
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_PROJECT}/.libs
138181
# Don't need to copy static lib on Windows.
@@ -150,7 +193,7 @@ add_custom_command(
150193
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pyFooBar> ${PYTHON_PROJECT}/foobar
151194
#COMMAND ${Python3_EXECUTABLE} setup.py bdist_egg bdist_wheel
152195
COMMAND ${Python3_EXECUTABLE} setup.py bdist_wheel
153-
COMMAND ${CMAKE_COMMAND} -E touch ${PROJECT_BINARY_DIR}/python/dist/timestamp
196+
COMMAND ${CMAKE_COMMAND} -E touch ${PROJECT_BINARY_DIR}/python/dist_timestamp
154197
MAIN_DEPENDENCY
155198
python/setup.py.in
156199
DEPENDS
@@ -170,59 +213,34 @@ add_custom_command(
170213
# Main Target
171214
add_custom_target(python_package ALL
172215
DEPENDS
173-
python/dist/timestamp
216+
python/dist_timestamp
174217
WORKING_DIRECTORY python)
175218

176-
###################
177-
## Python Test ##
178-
###################
179219
if(BUILD_TESTING)
180-
search_python_module(NAME virtualenv PACKAGE virtualenv)
181-
# venv not working on github windows runners
182-
# search_python_internal_module(NAME venv)
183-
# Testing using a vitual environment
184-
set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m virtualenv)
185-
#set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m venv)
186-
set(VENV_DIR ${CMAKE_CURRENT_BINARY_DIR}/python/venv)
187-
if(WIN32)
188-
set(VENV_Python3_EXECUTABLE ${VENV_DIR}/Scripts/python.exe)
189-
else()
190-
set(VENV_Python3_EXECUTABLE ${VENV_DIR}/bin/python)
191-
endif()
192220
# make a virtualenv to install our python package in it
193221
add_custom_command(TARGET python_package POST_BUILD
194222
# Clean previous install otherwise pip install may do nothing
195223
COMMAND ${CMAKE_COMMAND} -E remove_directory ${VENV_DIR}
196-
COMMAND ${VENV_EXECUTABLE} -p ${Python3_EXECUTABLE} ${VENV_DIR}
224+
#COMMAND ${VENV_EXECUTABLE} -p ${Python3_EXECUTABLE}
225+
COMMAND ${VENV_EXECUTABLE}
226+
$<$<BOOL:${VENV_USE_SYSTEM_SITE_PACKAGES}>:--system-site-packages>
227+
${VENV_DIR}
197228
#COMMAND ${VENV_EXECUTABLE} ${VENV_DIR}
198229
# Must NOT call it in a folder containing the setup.py otherwise pip call it
199230
# (i.e. "python setup.py bdist") while we want to consume the wheel package
200-
COMMAND ${VENV_Python3_EXECUTABLE} -m pip install --find-links=${CMAKE_CURRENT_BINARY_DIR}/python/dist ${PYTHON_PROJECT}
231+
COMMAND ${VENV_Python3_EXECUTABLE} -m pip install
232+
--find-links=${CMAKE_CURRENT_BINARY_DIR}/python/dist ${PYTHON_PROJECT}==${PROJECT_VERSION}
233+
# install modules only required to run examples
234+
COMMAND ${VENV_Python3_EXECUTABLE} -m pip install pytest
201235
BYPRODUCTS ${VENV_DIR}
202236
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
203237
COMMENT "Create venv and install ${PYTHON_PROJECT}"
204238
VERBATIM)
205239
endif()
206240

207-
# add_python_test()
208-
# CMake function to generate and build python test.
209-
# Parameters:
210-
# the python filename
211-
# e.g.:
212-
# add_python_test(foo.py)
213-
function(add_python_test FILE_NAME)
214-
message(STATUS "Configuring test ${FILE_NAME} ...")
215-
get_filename_component(EXAMPLE_NAME ${FILE_NAME} NAME_WE)
216-
217-
if(BUILD_TESTING)
218-
add_test(
219-
NAME python_test_${EXAMPLE_NAME}
220-
COMMAND ${VENV_Python3_EXECUTABLE} ${FILE_NAME}
221-
WORKING_DIRECTORY ${VENV_DIR})
222-
endif()
223-
message(STATUS "Configuring test ${FILE_NAME} done")
224-
endfunction()
225-
241+
######################
242+
## Python Example ##
243+
######################
226244
# add_python_example()
227245
# CMake function to generate and build python example.
228246
# Parameters:

0 commit comments

Comments
 (0)