Add a CMake based build system
Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
parent
d3e54131e7
commit
ee0a5374d8
12
.gitignore
vendored
12
.gitignore
vendored
@ -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
|
||||
|
59
CMakeLists.txt
Normal file
59
CMakeLists.txt
Normal file
@ -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)
|
35
Makefile
35
Makefile
@ -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
|
0
dummy/family.cmake
Normal file
0
dummy/family.cmake
Normal file
14
ice40/family.cmake
Normal file
14
ice40/family.cmake
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user