2019-05-03 20:04:02 -05:00
cmake_minimum_required ( VERSION 2.8.12 )
2019-08-21 16:25:36 -05:00
find_program ( CCACHE_FOUND ccache )
if ( CCACHE_FOUND )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_LINK ccache )
endif ( CCACHE_FOUND )
2019-05-03 20:04:02 -05:00
if ( ${ CMAKE_VERSION } VERSION_GREATER "3.8" )
#For cmake >= 3.9 INTERPROCEDURAL_OPTIMIZATION behaviour we need to explicitly
#set the cmake policy version number
cmake_policy ( VERSION 3.9 )
# If we are using verison < 3.9 then setting INTERPROCEDURAL_OPTIMIZATION
# has no effect unless an Intel compiler is used
endif ( )
# Set the default build type if not specified
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE Release CACHE STRING
" C h o o s e t h e t y p e o f b u i l d : N o n e , D e b u g , R e l e a s e , R e l W i t h D e b I n f o , M i n S i z e R e l "
F O R C E )
endif ( )
message ( STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}" )
2020-01-03 20:56:15 -06:00
if ( ${ CMAKE_SOURCE_DIR } STREQUAL ${ CMAKE_BINARY_DIR } )
message ( "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}" )
message ( "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}" )
message ( FATAL_ERROR "In-source builds not allowed. Use the Makefile wrapper (e.g. make), or create a new build directory and call cmake manually from there (e.g. mkdir -p build && cd build && cmake .. && make). You may need to 'rm -rf CMakeCache.txt CMakeFiles' first." )
endif ( )
#We install to the source directory by default
if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set ( CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "default install path" FORCE )
endif ( )
#Allow the user to configure how much assertion checking should occur
set ( VTR_ASSERT_LEVEL "2" CACHE STRING "VTR assertion checking level. 0: no assertions, 1: fast assertions, 2: regular assertions, 3: additional assertions with noticable run-time overhead, 4: all assertions (including those with significant run-time cost)" )
set_property ( CACHE VTR_ASSERT_LEVEL PROPERTY STRINGS 0 1 2 3 4 )
2019-05-03 20:04:02 -05:00
#Create the project
project ( "OPENFPGA" C CXX )
# Options
# Option to enable/disable graphic in compilation
option ( ENABLE_VPR_GRAPHICS "Enables VPR graphics" ON )
2020-01-03 20:56:15 -06:00
option ( ENABLE_VPR_GRAPHICS "Enables build with librtlnumber" OFF )
2019-05-03 20:04:02 -05:00
2020-01-27 14:44:28 -06:00
#Allow the user to decide weather to compile the graphics library
set ( VPR_USE_EZGL "auto" CACHE STRING "Specify whether vpr uses the graphics library" )
set_property ( CACHE VPR_USE_EZGL PROPERTY STRINGS auto off on )
2019-05-03 20:04:02 -05:00
# Version number
set ( OPENFPGA_VERSION_MAJOR 1 )
2022-02-20 22:48:51 -06:00
set ( OPENFPGA_VERSION_MINOR 1 )
2022-05-16 19:02:13 -05:00
set ( OPENFPGA_VERSION_PATCH 215 )
2019-05-03 20:04:02 -05:00
set ( OPENFPGA_VERSION_PRERELEASE "dev" )
# Include user-defined functions
list ( APPEND CMAKE_MODULE_PATH ${ CMAKE_CURRENT_SOURCE_DIR } /cmake/modules )
include ( FilesToDirs )
2020-01-03 20:56:15 -06:00
# Set the assertion level
add_definitions ( "-DVTR_ASSERT_LEVEL=${VTR_ASSERT_LEVEL}" )
2019-05-03 20:04:02 -05:00
# compiler flag configuration checks
include ( CheckCXXCompilerFlag )
2019-05-23 18:37:39 -05:00
#
# We require c++14 support
#
set ( CMAKE_CXX_STANDARD 14 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF ) #No compiler specific extensions
2019-05-03 20:04:02 -05:00
# Set WARN FLAGS
set ( WARN_FLAGS "" )
if ( MSVC )
# Visual studio warnings
# Note that we do not use /Wall since it generates warnings about standard library headers
set ( WARN_FLAGS_TO_CHECK # the flags to check if the compiler supports
" / W 4 " # Most warnings
)
else ( )
set ( WARN_FLAGS_TO_CHECK # the flags to check if the compiler supports
#GCC-like
" - W p o i n t e r - a r i t h "
" - W c a s t - q u a l "
" - D _ _ U S E _ F I X E D _ P R O T O T Y P E S _ _ "
" - a n s i "
" - W s h a d o w "
" - W n o - w r i t e - s t r i n g s "
" - D _ P O S I X _ S O U R C E "
" - W a l l " #Most warnings, typically good
" - W e x t r a " #Extra warning, usually good
" - W p e d a n t i c " #Ensure ISO compliance (i.e. no non-standard extensions)
" - W c a s t - q u a l " #Warn if cast removes qualifier (e.g. const char* -> char*)
" - W c a s t - a l i g n " #Warn if a cast causes memory alignment changes
" - W s h a d o w " #Warn if local variable shadows another variable
" - W f o r m a t = 2 " #Sanity checks for printf-like formatting
" - W n o - f o r m a t - n o n l i t e r a l " # But don't worry about non-literal formtting (i.e. run-time printf format strings)
" - W l o g i c a l - o p " #Checks for logical op when bit-wise expected
" - W m i s s i n g - d e c l a r a t i o n s " #Warn if a global function is defined with no declaration
" - W m i s s i n g - i n c l u d e - d i r s " #Warn if a user include directory is missing
" - W r e d u n d a n t - d e c l s " #Warn if there are overlapping declarations
" - W s w i t c h - d e f a u l t " #Warn if a switch has no default
" - W u n d e f " #Warn if #if() preprocessor refers to an undefined directive
" - W u n u s e d " #Warn about unused variables/parameters
" - W u n u s e d - v a r i a b l e " #Warn about variables that are not used
" - W u n u s e d - p a r a m e t e r " #Warn about function parameters which are unused
" - W d i s a b l e d - o p t i m i z a t i o n " #Warn when optimizations are skipped (usually due to large/complex code)
" - W n o e x c e p t " #Warn when functions should be noexcept (i.e. compiler know it doesn't throw)
" - W o v e r l o a d e d - v i r t u a l " #Warn when a function declaration overrides a virtual method
" - W c t o r - d t o r - p r i v a c y " #Warn about inaccessible constructors/destructors
" - W n o n - v i r t u a l - d t o r " #Warn about missing virtual destructors
" - W d u p l i c a t e d - c o n d " #Warn about identical conditions in if-else chains
" - W d u p l i c a t e d - b r a n c h e s " #Warn when different branches of an if-else chain are equivalent
" - W n u l l - d e r e f e r e n c e " #Warn about null pointer dereference execution paths
" - W u n i n i t i a l i z e d " #Warn about unitialized values
" - W i n i t - s e l f " #Warn about self-initialization
" - W c a t c h - v a l u e = 3 " #Warn when catch statements don't catch by reference
" - W e x t r a - s e m i " #Warn about redudnant semicolons
)
endif ( )
# check and see if the compiler supports the various warning flags
# and add valid flags
foreach ( flag ${ WARN_FLAGS_TO_CHECK } )
CHECK_CXX_COMPILER_FLAG ( ${ flag } CXX_COMPILER_SUPPORTS_ ${ flag } )
if ( CXX_COMPILER_SUPPORTS_ ${ flag } )
# flag supported, so enable it
set ( WARN_FLAGS "${WARN_FLAGS} ${flag}" )
endif ( )
endforeach ( )
#
# Sanitizer flags
#
set ( SANITIZE_FLAGS "" )
if ( OPENFPGA_ENABLE_SANITIZE )
#Enable sanitizers
# -fuse-ld=gold force the gold linker to be used (required for sanitizers, but not enabled by default on some systems)
set ( SANITIZE_FLAGS "-g -fsanitize=address -fsanitize=leak -fsanitize=undefined -fuse-ld=gold" )
message ( STATUS "SANTIIZE_FLAGS: ${SANITIZE_FLAGS}" )
link_libraries ( "-static-libasan" ) #Fixes 'ASan runtime does not come first in initial library list'
endif ( )
# Set final flags
#
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS} ${SANITIZE_FLAGS}" )
message ( STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}" )
# Unit Testing
#
enable_testing ( )
2020-01-27 14:44:28 -06:00
# set VPR_USE_EZGL in the root of VTR to decide whether to add
# subdirectory of graphics library, which prevents users
# without gtk/x11 libraries installed to build. VPR_USE_EZGL is
# being used in both the vpr CMakeLists and libs/EXTERNAL CMakeLists.
#
# check if GTK and X11 are installed and turn on/off graphics
if ( VPR_USE_EZGL STREQUAL "auto" )
find_package ( PkgConfig REQUIRED )
pkg_check_modules ( GTK3 QUIET gtk+-3.0 )
pkg_check_modules ( X11 QUIET x11 )
if ( GTK3_FOUND AND X11_FOUND )
set ( VPR_USE_EZGL "on" )
message ( STATUS "VPR Graphics: Enabled" )
else ( )
set ( VPR_USE_EZGL "off" )
message ( STATUS "VPR Graphics: Disabled (required libraries missing, on debia/ubuntu try: sudo apt install libgtk-3 libx11-dev" )
endif ( )
endif ( )
2019-05-03 20:04:02 -05:00
#
# Sub-projects
#
2019-05-15 14:22:14 -05:00
#add_subdirectory(iverilog)
2020-01-03 17:14:42 -06:00
add_subdirectory ( libs )
2020-01-12 19:11:00 -06:00
add_subdirectory ( libopenfpga )
2020-12-08 03:29:36 -06:00
#add_subdirectory(yosys)
2019-05-03 20:04:02 -05:00
add_subdirectory ( abc )
add_subdirectory ( ace2 )
2020-01-03 17:45:31 -06:00
add_subdirectory ( vpr )
2020-01-22 21:20:10 -06:00
add_subdirectory ( openfpga )
2019-05-03 20:04:02 -05:00
2020-12-08 22:35:57 -06:00
# yosys compilation starts
2020-12-08 03:29:36 -06:00
# Compilation options for yosys
include ( CMakeParseArguments )
##project(yosys)
# Options to enable/disable dependencies
2020-12-08 11:21:25 -06:00
option ( YOSYS_ENABLE_TCL, "Enable TCL parser integrated in yosys" ON )
2020-12-08 03:29:36 -06:00
option ( YOSYS_ENABLE_ABC, "Enable ABC library integrated in yosys" ON )
option ( YOSYS_ENABLE_PLUGINS, "Enable plug-in in yosys" ON )
option ( YOSYS_ENABLE_READLINE, "Enable readline library in yosys" ON )
option ( YOSYS_ENABLE_VERIFIC, "Enable verification library in yosys" OFF )
option ( YOSYS_ENABLE_COVER, "Enable coverage test in yosys" ON )
option ( YOSYS_ENABLE_LIBYOSYS, "Enable static library compiled yosys" OFF )
option ( YOSYS_ENABLE_GPROF, "Enable profiling in compiled yosys" OFF )
option ( YOSYS_ENABLE_NDEBUG, "Enable non-debugging feature in compiled yosys" OFF )
#
## Search and link dependent packages
## We need readline to compile
if ( YOSYS_ENABLE_READLINE )
find_package ( Readline REQUIRED )
endif ( )
#
#########################
## #
## Compiler Flags Setup #
## #
#########################
#
## Compiler flag configuration checks
include ( CheckCCompilerFlag )
include ( CheckCXXCompilerFlag )
#
2021-11-29 07:33:13 -06:00
# we will check if yosys already exist. if not then build it
if ( EXISTS ${ CMAKE_CURRENT_SOURCE_DIR } /yosys/install/bin/yosys )
message ( STATUS "Yosys pre-build exist so skipping it" )
else ( )
2020-12-08 03:29:36 -06:00
# run makefile provided, we pass-on the options to the local make file
add_custom_target (
y o s y s A L L
C O M M A N D $ ( M A K E ) c o n f i g - g c c
2021-11-03 20:52:09 -05:00
C O M M A N D $ ( M A K E ) i n s t a l l P R E F I X = $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / y o s y s / i n s t a l l
2020-12-08 03:29:36 -06:00
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / y o s y s
C O M M E N T " C o m p i l e Y o s y s w i t h g i v e n M a k e f i l e "
)
# yosys compilation ends
2021-11-03 20:52:09 -05:00
# yosys-plugins compilation starts
add_custom_target (
y o s y s - p l u g i n s A L L
2021-11-12 03:46:06 -06:00
C O M M A N D $ ( M A K E ) i n s t a l l _ q l - q l f Y O S Y S _ P A T H = $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / y o s y s / i n s t a l l E X T R A _ F L A G S = " - D P A S S _ N A M E = s y n t h _ q l "
2021-11-03 20:52:09 -05:00
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / y o s y s - p l u g i n s
D E P E N D S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / y o s y s / i n s t a l l / b i n / y o s y s
C O M M E N T " C o m p i l e Y o s y s - p l u g i n s w i t h g i v e n M a k e f i l e "
)
add_dependencies ( yosys-plugins yosys )
2021-11-29 07:33:13 -06:00
endif ( )
2021-11-03 20:52:09 -05:00
2019-05-03 20:04:02 -05:00
# run make to extract compiler options, linker options and list of source files
#add_custom_target(
# yosys
# COMMAND make run
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/yosys
#)
# Add extra compilation flags to suppress warnings from some libraries/tools
# Note that target_compile_options() *appends* to the current compilation options of
# the specified target
#Since ABC is an externally developed tool, we suppress all compiler warnings
CHECK_CXX_COMPILER_FLAG ( "-w" CXX_COMPILER_SUPPORTS_-w )
if ( CXX_COMPILER_SUPPORTS_-w )
target_compile_options ( libabc PRIVATE "-w" )
target_compile_options ( abc PRIVATE "-w" )
endif ( )
#Some ABC headers generate warnings, treat them as system headers to suppress warnings
get_property ( ABC_INCLUDE_DIRS TARGET libabc PROPERTY INCLUDE_DIRECTORIES )
target_include_directories ( libabc SYSTEM INTERFACE ${ ABC_INCLUDE_DIRS } )
# We use Yosys and abc Makefile now, TODO: create CMakeLists.txt as well
set_target_properties ( libabc abc
P R O P E R T I E S
A R C H I V E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a b c "
L I B R A R Y _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a b c "
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a b c " )
# Set output locations to be in the main source tree under the relevant folder
set_target_properties ( libace ace
P R O P E R T I E S
A R C H I V E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a c e 2 "
L I B R A R Y _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a c e 2 "
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a c e 2 " )
set_target_properties ( libvpr vpr
2020-01-03 21:06:40 -06:00
P R O P E R T I E S
A R C H I V E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / v p r "
L I B R A R Y _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / v p r "
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / v p r " )
2020-01-22 21:20:10 -06:00
set_target_properties ( libopenfpga openfpga
P R O P E R T I E S
A R C H I V E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / o p e n f p g a "
L I B R A R Y _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / o p e n f p g a "
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / o p e n f p g a " )