2020-01-03 17:14:42 -06:00
cmake_minimum_required ( VERSION 3.9 )
2020-07-04 18:31:34 -05:00
project ( "vpr" )
2020-01-03 17:14:42 -06:00
set ( VPR_EXECUTION_ENGINE "auto" CACHE STRING "Specify the framework for (potential) parallel execution" )
set_property ( CACHE VPR_EXECUTION_ENGINE PROPERTY STRINGS auto serial tbb )
option ( VPR_USE_SIGNAL_HANDLER "Should VPR use a signal handler to intercept signals (e.g. SIGINT)?" OFF )
set ( VPR_PGO_CONFIG "none" CACHE STRING "Configure VPR Profile-Guided Optimization (PGO). prof_gen: built executable will produce profiling info, prof_use: built executable will be optimized based on generated profiling info, none: disable pgo" )
set_property ( CACHE VPR_PGO_CONFIG PROPERTY STRINGS prof_gen prof_use none )
#Handle graphics setup
set ( GRAPHICS_DEFINES "" )
if ( VPR_USE_EZGL STREQUAL "on" )
message ( STATUS "EZGL: graphics enabled" )
set (
R E S O U R C E _ L I S T
# Strip all the whitespace characters from ui file
S T R I P B L A N K S m a i n . u i
)
list ( APPEND CMAKE_MODULE_PATH
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / l i b s / E X T E R N A L / l i b e z g l / g c r - c m a k e / m a c r o s )
include ( GlibCompileResourcesSupport )
else ( )
list ( APPEND GRAPHICS_DEFINES "-DNO_GRAPHICS" )
message ( STATUS "EZGL: graphics disabled" )
endif ( )
#
# Build Configuration
#
include ( CheckCXXSymbolExists )
#Collect the source files
file ( GLOB_RECURSE EXEC_SOURCES src/main.cpp )
file ( GLOB_RECURSE LIB_SOURCES src/*/*.cpp )
file ( GLOB_RECURSE LIB_HEADERS src/*/*.h )
files_to_dirs ( LIB_HEADERS LIB_INCLUDE_DIRS )
if ( ${ VTR_ENABLE_CAPNPROTO } )
add_definitions ( "-DVTR_ENABLE_CAPNPROTO" )
endif ( )
#Create the library
2020-07-04 18:31:34 -05:00
add_library ( libvpr STATIC
2020-01-03 17:14:42 -06:00
$ { L I B _ H E A D E R S }
$ { L I B _ S O U R C E S }
)
2020-07-04 18:31:34 -05:00
target_include_directories ( libvpr PUBLIC ${ LIB_INCLUDE_DIRS } )
set_target_properties ( libvpr PROPERTIES PREFIX "" ) #Avoid extra 'lib' prefix
2020-01-03 17:14:42 -06:00
#Specify link-time dependancies
2020-07-04 18:31:34 -05:00
target_link_libraries ( libvpr
2020-03-04 15:14:28 -06:00
l i b v t r u t i l
l i b o p e n f p g a u t i l
l i b a r c h f p g a
l i b s d c p a r s e
l i b b l i f p a r s e
l i b t a t u m
l i b a r g p a r s e
l i b p u g i x m l )
2020-01-03 17:14:42 -06:00
#link graphics library only when graphics set to on
if ( VPR_USE_EZGL STREQUAL "on" )
2020-07-04 18:31:34 -05:00
target_link_libraries ( libvpr
2020-01-03 17:14:42 -06:00
e z g l )
compile_gresources (
# input: the name of our resources
R E S O U R C E _ F I L E
# output: the filename of the generated XML file
X M L _ O U T
# generate C code to be compiled with our program
T Y P E
E M B E D _ C
# specify the name of the C file that is generated
T A R G E T
r e s o u r c e s . C
# specify the resource prefix (used in the code)
P R E F I X
/ e z g l
# input: specify the list of files to compile into resources
R E S O U R C E S
$ { R E S O U R C E _ L I S T }
)
add_custom_target (
r e s o u r c e A L L
D E P E N D S
$ { R E S O U R C E _ F I L E }
)
#Create the executable with resources
list ( APPEND EXEC_SOURCES ${ CMAKE_CURRENT_BINARY_DIR } /resources.C )
endif ( )
2020-07-04 18:31:34 -05:00
target_compile_definitions ( libvpr PUBLIC ${ GRAPHICS_DEFINES } )
2020-01-03 17:14:42 -06:00
if ( ${ VTR_ENABLE_CAPNPROTO } )
2020-07-04 18:31:34 -05:00
target_link_libraries ( libvpr libvtrcapnproto )
2020-01-03 17:14:42 -06:00
endif ( )
2020-07-04 18:31:34 -05:00
add_executable ( vpr ${ EXEC_SOURCES } )
2020-01-03 17:14:42 -06:00
2020-07-04 18:31:34 -05:00
target_link_libraries ( vpr libvpr )
2020-01-03 17:14:42 -06:00
#Supress IPO link warnings if IPO is enabled
get_target_property ( VPR_USES_IPO vpr INTERPROCEDURAL_OPTIMIZATION )
if ( VPR_USES_IPO )
2020-07-04 18:31:34 -05:00
set_target_properties ( vpr PROPERTIES LINK_FLAGS ${ IPO_LINK_WARN_SUPRESS_FLAGS } )
2020-01-03 17:14:42 -06:00
endif ( )
#
# VPR compiler options
#
set ( VPR_COMPILE_OPTIONS_FLAGS
#GCC-like
" - W e r r o r "
)
#
# Profile Guilded Optimization Configuration
#
set ( PROF_GEN_FLAGS_TO_CHECK
#GCC-like
" - f p r o f i l e - g e n e r a t e " #Build will generate profiling information
)
set ( PROF_USE_FLAGS_TO_CHECK
#GCC-like
" - f p r o f i l e - u s e " #Build will use previously generated profiling information to guide code optimization
" - W m i s s i n g - p r o f i l e " #Warn if the used profiling information doesn't match the source code or is missing
)
if ( VPR_PGO_CONFIG STREQUAL "prof_gen" )
message ( STATUS "VPR: building to generate profiling data for PGO" )
foreach ( flag ${ PROF_GEN_FLAGS_TO_CHECK } )
CHECK_CXX_COMPILER_FLAG ( ${ flag } CXX_COMPILER_SUPPORTS_ ${ flag } )
if ( CXX_COMPILER_SUPPORTS_ ${ flag } )
2020-07-04 18:31:34 -05:00
target_compile_options ( libvpr PUBLIC ${ flag } )
target_compile_options ( vpr PUBLIC ${ flag } )
target_link_libraries ( vpr ${ flag } )
2020-01-03 17:14:42 -06:00
endif ( )
endforeach ( )
elseif ( VPR_PGO_CONFIG STREQUAL "prof_use" )
message ( STATUS "VPR: using generated profiling data for PGO" )
foreach ( flag ${ PROF_USE_FLAGS_TO_CHECK } )
CHECK_CXX_COMPILER_FLAG ( ${ flag } CXX_COMPILER_SUPPORTS_ ${ flag } )
if ( CXX_COMPILER_SUPPORTS_ ${ flag } )
2020-07-04 18:31:34 -05:00
target_compile_options ( libvpr PUBLIC ${ flag } )
target_compile_options ( vpr PUBLIC ${ flag } )
target_link_libraries ( vpr ${ flag } )
2020-01-03 17:14:42 -06:00
endif ( )
endforeach ( )
elseif ( VPR_PGO_CONFIG STREQUAL "none" )
#Pass
else ( )
message ( ERROR "Unsupported VPR_PGO_CONFIG '${VPR_PGO_CONFIG}'" )
endif ( )
if ( VTR_COMPILE_OPTIONS STREQUAL "strict" )
message ( STATUS "VPR: building with strict flags" )
foreach ( flag ${ VPR_COMPILE_OPTIONS_FLAGS } )
message ( STATUS "\tAdding CXX flag: ${flag}" )
2020-07-04 18:31:34 -05:00
target_compile_options ( libvpr PRIVATE ${ flag } )
target_compile_options ( vpr PRIVATE ${ flag } )
target_link_libraries ( vpr ${ flag } )
2020-01-03 17:14:42 -06:00
endforeach ( )
endif ( )
find_package ( TBB )
#
# Execution Engine Configuration
#
#Figure out which engine to use
if ( VPR_EXECUTION_ENGINE STREQUAL "serial" )
set ( VPR_USE_EXECUTION_ENGINE "serial" )
else ( )
find_package ( TBB )
if ( VPR_EXECUTION_ENGINE STREQUAL "auto" )
if ( TBB_FOUND )
set ( VPR_USE_EXECUTION_ENGINE "tbb" )
else ( )
set ( VPR_USE_EXECUTION_ENGINE "serial" )
endif ( )
elseif ( VPR_EXECUTION_ENGINE STREQUAL "tbb" )
if ( TBB_FOUND )
set ( VPR_USE_EXECUTION_ENGINE "tbb" )
else ( )
message ( FATAL_ERROR "VPR: TBB requested but not found (on debian/ubuntu try 'sudo apt install libtbb-dev'" )
endif ( )
endif ( )
endif ( )
#Configure the build to use the selected engine
if ( VPR_USE_EXECUTION_ENGINE STREQUAL "tbb" )
2020-07-04 18:31:34 -05:00
target_compile_definitions ( libvpr PRIVATE VPR_USE_TBB )
target_link_libraries ( libvpr tbb )
target_link_libraries ( libvpr tbbmalloc_proxy ) #Use the scalable memory allocator
2020-01-03 17:14:42 -06:00
message ( STATUS "VPR: will support parallel execution using '${VPR_USE_EXECUTION_ENGINE}'" )
elseif ( VPR_USE_EXECUTION_ENGINE STREQUAL "serial" )
message ( STATUS "VPR: will only support serial execution" )
else ( )
message ( FATAL_ERROR "VPR: Unrecognized execution engine '${VPR_USE_EXECUTION_ENGINE}'" )
endif ( )
#
# Signal handler configuration
#
if ( VPR_USE_SIGNAL_HANDLER )
#Check wheter VPR can use sigaction to handle signals (only supported by POSIX)
CHECK_CXX_SYMBOL_EXISTS ( sigaction csignal HAVE_SIGACTION )
if ( HAVE_SIGACTION )
2020-07-04 18:31:34 -05:00
target_compile_definitions ( libvpr PRIVATE VPR_USE_SIGACTION )
2020-01-03 17:14:42 -06:00
endif ( )
endif ( )
2020-07-04 18:31:34 -05:00
install ( TARGETS vpr libvpr DESTINATION bin )
2020-01-03 17:14:42 -06:00
#
# Unit Tests
#
file ( GLOB_RECURSE TEST_SOURCES test/*.cpp )
2020-07-04 18:31:34 -05:00
add_executable ( test_vpr ${ TEST_SOURCES } )
target_link_libraries ( test_vpr
2020-01-03 17:14:42 -06:00
l i b c a t c h
2020-07-04 18:31:34 -05:00
l i b v p r )
2020-01-03 17:14:42 -06:00
#Supress IPO link warnings if IPO is enabled
2020-07-04 18:31:34 -05:00
get_target_property ( TEST_VPR_USES_IPO vpr INTERPROCEDURAL_OPTIMIZATION )
2020-01-03 17:14:42 -06:00
if ( TEST_VPR_USES_IPO )
2020-07-04 18:31:34 -05:00
set_target_properties ( test_vpr PROPERTIES LINK_FLAGS ${ IPO_LINK_WARN_SUPRESS_FLAGS } )
2020-01-03 17:14:42 -06:00
endif ( )
2020-07-04 18:31:34 -05:00
add_test ( NAME test_vpr
2020-01-03 17:14:42 -06:00
C O M M A N D t e s t _ v p r - - u s e - c o l o u r = y e s
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 } / t e s t
)