diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2023-10-26 12:26:15 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@github.mail.kapsi.fi> | 2023-10-27 13:37:50 +0300 |
commit | 6bbb70af1a7dc47e737957e1ad469581dcbf99f6 (patch) | |
tree | 2dd2b40297ea4c0b0f736669215226b03e9c4933 /extra | |
parent | f5593b78ba0984c8a4d8382f93b17ee7dd490ba8 (diff) |
CMake: Installation improvements.
- Allow installed nanopb_generator.py wrapper script find the module by relative path.
- Install include files under `nanopb` subdirectory.
Diffstat (limited to 'extra')
-rwxr-xr-x | extra/script_wrappers/nanopb_generator.py | 6 | ||||
-rwxr-xr-x | extra/script_wrappers/nanopb_generator.py.in | 24 |
2 files changed, 24 insertions, 6 deletions
diff --git a/extra/script_wrappers/nanopb_generator.py b/extra/script_wrappers/nanopb_generator.py deleted file mode 100755 index 493a91f..0000000 --- a/extra/script_wrappers/nanopb_generator.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python3 -# This script is a wrapper to invoke nanopb_generator from an installed Python module. -import sys -from nanopb.generator.nanopb_generator import main_cli, main_plugin -if __name__ == '__main__': - sys.exit(main_cli()) diff --git a/extra/script_wrappers/nanopb_generator.py.in b/extra/script_wrappers/nanopb_generator.py.in new file mode 100755 index 0000000..d44a9db --- /dev/null +++ b/extra/script_wrappers/nanopb_generator.py.in @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# This script is a wrapper to invoke nanopb_generator from an installed Python module. +import sys +import os.path + +# CMakeLists.txt can provide this file the path to Python module installation +# location. It is used as a relative path. By default only system path is used. +python_instdir = r"@PYTHON_INSTDIR@" +cmake_bindir = r"@CMAKE_INSTALL_BINDIR@" +cmake_install_prefix = r"@CMAKE_INSTALL_PREFIX@" +if python_instdir[0] != '@': + python_instdir = os.path.join(cmake_install_prefix, python_instdir) + cmake_bindir = os.path.join(cmake_install_prefix, cmake_bindir) + relpath = os.path.relpath(python_instdir, cmake_bindir) + bindir = os.path.dirname(os.path.realpath(__file__)) + libdir = os.path.abspath(os.path.join(bindir, relpath)) + if os.path.isdir(libdir): + sys.path.insert(0, libdir) # Path after make install + else: + sys.path.insert(0, bindir) # Path before make install + +from nanopb.generator.nanopb_generator import main_cli, main_plugin +if __name__ == '__main__': + sys.exit(main_cli()) |