2018-06-01 17:58:31 +08:00
|
|
|
# TODO: sensible minimum CMake version
|
|
|
|
cmake_minimum_required(VERSION 3.3)
|
|
|
|
project(nextpnr)
|
2018-06-02 19:48:12 +08:00
|
|
|
# List of families to build
|
2018-06-01 17:58:31 +08:00
|
|
|
set(FAMILIES dummy ice40)
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
# set(CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra -Werror")
|
|
|
|
set(CMAKE_DEFIN)
|
2018-06-02 19:48:12 +08:00
|
|
|
# List of Boost libraries to include
|
2018-06-06 03:03:06 +08:00
|
|
|
set(boost_libs filesystem thread program_options)
|
2018-06-01 17:58:31 +08:00
|
|
|
# TODO: sensible minimum Python version
|
|
|
|
find_package(PythonInterp 3.5 REQUIRED)
|
|
|
|
find_package(PythonLibs 3.5 REQUIRED)
|
|
|
|
|
|
|
|
find_package(Boost REQUIRED COMPONENTS ${boost_libs})
|
|
|
|
|
2018-06-06 03:03:06 +08:00
|
|
|
# Get the latest abbreviated commit hash of the working branch
|
|
|
|
execute_process(
|
|
|
|
COMMAND git log -1 --format=%h
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
2018-06-12 03:04:30 +08:00
|
|
|
add_subdirectory(3rdparty/googletest/googletest)
|
|
|
|
enable_testing()
|
|
|
|
|
2018-06-06 03:03:06 +08:00
|
|
|
add_definitions("-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}")
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/common/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h
|
|
|
|
)
|
|
|
|
|
2018-06-01 17:58:31 +08:00
|
|
|
# Find Boost::Python of a suitable version in a cross-platform way
|
2018-06-02 19:48:12 +08:00
|
|
|
# Some distributions (Arch) call it libboost_python3, others such as Ubuntu
|
|
|
|
# call it libboost_python35. In the latter case we must consider all minor versions
|
|
|
|
# Original source: https://github.com/BVLC/caffe/blob/master/cmake/Dependencies.cmake#L148
|
2018-06-01 17:58:31 +08:00
|
|
|
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})
|
2018-06-06 17:27:02 +08:00
|
|
|
if ("${Boost_LIBRARIES}" MATCHES ".*(python|PYTHON).*" )
|
|
|
|
set(Boost_PYTHON_FOUND TRUE)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (NOT Boost_PYTHON_FOUND)
|
|
|
|
STRING(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" gentoo_version ${PYTHONLIBS_VERSION_STRING})
|
|
|
|
find_package(Boost COMPONENTS python-${gentoo_version} ${boost_libs})
|
|
|
|
if ("${Boost_LIBRARIES}" MATCHES ".*(python|PYTHON).*" )
|
|
|
|
set(Boost_PYTHON_FOUND TRUE)
|
|
|
|
endif ()
|
2018-06-01 17:58:31 +08:00
|
|
|
endif ()
|
|
|
|
|
2018-06-06 17:27:02 +08:00
|
|
|
if (NOT Boost_PYTHON_FOUND )
|
|
|
|
message( FATAL_ERROR "No version of Boost::Python 3.x could be found.")
|
|
|
|
endif ()
|
2018-06-06 03:03:06 +08:00
|
|
|
include(gui/gui.cmake)
|
2018-06-01 17:58:31 +08:00
|
|
|
|
2018-06-12 02:34:40 +08:00
|
|
|
include_directories(common/ gui/ frontend/json ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} 3rdparty/QtPropertyBrowser/src)
|
2018-06-07 02:44:54 +08:00
|
|
|
aux_source_directory(common/ COMMON_SRC_FILES)
|
|
|
|
aux_source_directory(frontend/json/ JSON_PARSER_FILES)
|
|
|
|
set(COMMON_FILES ${COMMON_SRC_FILES} ${JSON_PARSER_FILES})
|
2018-06-07 19:52:05 +08:00
|
|
|
set(CMAKE_BUILD_TYPE Debug)
|
2018-06-01 17:58:31 +08:00
|
|
|
|
|
|
|
foreach (family ${FAMILIES})
|
|
|
|
string(TOUPPER ${family} ufamily)
|
|
|
|
aux_source_directory(${family}/ ${ufamily}_FILES)
|
2018-06-02 19:48:12 +08:00
|
|
|
# Add the CLI binary target
|
2018-06-06 03:03:06 +08:00
|
|
|
add_executable(nextpnr-${family} ${COMMON_FILES} ${${ufamily}_FILES} ${GUI_SOURCE_FILES})
|
2018-06-02 19:48:12 +08:00
|
|
|
# Add the importable Python module target
|
2018-06-01 19:57:06 +08:00
|
|
|
PYTHON_ADD_MODULE(nextpnrpy_${family} ${COMMON_FILES} ${${ufamily}_FILES})
|
2018-06-08 17:17:04 +08:00
|
|
|
target_compile_definitions(nextpnrpy_${family} PRIVATE PYTHON_MODULE)
|
2018-06-02 19:48:12 +08:00
|
|
|
# Add any new per-architecture targets here
|
|
|
|
|
|
|
|
# Set ${family_targets} to the list of targets being build for this family
|
2018-06-01 19:57:06 +08:00
|
|
|
set(family_targets nextpnr-${family} nextpnrpy_${family})
|
2018-06-02 19:48:12 +08:00
|
|
|
# Include the family-specific CMakeFile
|
2018-06-01 17:58:31 +08:00
|
|
|
include(${family}/family.cmake)
|
|
|
|
foreach (target ${family_targets})
|
2018-06-02 19:48:12 +08:00
|
|
|
# Include family-specific source files to all family targets and set defines appropriately
|
2018-06-01 17:58:31 +08:00
|
|
|
target_include_directories(${target} PRIVATE ${family}/)
|
2018-06-12 20:24:59 +08:00
|
|
|
target_compile_definitions(${target} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family} ARCH_${ufamily} ARCHNAME=${family} -DQT_NO_KEYWORDS)
|
2018-06-06 03:03:06 +08:00
|
|
|
target_link_libraries(${target} LINK_PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${GUI_LIBRARY_FILES})
|
2018-06-01 17:58:31 +08:00
|
|
|
endforeach (target)
|
2018-06-12 03:04:30 +08:00
|
|
|
|
|
|
|
add_executable(nextpnr-${family}-test "")
|
|
|
|
target_sources(nextpnr-${family}-test PRIVATE tests/${family}/main.cpp)
|
|
|
|
target_link_libraries(nextpnr-${family}-test PRIVATE gtest_main)
|
|
|
|
add_test(${family}-test ${CMAKE_CURRENT_BINARY_DIR}/nextpnr-${family}-test)
|
2018-06-01 17:58:31 +08:00
|
|
|
endforeach (family)
|
2018-06-03 06:31:29 +08:00
|
|
|
|
|
|
|
file(GLOB_RECURSE CLANGFORMAT_FILES *.cc *.h)
|
2018-06-03 18:42:06 +08:00
|
|
|
string(REGEX REPLACE "[^;]*/ice40/chipdbs/chipdb-[^;]*.cc" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
|
2018-06-12 03:36:54 +08:00
|
|
|
string(REGEX REPLACE "[^;]*/3rdparty[^;]*" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
|
2018-06-03 06:31:29 +08:00
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
clangformat
|
|
|
|
COMMAND clang-format
|
|
|
|
-style=file
|
|
|
|
-i
|
|
|
|
${CLANGFORMAT_FILES}
|
|
|
|
)
|