aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2018-06-08 11:17:04 +0200
committerDavid Shah <davey1576@gmail.com>2018-06-08 11:17:04 +0200
commitc16a971c0fe5980a2d6da23e7d3d6d917cb9dc67 (patch)
tree7258aa4dbe3ff282ecc3a8ed12ff088a06c35a07
parent7f330af9f397ab121e11723bdf7b976630b7e450 (diff)
downloadnextpnr-c16a971c0fe5980a2d6da23e7d3d6d917cb9dc67.tar.gz
nextpnr-c16a971c0fe5980a2d6da23e7d3d6d917cb9dc67.tar.bz2
nextpnr-c16a971c0fe5980a2d6da23e7d3d6d917cb9dc67.zip
python: Fixing builds as importable module
Signed-off-by: David Shah <davey1576@gmail.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--common/pybindings.cc4
-rw-r--r--dummy/main.cc4
-rw-r--r--ice40/main.cc5
-rw-r--r--python/python_mod_test.py7
5 files changed, 21 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02e67e87..e6c6803d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,6 +83,7 @@ foreach (family ${FAMILIES})
add_executable(nextpnr-${family} ${COMMON_FILES} ${${ufamily}_FILES} ${GUI_SOURCE_FILES})
# Add the importable Python module target
PYTHON_ADD_MODULE(nextpnrpy_${family} ${COMMON_FILES} ${${ufamily}_FILES})
+ target_compile_definitions(nextpnrpy_${family} PRIVATE PYTHON_MODULE)
# Add any new per-architecture targets here
# Set ${family_targets} to the list of targets being build for this family
diff --git a/common/pybindings.cc b/common/pybindings.cc
index 5c86720e..454a571c 100644
--- a/common/pybindings.cc
+++ b/common/pybindings.cc
@@ -113,6 +113,7 @@ static wchar_t *program;
void init_python(const char *executable)
{
+#ifndef PYTHON_MODULE
program = Py_DecodeLocale(executable, NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode executable filename\n");
@@ -129,12 +130,15 @@ void init_python(const char *executable)
std::string perror_str = parse_python_exception();
std::cout << "Error in Python: " << perror_str << std::endl;
}
+#endif
}
void deinit_python()
{
+#ifndef PYTHON_MODULE
Py_Finalize();
PyMem_RawFree(program);
+#endif
}
void execute_python_file(const char *python_file)
diff --git a/dummy/main.cc b/dummy/main.cc
index cc6addb5..4de749b7 100644
--- a/dummy/main.cc
+++ b/dummy/main.cc
@@ -17,6 +17,8 @@
*
*/
+#ifndef PYTHON_MODULE
+
#include <QApplication>
#include "design.h"
#include "mainwindow.h"
@@ -31,3 +33,5 @@ int main(int argc, char *argv[])
return a.exec();
}
+
+#endif
diff --git a/ice40/main.cc b/ice40/main.cc
index 9fb6b0aa..073bbae2 100644
--- a/ice40/main.cc
+++ b/ice40/main.cc
@@ -16,6 +16,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
+
+#ifndef PYTHON_MODULE
+
#include <QApplication>
#include <boost/program_options.hpp>
#include <fstream>
@@ -263,3 +266,5 @@ int main(int argc, char *argv[])
deinit_python();
return rc;
}
+
+#endif
diff --git a/python/python_mod_test.py b/python/python_mod_test.py
new file mode 100644
index 00000000..e7a8de94
--- /dev/null
+++ b/python/python_mod_test.py
@@ -0,0 +1,7 @@
+# Run: PYTHONPATH=. python3 python/python_mod_test.py
+from nextpnrpy_ice40 import Chip, ChipArgs, iCE40Type
+args = ChipArgs()
+args.type = iCE40Type.HX1K
+chip = Chip(args)
+for wire in chip.getWires():
+ print(chip.getWireName(wire))