aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore12
-rw-r--r--CMakeLists.txt59
-rw-r--r--Makefile35
-rw-r--r--dummy/family.cmake0
-rw-r--r--ice40/family.cmake14
5 files changed, 85 insertions, 35 deletions
diff --git a/.gitignore b/.gitignore
index 1ce0c108..f75a5be6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,15 @@
/objs/
/nextpnr-dummy
/nextpnr-ice40
+cmake-build-*/
+Makefile
+cmake_install.cmake
+compile_commands.json
+CMakeFiles
+CMakeScripts
+CTestfile.cmake
+CMakeCache.txt
+*.so
+*.dll
+*.a
+*.cbp
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..a17a07ce
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,59 @@
+# TODO: sensible minimum CMake version
+cmake_minimum_required(VERSION 3.3)
+project(nextpnr)
+
+set(FAMILIES dummy ice40)
+set(CMAKE_CXX_STANDARD 11)
+# set(CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra -Werror")
+set(CMAKE_DEFIN)
+set(boost_libs filesystem thread)
+# TODO: sensible minimum Python version
+find_package(PythonInterp 3.5 REQUIRED)
+find_package(PythonLibs 3.5 REQUIRED)
+
+find_package(Boost REQUIRED COMPONENTS ${boost_libs})
+
+# Find Boost::Python of a suitable version in a cross-platform way
+
+set(version ${PYTHONLIBS_VERSION_STRING})
+
+STRING(REGEX REPLACE "[^0-9]" "" boost_py_version ${version})
+find_package(Boost COMPONENTS "python-py${boost_py_version}" ${boost_libs})
+set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+
+while (NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND)
+ STRING(REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version})
+
+ STRING(REGEX REPLACE "[^0-9]" "" boost_py_version ${version})
+ find_package(Boost COMPONENTS "python-py${boost_py_version}" ${boost_libs})
+ set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+
+ STRING(REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version})
+ if ("${has_more_version}" STREQUAL "")
+ break()
+ endif ()
+endwhile ()
+
+if (NOT Boost_PYTHON_FOUND)
+ find_package(Boost COMPONENTS python3 ${boost_libs})
+endif ()
+
+# TODO: Find and include Qt
+
+include_directories(common/ ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
+aux_source_directory(common/ COMMON_FILES)
+
+foreach (family ${FAMILIES})
+ string(TOUPPER ${family} ufamily)
+ aux_source_directory(${family}/ ${ufamily}_FILES)
+ add_executable(nextpnr-${family} ${COMMON_FILES} ${${ufamily}_FILES})
+ # TODO: also build an importable Python module
+ # PYTHON_ADD_MODULE(pynextpnr_${family} ${COMMON_FILES} ${${ufamily}_FILES})
+ set(family_targets nextpnr-${family})
+ include(${family}/family.cmake)
+ foreach (target ${family_targets})
+ target_include_directories(${target} PRIVATE ${family}/)
+ target_compile_definitions(${target} PRIVATE ARCH_${ufamily} ARCHNAME="${family}")
+ target_link_libraries(${target} LINK_PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
+ endforeach (target)
+endforeach (family)
diff --git a/Makefile b/Makefile
deleted file mode 100644
index fd669ba7..00000000
--- a/Makefile
+++ /dev/null
@@ -1,35 +0,0 @@
-archs = dummy
-common_objs = design.o
-dummy_objs = chip.o main.o
-
-all::
-clean::
-
-include ice40/makefile.inc
-
-CXX = clang
-CXXFLAGS = -ggdb -MD -std=c++11 -O2 -Icommon
-LDFLAGS = -ggdb
-LDLIBS = -lstdc++
-
-define binaries
-all:: nextpnr-$(1)
-
-nextpnr-$(1): $$(addprefix objs/$(1)-common-,$$(common_objs)) $$(addprefix objs/$(1)-arch-,$$($(1)_objs))
- $$(CXX) -o $$@ $$(LDFLAGS) -I$(1) $$^ $$(LDLIBS)
-
-objs/$(1)-common-%.o: common/%.cc
- @mkdir -p objs
- $$(CXX) -c -o $$@ -D$$(shell echo arch_$(1) | tr a-z A-Z) $$(CXXFLAGS) -I$(1) $$<
-
-objs/$(1)-arch-%.o: $(1)/%.cc
- @mkdir -p objs
- $$(CXX) -c -o $$@ -D$$(shell echo arch_$(1) | tr a-z A-Z) $$(CXXFLAGS) -I$(1) $$<
-endef
-
-$(foreach arch,$(archs),$(eval $(call binaries,$(arch))))
-
-clean::
- rm -rf $(addprefix nextpnr-,$(archs)) objs
-
--include objs/*.d
diff --git a/dummy/family.cmake b/dummy/family.cmake
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dummy/family.cmake
diff --git a/ice40/family.cmake b/ice40/family.cmake
new file mode 100644
index 00000000..6d6c6ae0
--- /dev/null
+++ b/ice40/family.cmake
@@ -0,0 +1,14 @@
+set(devices 384 1k 5k 8k)
+set(DB_PY ${CMAKE_CURRENT_SOURCE_DIR}/ice40/chipdb.py)
+foreach (dev ${devices})
+ set(DEV_TXT_DB /usr/local/share/icebox/chipdb-${dev}.txt)
+ set(DEV_CC_DB ${CMAKE_CURRENT_SOURCE_DIR}/ice40/chipdb-${dev}.cc)
+ add_custom_command(OUTPUT ${DEV_CC_DB}
+ COMMAND python3 ${DB_PY} ${DEV_TXT_DB} > ${DEV_CC_DB}.new
+ COMMAND mv ${DEV_CC_DB}.new ${DEV_CC_DB}
+ DEPENDS ${DEV_TXT_DB} ${DB_PY}
+ )
+ foreach (target ${family_targets})
+ target_sources(${target} PRIVATE ${DEV_CC_DB})
+ endforeach (target)
+endforeach (dev)