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 ( )
2022-08-18 21:49:15 -05:00
## Set the default build type if not specified
2022-08-24 16:34:33 -05:00
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}" )
2019-05-03 20:04:02 -05:00
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 ( )
2022-08-24 16:34:33 -05:00
set ( OPENFPGA_IPO_BUILD "auto" CACHE STRING "Should OpenFPGA be compiled with interprocedural compiler optimizations?" )
set_property ( CACHE OPENFPGA_IPO_BUILD PROPERTY STRINGS auto on off )
2020-01-03 20:56:15 -06:00
#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
2022-08-18 13:34:01 -05:00
project ( "OpenFPGA-tool-suites" C CXX )
2019-05-03 20:04:02 -05:00
# Version number
2022-05-22 02:22:43 -05:00
file ( STRINGS "VERSION.md" VERSION_NUMBER )
string ( REPLACE "." ";" VERSION_LIST ${ VERSION_NUMBER } )
list ( GET VERSION_LIST 0 OPENFPGA_VERSION_MAJOR )
list ( GET VERSION_LIST 1 OPENFPGA_VERSION_MINOR )
list ( GET VERSION_LIST 2 OPENFPGA_VERSION_PATCH )
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 )
2022-12-01 14:23:01 -06:00
include ( SwigLib )
2019-05-03 20:04:02 -05:00
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 )
2022-09-26 17:46:12 -05:00
# Options
## General options
option ( OPENFPGA_WITH_YOSYS "Enable building Yosys" ON )
option ( OPENFPGA_WITH_YOSYS_PLUGIN "Enable building Yosys plugin" ON )
option ( OPENFPGA_WITH_TEST "Enable testing build for codebase. Once enabled, make test can be run" ON )
2022-10-03 13:37:41 -05:00
option ( OPENFPGA_WITH_VERSION "Enable version always-up-to-date when building codebase. Disable only when you do not care an accurate version number" ON )
2022-12-01 14:06:27 -06:00
option ( OPENFPGA_WITH_SWIG "Enable SWIG interface when building codebase. Disable when you do not need high-level interfaces, such as Tcl/Python" ON )
2023-01-31 14:41:15 -06:00
option ( OPENFPGA_ENABLE_STRICT_COMPILE "Specifies whether compiler warnings should be treated as errors (e.g. -Werror)" OFF )
2022-09-26 17:46:12 -05:00
# Options pass on to VTR
2022-09-26 23:06:51 -05:00
set ( WITH_ABC ON CACHE BOOL "Enable building ABC in Verilog-to-Routing" )
2022-09-26 17:46:12 -05:00
set ( WITH_ODIN OFF CACHE BOOL "Enable building Odin in Verilog-to-Routing" )
set ( ODIN_DEBUG OFF CACHE BOOL "Enable building odin with debug flags in Verilog-to-Routing" )
set ( ODIN_WARN OFF CACHE BOOL "Enable building odin with extra warning flags in Verilog-to-Routing" )
set ( ODIN_COVERAGE OFF CACHE BOOL "Enable building odin with coverage flags in Verilog-to-Routing" )
set ( ODIN_TIDY OFF CACHE BOOL "Enable building odin with clang tidy in Verilog-to-Routing" )
set ( ODIN_SANITIZE OFF CACHE BOOL "Enable building odin with sanitize flags in Verilog-to-Routing" )
set ( WITH_YOSYS OFF CACHE BOOL "Enable building Yosys in Verilog-to-Routing" )
set ( ODIN_YOSYS OFF CACHE BOOL "Enable building odin with yosys in Verilog-to-Routing" )
set ( YOSYS_SV_UHDM_PLUGIN OFF CACHE BOOL "Enable building and installing Yosys SystemVerilog and UHDM plugins in Verilog-to-Routing" )
2022-10-03 13:37:41 -05:00
set ( VTR_ENABLE_VERSION ${ OPENFPGA_WITH_VERSION } CACHE BOOL "Enable version always-up-to-date when building codebase. Disable only when you do not care an accurate version number" )
2023-01-31 16:05:19 -06:00
# TODO: OpenFPGA and VPR has different requirements on no-warning build, e.g., on OS and compiler versions
#set(VTR_ENABLE_STRICT_COMPILE ${OPENFPGA_ENABLE_STRICT_COMPILE} CACHE BOOL "Specifies whether compiler warnings should be treated as errors (e.g. -Werror)")
2022-09-26 17:46:12 -05:00
2022-12-01 14:26:30 -06:00
# TCL file/lib required to link with SWIG generated wrapper
if ( OPENFPGA_WITH_SWIG )
#Find Tcl
include ( FindTCL )
message ( STATUS "tcl.h path is : ${TCL_INCLUDE_PATH}" )
message ( STATUS "libtcl.so path is : ${TCL_LIBRARY}" )
#Find SWIG
find_package ( SWIG 3.0 REQUIRED )
if ( SWIG_VERSION VERSION_GREATER_EQUAL "4.1.0" )
message ( WARNING "Using SWIG >= ${SWIG_VERSION} -flatstaticmethod flag for python" )
endif ( )
include ( UseSWIG )
endif ( )
2022-10-17 17:16:23 -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
2022-08-24 16:34:33 -05:00
#
# Interprocedural optimization
#
# Note that we manually clear the INTERPROCEDURAL_OPTIMIZATION flag on ABC later
# to avoid cmake warnings
include ( CheckIPOSupported )
check_ipo_supported ( RESULT IPO_SUPPORTED )
2022-08-24 23:51:29 -05:00
if ( OPENFPGA_IPO_BUILD STREQUAL "on" )
2022-08-24 16:34:33 -05:00
if ( IPO_SUPPORTED )
message ( STATUS "Building with IPO: on" )
set ( CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
else ( )
message ( ERROR "Building with IPO unsupported with this compiler!" )
endif ( )
2022-08-24 23:51:29 -05:00
elseif ( OPENFPGA_IPO_BUILD STREQUAL "auto" )
2022-08-24 16:34:33 -05:00
if ( IPO_SUPPORTED AND NOT CMAKE_BUILD_TYPE STREQUAL "debug" )
message ( STATUS "Building with IPO: on (auto)" )
set ( CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
else ( )
message ( STATUS "Building with IPO: off (auto)" )
endif ( )
else ( )
message ( STATUS "Building with IPO: off" )
endif ( )
2022-08-17 16:19:02 -05:00
if ( NOT MSVC )
# for GCC and Clang
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3" )
endif ( )
2019-05-23 18:37:39 -05:00
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 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
2022-08-17 11:54:31 -05:00
" - W e x t r a - s e m i " #Warn about redudnant semicolons
2022-08-17 21:22:46 -05:00
" - W i m p l i c i t - f a l l t h r o u g h = 3 " #Warn about case fallthroughs, but allow 'fallthrough' comments to suppress warnings
2022-08-17 11:54:31 -05:00
#GCC-like optional
#"-Wsuggest-final-types" #Suggest where 'final' would help if specified on a type methods
#"-Wsuggest-final-methods" #Suggest where 'final' would help if specified on methods
#"-Wsuggest-override" #Suggest where 'override' should be specified
#"-Wold-style-cast" #Warn about using c-style casts
#"-Wconversion" #Warn when type conversions may change value
#"-Wsign-conversion" #Warn if a conversion may change the sign
#"-Wpadded" #Will warn if additional padding is introduced to a struct/class. Turn on if optimizing class memory layouts
#"-Wstrict-overflow=2" #Warn if the compiler optimizes assuming signed overflow does not occur
#"-Wfloat-equal" #Warn about using direct floating point equality
#"-Wunsafe-loop-optimizations" #Warn when loops can't be optimized
#"-Wswitch-enum" #Warn about uncovered enumeration values in a switch (even if there is a default)
#"-Wsign-promo" #Warn when overload resolution converts an unsigned type to signed when an unsigned overload exists
#"-Wdouble-promotion" #Warn when float is implicitly propted to double
#"-Wuseless-cast" #Warn about casts to the same type
#"-Wzero-as-null-pointer-constant" #Warn about using '0' instead of nullptr
2019-05-03 20:04:02 -05:00
)
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 ( )
2022-08-24 18:48:19 -05:00
#Suppress IPO link warnings
set ( IPO_LINK_WARN_SUPRESS_FLAGS " " )
set ( IPO_LINK_WARN_SUPRESS_FLAGS_TO_CHECK
" - W n o - n u l l - d e r e f e r e n c e "
)
foreach ( flag ${ IPO_LINK_WARN_SUPRESS_FLAGS_TO_CHECK } )
CHECK_CXX_COMPILER_FLAG ( ${ flag } CXX_COMPILER_SUPPORTS_ ${ flag } )
if ( CXX_COMPILER_SUPPORTS_ ${ flag } )
#Flag supported, so enable it
set ( IPO_LINK_WARN_SUPRESS_FLAGS "${IPO_LINK_WARN_SUPRESS_FLAGS} ${flag}" )
endif ( )
endforeach ( )
2019-05-03 20:04:02 -05:00
#
# 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 ( )
2022-12-01 16:49:05 -06:00
# Extra flags
2022-12-01 17:16:58 -06:00
set ( SWIG_SHARED_FLAGS "" )
2022-12-01 16:49:05 -06:00
if ( OPENFPGA_WITH_SWIG )
2022-12-01 17:16:58 -06:00
set ( SWIG_SHARED_FLAGS "-fpic" )
2022-12-01 16:49:05 -06:00
endif ( )
2022-12-01 17:16:58 -06:00
add_compile_options ( ${ SWIG_SHARED_FLAGS } )
2022-12-01 16:49:05 -06:00
2019-05-03 20:04:02 -05:00
# Set final flags
#
2022-10-17 17:16:23 -05:00
separate_arguments (
2022-12-01 17:16:58 -06:00
A D D I T I O N A L _ F L A G S U N I X _ C O M M A N D " $ { S A N I T I Z E _ F L A G S } $ { P R O F I L I N G _ F L A G S } $ { C O V E R A G E _ F L A G S } $ { L O G G I N G _ F L A G S } $ { C O L O R E D _ C O M P I L E } $ { E X T R A _ F L A G S } $ { S W I G _ S H A R E D _ F L A G S } "
2022-10-17 17:16:23 -05:00
)
separate_arguments (
W A R N _ F L A G S U N I X _ C O M M A N D " $ { W A R N _ F L A G S } "
)
#
# Sub-projects with their own compiler settings
#
add_subdirectory ( vtr-verilog-to-routing )
2019-05-03 20:04:02 -05:00
2022-10-17 17:16:23 -05:00
add_compile_options ( ${ WARN_FLAGS } ) #Add warn flags for VTR tools
add_compile_options ( ${ ADDITIONAL_FLAGS } )
link_libraries ( ${ ADDITIONAL_FLAGS } )
2019-05-03 20:04:02 -05:00
# Unit Testing
#
2022-09-26 17:46:12 -05:00
if ( OPENFPGA_WITH_TEST )
enable_testing ( )
endif ( )
2019-05-03 20:04:02 -05:00
#
2022-10-17 17:16:23 -05:00
# Sub-projects to apply current complier settings
2019-05-03 20:04:02 -05:00
#
2022-08-18 12:27:20 -05:00
add_subdirectory ( libs )
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 ( )
2022-10-17 17:16:23 -05:00
#PugiXml has some deliberate switch fallthrough cases (as indicated by comments), but they
#are tagged as warnings with g++-7 (the comments don't match g++-7's suppression regexes).
#Since we don't want to change PugiXml (it is developed externally), we relax the warning
#level so no fallthrough warnings are generated
CHECK_CXX_COMPILER_FLAG ( "-Wimplicit-fallthrough=0" CXX_COMPILER_SUPPORTS_-Wimplicit-fallthrough=0 )
if ( CXX_COMPILER_SUPPORTS_-Wimplicit-fallthrough=0 )
target_compile_options ( libpugixml PRIVATE "-Wimplicit-fallthrough=0" )
endif ( )
2020-12-08 03:29:36 -06:00
2021-11-29 07:33:13 -06:00
# we will check if yosys already exist. if not then build it
2022-09-26 17:46:12 -05:00
if ( OPENFPGA_WITH_YOSYS )
if ( EXISTS ${ CMAKE_CURRENT_SOURCE_DIR } /yosys/install/bin/yosys )
message ( STATUS "Yosys pre-build exist so skipping it" )
else ( )
# 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
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
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
# yosys-plugins compilation starts
if ( OPENFPGA_WITH_YOSYS_PLUGIN )
add_custom_target (
y o s y s - p l u g i n s A L L
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 "
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 )
endif ( )
endif ( )
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