2022-12-21 00:42:27 +00:00
#*****************************************************************************
#
# DESCRIPTION: Script for build tool cmake on both unix and windows
#
#*****************************************************************************
#
2024-01-01 08:19:59 +00:00
# Copyright 2003-2024 by Wilson Snyder. This program is free software; you
2022-12-21 00:42:27 +00:00
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
#
#****************************************************************************/
cmake_minimum_required ( VERSION 3.15 )
cmake_policy ( SET CMP0091 NEW ) # Use MSVC_RUNTIME_LIBRARY to select the runtime
project ( Verilator
2024-06-15 12:49:57 +00:00
V E R S I O N 5 . 0 2 7
2022-12-21 00:42:27 +00:00
H O M E P A G E _ U R L h t t p s : / / v e r i l a t o r . o r g
L A N G U A G E S C X X
)
option ( DEBUG_AND_RELEASE_AND_COVERAGE
" B u i l d s b o t h t h e d e b u g a n d r e l e a s e b i n a r i e s , o v e r r i d i n g C M A K E _ B U I L D _ T Y P E . N o t s u p p o r t e d u n d e r M S B u i l d . " )
2023-03-18 11:38:09 +00:00
find_package ( Python3 COMPONENTS Interpreter )
2024-06-19 12:07:17 +00:00
set ( PYTHON3 ${ Python3_EXECUTABLE } )
2022-12-21 00:42:27 +00:00
set ( CMAKE_INSTALL_DATADIR ${ CMAKE_INSTALL_PREFIX } )
include ( GNUInstallDirs )
include ( CMakePackageConfigHelpers )
include ( CheckStructHasMember )
include ( ExternalProject )
if ( NOT WIN32 )
message ( WARNING "CMake support on Linux/OSX is experimental." )
endif ( )
2023-11-08 11:27:56 +00:00
if ( WIN32 )
2022-12-21 00:42:27 +00:00
if ( DEFINED ENV{WIN_FLEX_BISON} )
set ( WIN_FLEX_BISON "$ENV{WIN_FLEX_BISON}" )
endif ( )
if ( EXISTS ${ WIN_FLEX_BISON } )
list ( APPEND CMAKE_PREFIX_PATH ${ WIN_FLEX_BISON } )
endif ( )
if ( NOT WIN_FLEX_BISON )
message ( FATAL_ERROR "Please install https://github.com/lexxmark/winflexbison and set WIN_FLEX_BISON environment variable. Please use install cmake target after a successful build." )
endif ( )
2023-03-18 11:38:09 +00:00
set ( CMAKE_CXX_STANDARD 20 )
2022-12-21 00:42:27 +00:00
endif ( )
2023-11-10 02:05:36 +00:00
set ( OBJCACHE "" CACHE STRING "Path for ccache, auto-detected if empty" )
option ( OBJCACHE_ENABLED "Compile Verilator with ccache" ON )
if ( OBJCACHE_ENABLED )
if ( OBJCACHE STREQUAL "" )
find_program ( OBJCACHE_PATH ccache )
if ( OBJCACHE_PATH STREQUAL "OBJCACHE_PATH-NOTFOUND" )
set ( OBJCACHE_PATH "" )
endif ( )
else ( )
set ( OBJCACHE_PATH "${OBJCACHE}" )
endif ( )
if ( NOT OBJCACHE_PATH STREQUAL "" )
execute_process ( COMMAND "${OBJCACHE_PATH}" --version
O U T P U T _ V A R I A B L E o b j c a c h e _ v e r s i o n )
string ( REGEX MATCH "[^\n\r]+" objcache_version "${objcache_version}" )
message ( STATUS "Found ccache: ${OBJCACHE_PATH} (\" ${ objcache_version } \")")
set ( CMAKE_CXX_COMPILER_LAUNCHER "${OBJCACHE_PATH}" )
endif ( )
endif ( )
2022-12-21 00:42:27 +00:00
find_package ( BISON )
find_package ( FLEX )
# Build
#set_property(GLOBAL PROPERTY JOB_POOLS one_job=1)
if ( DEBUG_AND_RELEASE_AND_COVERAGE )
if ( CMAKE_GENERATOR MATCHES "^Visual Studio " )
error ( "%Error: The DEBUG_AND_RELEASE_AND_COVERAGE option is not supported in MSBuild-based builds." )
endif ( )
set ( saved_build_type ${ CMAKE_BUILD_TYPE } )
set ( CMAKE_BUILD_TYPE Debug )
add_subdirectory ( src build-Debug )
set ( CMAKE_BUILD_TYPE Release )
add_subdirectory ( src build-Release )
set ( CMAKE_BUILD_TYPE Coverage )
add_subdirectory ( src build-Coverage )
set ( CMAKE_BUILD_TYPE ${ saved_build_type } )
else ( )
add_subdirectory ( src )
endif ( )
# Configuration and Installation
set ( PACKAGE_NAME ${ PROJECT_NAME } )
set ( PACKAGE_VERSION ${ PROJECT_VERSION } )
2024-06-19 12:07:17 +00:00
set ( CXX ${ CMAKE_CXX_COMPILER } )
set ( AR ${ CMAKE_AR } )
2022-12-21 00:42:27 +00:00
configure_file ( include/verilated_config.h.in include/verilated_config.h @ONLY )
2024-06-19 12:07:17 +00:00
configure_file ( include/verilated.mk.in include/verilated.mk @ONLY )
2022-12-21 00:42:27 +00:00
install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /include/verilated_config.h DESTINATION ${ CMAKE_INSTALL_PREFIX } /include )
2024-06-19 12:07:17 +00:00
install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /include/verilated.mk DESTINATION ${ CMAKE_INSTALL_PREFIX } /include )
2022-12-21 00:42:27 +00:00
configure_package_config_file ( verilator-config.cmake.in verilator-config.cmake
I N S T A L L _ D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ P R E F I X }
)
install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /verilator-config.cmake DESTINATION ${ CMAKE_INSTALL_PREFIX } )
configure_package_config_file ( verilator-config-version.cmake.in verilator-config-version.cmake
I N S T A L L _ D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ P R E F I X }
)
install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /verilator-config-version.cmake DESTINATION ${ CMAKE_INSTALL_PREFIX } )
foreach ( program
2023-03-18 11:38:09 +00:00
v e r i l a t o r
2022-12-21 00:42:27 +00:00
v e r i l a t o r _ g a n t t
v e r i l a t o r _ c c a c h e _ r e p o r t
v e r i l a t o r _ d i f f t r e e
v e r i l a t o r _ p r o f c f u n c
2024-06-19 12:07:17 +00:00
v e r i l a t o r _ i n c l u d e r
2022-12-21 00:42:27 +00:00
)
install ( PROGRAMS bin/ ${ program } TYPE BIN )
endforeach ( )
install ( DIRECTORY examples TYPE DATA FILES_MATCHING
P A T T E R N " e x a m p l e s / * / * . [ c h v ] * "
P A T T E R N " e x a m p l e s / * / M a k e f i l e * "
P A T T E R N " e x a m p l e s / * / C M a k e L i s t s . t x t "
)
install ( DIRECTORY include TYPE DATA FILES_MATCHING
P A T T E R N " i n c l u d e / v e r i l a t e d _ c o n f i g . h "
P A T T E R N " i n c l u d e / * . [ c h v ] "
P A T T E R N " i n c l u d e / * . c p p "
2023-02-04 13:19:49 +00:00
P A T T E R N " i n c l u d e / * . s v "
2022-12-21 00:42:27 +00:00
P A T T E R N " i n c l u d e / g t k w a v e / * . [ c h v ] * "
P A T T E R N " i n c l u d e / v l t s t d / * . [ c h v ] * "
)