Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ATSPI] Some house-keeping changes #18

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[ATSPI] Add feature flag for python bindings too
Similar to what we did for NodeJS, we put the python3 bindings under a
flag that is ON by default, so that users that don't need this binding
are not annoyed by the dependency.

Now swig is required and imported only if we have either Python or NodeJS
bindings ON.

The README file was updated accordingly.
  • Loading branch information
elima committed Nov 21, 2023
commit b6fe33e760c443265a6a25a8998b389cd9441658
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

#### Dependencies

`sudo apt install libatspi2.0-dev`
`sudo apt install cmake libatspi2.0-dev`

For swig:
* `sudo apt install swig`
For Python3 bindings (optional):
* `sudo apt install swig python3-dev`

For NodeJS module (optional):
* `sudo apt install swig node-gyp`

* `sudo apt install node-gyp`
These bindings dependencies are on my default. See *Feature Flags* section below for how to disable them.

#### Build steps
```
Expand All @@ -38,7 +39,7 @@ As well as a python module.
'Google Chrome'
```

An optionally a NodeJS module `atspi_inspect.node`.
And a NodeJS module `atspi_inspect.node`.
```
% cd build/lib/atspi/
% nodejs
Expand All @@ -52,6 +53,7 @@ An optionally a NodeJS module `atspi_inspect.node`.

#### Feature flags

* Python3 bindings: `-DATSPI_PYTHON_MODULE=<ON/OFF>`, ON by default.
* NodeJS bindings: `-DATSPI_NODEJS_MODULE=<ON/OFF>`, ON by default.

### On Mac
Expand Down
65 changes: 40 additions & 25 deletions lib/atspi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Feature flag for NodeJS bindings
# Feature flag for Python bindings, ON by default
option(
ATSPI_PYTHON_MODULE
"Build Python bindings (requires swig and python3)"
ON
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As someone whose first exposure to CMake is this project: I assume if we wanted to avoid passing the command line flag to disable building this each time, we could just make a local edit to this file changing this line to OFF? Are there any other ways to change the default locally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, cmake options are cached (see CMakeCache.txt in build dir), so you only need to specify the flags once. Unless you are passing --fresh option (or cleaning the cmake cache somehow).

I suppose we could also add an environment variable that overrides the default flags, if you are doing constant re-fresh of cmake while working on swift, and it is annoying enough to have to pass the options every time. It would be a simple change.

)

# Feature flag for NodeJS bindings, ON by default
option(
ATSPI_NODEJS_MODULE
"Build NodeJS bindings (requires swig and node-gyp)"
Expand Down Expand Up @@ -67,36 +74,44 @@ target_link_libraries(
atspi_inspect
)

# SWIG Instructions to build a python module called "atspi_inspect"
# SWIG Instructions to build library bindings to different languages
# (only required if at least one binding is ON).

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
if (ATSPI_PYTHON_MODULE OR ATSPI_NODEJS_MODULE)
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
endif()

FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
# Generate Python bindings using swig + python3

SET_SOURCE_FILES_PROPERTIES(atspi_inspect.i PROPERTIES CPLUSPLUS ON)
if (ATSPI_PYTHON_MODULE)
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SWIG_ADD_LIBRARY(
# The name of the c++ library used by python module
atspi_python_inspect
TYPE SHARED
LANGUAGE python
SOURCES atspi_inspect.i
)
SET_SOURCE_FILES_PROPERTIES(atspi_inspect.i PROPERTIES CPLUSPLUS ON)

TARGET_LINK_LIBRARIES(
atspi_python_inspect
atspi_inspect
${PYTHON_LIBRARIES}
)
SWIG_ADD_LIBRARY(
# The name of the c++ library used by python module
atspi_python_inspect
TYPE SHARED
LANGUAGE python
SOURCES atspi_inspect.i
)

TARGET_LINK_LIBRARIES(
atspi_python_inspect
atspi_inspect
${PYTHON_LIBRARIES}
)

set_property(
TARGET atspi_python_inspect
PROPERTY
SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
)
endif()

set_property(
TARGET atspi_python_inspect
PROPERTY
SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
)

# Generate a NodeJS Module using swig + node-gyp

Expand Down