2018-06-01 17:58:31 +08:00
|
|
|
# TODO: sensible minimum CMake version
|
|
|
|
cmake_minimum_required(VERSION 3.3)
|
|
|
|
project(nextpnr)
|
2018-06-23 20:32:18 +08:00
|
|
|
|
|
|
|
option(BUILD_GUI "Build GUI" ON)
|
|
|
|
option(BUILD_PYTHON "Build Python Integration" ON)
|
|
|
|
option(BUILD_TESTS "Build GUI" OFF)
|
|
|
|
|
2018-06-02 19:48:12 +08:00
|
|
|
# List of families to build
|
2018-07-06 02:59:11 +08:00
|
|
|
set(FAMILIES generic ice40 ecp5)
|
2018-07-08 17:20:04 +08:00
|
|
|
|
2018-07-11 16:23:23 +08:00
|
|
|
set(ARCH "" CACHE STRING "Architecture family for nextpnr build")
|
|
|
|
set_property(CACHE ARCH PROPERTY STRINGS ${FAMILIES})
|
|
|
|
|
|
|
|
if (NOT ARCH)
|
|
|
|
message(STATUS "Architecture needs to be set, set desired one with -DARCH=xxx")
|
|
|
|
message(STATUS "Supported architectures are :")
|
|
|
|
message(STATUS " all")
|
|
|
|
foreach(item ${FAMILIES})
|
|
|
|
message(STATUS " ${item}")
|
|
|
|
endforeach()
|
|
|
|
message(FATAL_ERROR "Architecture setting is mandatory")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ARCH STREQUAL "all")
|
|
|
|
SET(ARCH ${FAMILIES})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(item ${ARCH})
|
|
|
|
if (NOT item IN_LIST FAMILIES)
|
|
|
|
message(FATAL_ERROR "Architecture '${item}' not in list of supported architectures")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2018-06-01 17:58:31 +08:00
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
2018-07-03 14:52:19 +08:00
|
|
|
if (MSVC)
|
2018-07-04 19:17:05 +08:00
|
|
|
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
|
2018-07-05 16:14:19 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /W4 /wd4100 /wd4244 /wd4125 /wd4800 /wd4456 /wd4458 /wd4305 /wd4459 /wd4121 /wd4996")
|
2018-07-05 16:33:11 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W4 /wd4100 /wd4244 /wd4125 /wd4800 /wd4456 /wd4458 /wd4305 /wd4459 /wd4121 /wd4996 /wd4127")
|
2018-07-03 14:52:19 +08:00
|
|
|
else()
|
2018-06-20 00:04:10 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -fPIC -ggdb")
|
2018-07-10 18:31:58 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "-Wall -fPIC -O3 -g")
|
2018-07-03 14:52:19 +08:00
|
|
|
endif()
|
2018-06-01 17:58:31 +08:00
|
|
|
set(CMAKE_DEFIN)
|
2018-06-25 01:32:39 +08:00
|
|
|
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
|
|
|
|
|
2018-07-05 16:14:19 +08:00
|
|
|
if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
|
|
|
|
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings")
|
|
|
|
endif()
|
|
|
|
|
2018-06-25 01:32:39 +08:00
|
|
|
find_package(Sanitizers)
|
|
|
|
|
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-23 20:32:18 +08:00
|
|
|
|
2018-07-14 20:06:05 +08:00
|
|
|
if (BUILD_GUI AND NOT BUILD_PYTHON)
|
|
|
|
message(FATAL_ERROR "GUI requires Python to build")
|
|
|
|
endif()
|
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_PYTHON)
|
|
|
|
# TODO: sensible minimum Python version
|
|
|
|
find_package(PythonInterp 3.5 REQUIRED)
|
|
|
|
find_package(PythonLibs 3.5 REQUIRED)
|
|
|
|
else()
|
|
|
|
add_definitions("-DNO_PYTHON")
|
|
|
|
endif()
|
2018-06-01 17:58:31 +08:00
|
|
|
|
|
|
|
find_package(Boost REQUIRED COMPONENTS ${boost_libs})
|
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_GUI)
|
|
|
|
# Find the Qt5 libraries
|
|
|
|
find_package(Qt5 COMPONENTS Core Widgets OpenGL REQUIRED)
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
else()
|
|
|
|
add_definitions("-DNO_GUI")
|
|
|
|
endif()
|
2018-06-20 22:13:49 +08:00
|
|
|
|
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-23 20:32:18 +08:00
|
|
|
if (BUILD_TESTS)
|
2018-07-04 02:46:05 +08:00
|
|
|
add_subdirectory(3rdparty/googletest/googletest ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/googletest EXCLUDE_FROM_ALL)
|
2018-06-23 20:32:18 +08:00
|
|
|
enable_testing()
|
|
|
|
endif()
|
2018-06-12 03:04:30 +08:00
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_GUI)
|
2018-07-11 16:23:23 +08:00
|
|
|
add_subdirectory(3rdparty/QtPropertyBrowser ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/QtPropertyBrowser EXCLUDE_FROM_ALL)
|
2018-06-23 20:32:18 +08:00
|
|
|
endif()
|
2018-06-20 20:24:16 +08:00
|
|
|
|
2018-06-06 03:03:06 +08:00
|
|
|
add_definitions("-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}")
|
2018-06-23 20:32:18 +08:00
|
|
|
|
2018-06-06 03:03:06 +08:00
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/common/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h
|
|
|
|
)
|
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_PYTHON)
|
|
|
|
# Find Boost::Python of a suitable version in a cross-platform way
|
|
|
|
# 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
|
|
|
|
set(version ${PYTHONLIBS_VERSION_STRING})
|
2018-06-01 17:58:31 +08:00
|
|
|
|
|
|
|
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})
|
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
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})
|
2018-06-01 17:58:31 +08:00
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
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})
|
|
|
|
if ("${Boost_LIBRARIES}" MATCHES ".*(python|PYTHON).*" )
|
|
|
|
set(Boost_PYTHON_FOUND TRUE)
|
|
|
|
endif ()
|
2018-06-06 17:27:02 +08:00
|
|
|
endif ()
|
|
|
|
|
2018-07-03 16:22:22 +08:00
|
|
|
if (NOT Boost_PYTHON_FOUND)
|
|
|
|
find_package(Boost COMPONENTS python36 ${boost_libs})
|
|
|
|
if ("${Boost_LIBRARIES}" MATCHES ".*(python|PYTHON).*" )
|
|
|
|
set(Boost_PYTHON_FOUND TRUE)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2018-07-12 20:36:28 +08:00
|
|
|
if (NOT Boost_PYTHON_FOUND)
|
|
|
|
find_package(Boost COMPONENTS python37 ${boost_libs})
|
|
|
|
if ("${Boost_LIBRARIES}" MATCHES ".*(python|PYTHON).*" )
|
|
|
|
set(Boost_PYTHON_FOUND TRUE)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
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-06 17:27:02 +08:00
|
|
|
endif ()
|
2018-06-01 17:58:31 +08:00
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
if (NOT Boost_PYTHON_FOUND )
|
|
|
|
message( FATAL_ERROR "No version of Boost::Python 3.x could be found.")
|
|
|
|
endif ()
|
|
|
|
endif()
|
2018-06-01 17:58:31 +08:00
|
|
|
|
2018-06-23 22:20:31 +08:00
|
|
|
include_directories(common/ json/ ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
|
2018-06-07 02:44:54 +08:00
|
|
|
aux_source_directory(common/ COMMON_SRC_FILES)
|
2018-06-23 22:20:31 +08:00
|
|
|
aux_source_directory(json/ JSON_PARSER_FILES)
|
2018-06-07 02:44:54 +08:00
|
|
|
set(COMMON_FILES ${COMMON_SRC_FILES} ${JSON_PARSER_FILES})
|
2018-06-20 00:04:10 +08:00
|
|
|
set(CMAKE_BUILD_TYPE Release)
|
2018-06-01 17:58:31 +08:00
|
|
|
|
2018-06-13 14:34:58 +08:00
|
|
|
if(MINGW)
|
|
|
|
add_definitions("-Wa,-mbig-obj")
|
|
|
|
endif(MINGW)
|
2018-07-04 18:06:03 +08:00
|
|
|
|
2018-07-11 16:23:23 +08:00
|
|
|
foreach (family ${ARCH})
|
|
|
|
message(STATUS "Configuring architecture : ${family}")
|
2018-06-01 17:58:31 +08:00
|
|
|
string(TOUPPER ${family} ufamily)
|
2018-06-23 20:32:18 +08:00
|
|
|
aux_source_directory(${family}/ ${ufamily}_FILES)
|
2018-06-20 22:13:49 +08:00
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_GUI)
|
2018-07-11 16:23:23 +08:00
|
|
|
add_subdirectory(gui ${CMAKE_CURRENT_BINARY_DIR}/generated/gui/${family} EXCLUDE_FROM_ALL)
|
2018-06-23 20:32:18 +08:00
|
|
|
endif()
|
2018-06-20 22:13:49 +08:00
|
|
|
|
2018-06-02 19:48:12 +08:00
|
|
|
# Add the CLI binary target
|
2018-07-11 16:23:23 +08:00
|
|
|
add_executable(nextpnr-${family} ${COMMON_FILES} ${${ufamily}_FILES})
|
2018-06-13 19:09:37 +08:00
|
|
|
install(TARGETS nextpnr-${family} RUNTIME DESTINATION bin)
|
2018-06-13 01:56:03 +08:00
|
|
|
target_compile_definitions(nextpnr-${family} PRIVATE MAIN_EXECUTABLE)
|
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_PYTHON)
|
|
|
|
# Add the importable Python module target
|
2018-07-11 16:23:23 +08:00
|
|
|
PYTHON_ADD_MODULE(nextpnrpy_${family} ${COMMON_FILES} ${${ufamily}_FILES})
|
2018-06-23 20:32:18 +08:00
|
|
|
endif()
|
|
|
|
|
2018-06-02 19:48:12 +08:00
|
|
|
# Add any new per-architecture targets here
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_TESTS)
|
|
|
|
aux_source_directory(tests/${family}/ ${ufamily}_TEST_FILES)
|
|
|
|
|
|
|
|
add_executable(nextpnr-${family}-test ${${ufamily}_TEST_FILES} ${COMMON_FILES} ${${ufamily}_FILES})
|
|
|
|
target_link_libraries(nextpnr-${family}-test PRIVATE gtest_main)
|
2018-06-25 01:32:39 +08:00
|
|
|
add_sanitizers(nextpnr-${family}-test)
|
2018-06-02 19:48:12 +08:00
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
add_test(${family}-test ${CMAKE_CURRENT_BINARY_DIR}/nextpnr-${family}-test)
|
|
|
|
endif()
|
2018-06-13 01:56:03 +08:00
|
|
|
|
2018-06-02 19:48:12 +08:00
|
|
|
# Set ${family_targets} to the list of targets being build for this family
|
2018-06-23 20:32:18 +08:00
|
|
|
set(family_targets nextpnr-${family})
|
|
|
|
|
|
|
|
if (BUILD_TESTS)
|
|
|
|
set(family_targets ${family_targets} nextpnr-${family}-test)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (BUILD_PYTHON)
|
|
|
|
set(family_targets ${family_targets} nextpnrpy_${family})
|
|
|
|
endif()
|
|
|
|
|
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-07-04 02:46:05 +08:00
|
|
|
target_include_directories(${target} PRIVATE ${family}/ ${CMAKE_CURRENT_BINARY_DIR}/generated/)
|
2018-06-23 20:32:18 +08:00
|
|
|
target_compile_definitions(${target} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family} ARCH_${ufamily} ARCHNAME=${family})
|
2018-07-16 14:07:57 +08:00
|
|
|
target_link_libraries(${target} LINK_PUBLIC ${Boost_LIBRARIES})
|
|
|
|
if (NOT MSVC)
|
|
|
|
target_link_libraries(${target} LINK_PUBLIC pthread)
|
|
|
|
endif()
|
2018-06-25 01:32:39 +08:00
|
|
|
add_sanitizers(${target})
|
2018-06-23 20:32:18 +08:00
|
|
|
if (BUILD_GUI)
|
|
|
|
target_include_directories(${target} PRIVATE gui/${family}/ gui/)
|
|
|
|
target_compile_definitions(${target} PRIVATE QT_NO_KEYWORDS)
|
|
|
|
target_link_libraries(${target} LINK_PUBLIC gui_${family} ${GUI_LIBRARY_FILES_${ufamily}})
|
|
|
|
endif()
|
2018-07-02 16:59:25 +08:00
|
|
|
if (BUILD_PYTHON)
|
|
|
|
target_link_libraries(${target} LINK_PUBLIC ${PYTHON_LIBRARIES})
|
|
|
|
endif()
|
2018-06-01 17:58:31 +08:00
|
|
|
endforeach (target)
|
|
|
|
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-07-08 18:56:43 +08:00
|
|
|
string(REGEX REPLACE "[^;]*/ecp5/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-13 01:56:03 +08:00
|
|
|
string(REGEX REPLACE "[^;]*/generated[^;]*" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
|
2018-06-03 06:31:29 +08:00
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
clangformat
|
|
|
|
COMMAND clang-format
|
|
|
|
-style=file
|
|
|
|
-i
|
|
|
|
${CLANGFORMAT_FILES}
|
|
|
|
)
|