File size: 11,741 Bytes
f61bac1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | # SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2019-2025, The OpenROAD Authors
cmake_minimum_required (VERSION 3.16)
# Use standard target names
cmake_policy(SET CMP0078 NEW)
# Allows SWIG_MODULE_NAME to be set
cmake_policy(SET CMP0086 NEW)
# CMP0074: Allows find_package to use <PackageName>_ROOT variables. This
# policy was the original mechanism for letting users specify custom
# dependency locations.
cmake_policy(SET CMP0074 NEW)
# CMP0144: Standardizes the use of <PACKAGENAME>_ROOT (uppercase) variables
# in find_package. Newer CMake modules rely on this policy for consistent
# behavior. Setting both CMP0074 and CMP0144 ensures that both older and
# newer find modules correctly respect custom dependency paths, which is
# critical for builds in non-standard environments.
cmake_policy(SET CMP0144 NEW)
# Allow AUTOUIC on generated source
cmake_policy(SET CMP0071 NEW)
# option() behavior
cmake_policy(SET CMP0077 NEW)
# Let AUTOMOC and AUTOUIC process GENERATED files.
cmake_policy(SET CMP0071 NEW)
# Allow to use external shared boost libraries
option(USE_SYSTEM_BOOST "Use system shared Boost libraries" OFF)
# Allow to use external shared opensta libraries
option(USE_SYSTEM_OPENSTA "Use system shared OpenSTA library" OFF)
# Allow to use external shared abc libraries
option(USE_SYSTEM_ABC "Use system shared ABC library" OFF)
# Allow disabling tests
option(ENABLE_TESTS "Enable OpenROAD tests" ON)
# Opt-in GPU acceleration via Kokkos. The actual compute backend (CUDA, HIP,
# SYCL, or host-only OpenMP/Threads) is determined by the installed Kokkos
# package; OpenROAD inspects Kokkos_ENABLE_* and turns on the matching CMake
# language and dependencies automatically. See the per-module CMakeLists for
# how individual subsystems wire their GPU sources.
option(ENABLE_GPU "Enable GPU acceleration via Kokkos" OFF)
# Allow enabling address sanitizer
option(ASAN "Enable Address Sanitizer" OFF)
# Allow enabling address sanitizer
# On Ubuntu22.04 you need to use "sudo sysctl vm.mmap_rnd_bits=28" to
# resolve a known fatal
option(TSAN "Enable Thread Sanitizer" OFF)
# Allow enabling address sanitizer
option(UBSAN "Enable Undefined Behavior Sanitizer" OFF)
project(OpenROAD VERSION 1
LANGUAGES C CXX
)
set(OPENROAD_HOME ${PROJECT_SOURCE_DIR})
set(OPENROAD_SHARE ${CMAKE_INSTALL_PREFIX}/share/openroad)
# Default c++ standard used unless otherwise specified in target_compile_features.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Disable compiler specific extensions like gnu++11.
set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Defer GoogleTest case discovery from build time (POST_BUILD default, which
# execs each test binary during the build) to ctest time. On a loaded CI host
# the build-time discovery run can exceed the timeout and fail the whole build.
set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE PRE_TEST)
# Get version string in OPENROAD_VERSION
if(NOT OPENROAD_VERSION)
include(GetGitRevisionDescription)
git_describe(OPENROAD_VERSION --tags --match "[0-9][0-9]Q[0-9]")
string(FIND ${OPENROAD_VERSION} "NOTFOUND" GIT_DESCRIBE_NOTFOUND)
if(${GIT_DESCRIBE_NOTFOUND} GREATER -1)
message(WARNING "OpenROAD git describe failed, using sha1 instead")
get_git_head_revision(GIT_REFSPEC OPENROAD_VERSION)
endif()
endif()
message(STATUS "OpenROAD version: ${OPENROAD_VERSION}")
# Default to bulding optimnized/release executable.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
endif()
# GPU backend wiring (opt-in). All Kokkos / CUDA / HIP / SYCL detection,
# compiler probing, and language enablement live in cmake/KokkosBackend.cmake
# and are loaded only when the user opts in via ENABLE_GPU=ON.
if(ENABLE_GPU)
include(KokkosBackend)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.3.0")
message(FATAL_ERROR "Insufficient gcc version. Found ${CMAKE_CXX_COMPILER_VERSION}, but require >= 8.3.0.")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0.0")
message(FATAL_ERROR "Insufficient Clang version. Found ${CMAKE_CXX_COMPILER_VERSION}, but require >= 7.0.0.")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0.0")
message(FATAL_ERROR "Insufficient AppleClang version. Found ${CMAKE_CXX_COMPILER_VERSION}, but require >= 12.0.0.")
endif()
else()
message(WARNING "Compiler ${CMAKE_CXX_COMPILER_ID} is not officially supported.")
endif()
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "C++ Standard Required: ${CMAKE_CXX_STANDARD_REQUIRED}")
message(STATUS "C++ Extensions: ${CMAKE_CXX_EXTENSIONS}")
# Detect OS distribution and version from /etc/os-release
# LTO is known to cause build errors on Rocky Linux 8
set(LTO_UNSUPPORTED_OS FALSE)
if(EXISTS "/etc/os-release")
file(STRINGS "/etc/os-release" OS_RELEASE_CONTENTS)
set(OS_ID "")
set(OS_VERSION_ID "")
foreach(line ${OS_RELEASE_CONTENTS})
if(line MATCHES "^ID=(.*)$")
string(REGEX REPLACE "^ID=\"?([^\"]*)\"?$" "\\1" OS_ID "${line}")
endif()
if(line MATCHES "^VERSION_ID=(.*)$")
string(REGEX REPLACE "^VERSION_ID=\"?([^\"]*)\"?$" "\\1" OS_VERSION_ID "${line}")
endif()
endforeach()
# Check for unsupported OS for LTO
if(OS_ID STREQUAL "rocky" AND OS_VERSION_ID MATCHES "^8")
set(LTO_UNSUPPORTED_OS TRUE)
message(STATUS "Detected unsupported OS (${OS_ID} ${OS_VERSION_ID}): LTO will be disabled due to known build issues")
# Rocky 8 ships gcc 8 in /usr/lib64/libstdc++.so.6. gcc-toolset-13's
# `-lstdc++` resolves through a linker script that pulls
# libstdc++_nonshared.a (fill-in for <filesystem> etc.). When that
# archive's TUs (e.g. fs_path80.o) are pulled into a link with many
# OpenROAD .a/.so inputs, the order/visibility of the system
# libstdc++.so.6 ends up such that ld can't resolve internal helpers
# like basic_string::resize and _Sp_counted_*. Statically link
# libstdc++/libgcc to sidestep the fill-in archive entirely.
add_link_options(-static-libstdc++ -static-libgcc)
message(STATUS "Rocky 8: enabling -static-libstdc++ -static-libgcc to avoid libstdc++_nonshared.a link errors")
endif()
endif()
option(LINK_TIME_OPTIMIZATION "Flag to control link time optimization: on by default" ON)
set(LTO_STATUS "disabled")
if (LINK_TIME_OPTIMIZATION AND NOT LTO_UNSUPPORTED_OS)
include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported OUTPUT lto_error)
if(lto_supported)
# LTO is enabled globally for Release build
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO FALSE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE)
string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE)
if(UPPER_BUILD_TYPE STREQUAL "RELEASE")
set(LTO_STATUS "enabled")
endif()
else()
set(LTO_STATUS "not supported: ${lto_error}")
endif()
endif()
message(STATUS "LTO/IPO is ${LTO_STATUS}")
# Compress DWARF debug sections in builds that emit debug info. This is a
# large on-disk win for template-heavy C++ (debug info dominates these
# binaries) and is transparent to gdb/readelf/addr2line/lldb. It is a no-op
# for builds without -g (e.g. Release), so it is safe to apply globally.
# Excluded on Apple platforms: Mach-O does not support -gz=zlib and AppleClang
# (which CMAKE_CXX_COMPILER_ID matches as "Clang") would fail the build.
# The compile flag is scoped to C/C++: -gz is a GCC/Clang host-compiler flag
# that nvcc does not accept (it would need explicit -Xcompiler forwarding), so
# applying it directory-wide would break CUDA (ENABLE_GPU) debug builds where
# gpl marks GPU sources as LANGUAGE CUDA. The link flag needs no such guard:
# linking is driven by the host C++ compiler.
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
AND NOT APPLE)
set(DEBUG_CONFIG_GENEX "$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>")
add_compile_options(
"$<$<AND:${DEBUG_CONFIG_GENEX},$<COMPILE_LANGUAGE:CXX,C>>:-gz=zlib>")
add_link_options("$<${DEBUG_CONFIG_GENEX}:-gz=zlib>")
endif()
# configure a header file to pass some of the CMake settings
configure_file(
${OPENROAD_HOME}/include/ord/Version.hh.cmake
${OPENROAD_HOME}/include/ord/Version.hh
)
################################################################
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.1")
MESSAGE(STATUS "Older version of GCC detected. Linking against stdc++fs")
link_libraries(stdc++fs)
endif()
# Ask CMake to output a compile_commands.json file for use with things like clang-tidy
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
add_subdirectory(third-party)
if(ENABLE_TESTS)
find_program (BASH_PROGRAM bash REQUIRED)
enable_testing()
add_custom_target(build_and_test ${CMAKE_CTEST_COMMAND} --parallel --output-on-failure -LE IntegrationTest)
include(GoogleTest)
endif()
add_subdirectory(src)
add_subdirectory(test)
# Not currently used but may become useful again with Kokkos
target_compile_definitions(openroad PRIVATE GPU)
if(BUILD_PYTHON)
target_compile_definitions(openroad PRIVATE BUILD_PYTHON=1)
else()
target_compile_definitions(openroad PRIVATE BUILD_PYTHON=0)
endif()
if(BUILD_GUI)
target_compile_definitions(openroad PRIVATE BUILD_GUI=1)
else()
target_compile_definitions(openroad PRIVATE BUILD_GUI=0)
endif()
####################################################################
# Build man pages (Optional)
option(BUILD_MAN "Enable building man pages" OFF)
if(BUILD_MAN)
message(STATUS "man is enabled")
# Use the processor_count command to get the number of cores
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
message(STATUS "Number of processor cores: ${PROCESSOR_COUNT}")
add_custom_target(
man_page ALL
COMMAND make clean && make preprocess && make all -j${PROCESSOR_COUNT}
WORKING_DIRECTORY ${OPENROAD_HOME}/docs
)
# Based on ${CMAKE_INSTALL_PREFIX}, we want to go to ${CMAKE_INSTALL_PREFIX}/share/man
install(DIRECTORY ${OPENROAD_HOME}/docs/cat DESTINATION ${OPENROAD_SHARE}/man)
install(DIRECTORY ${OPENROAD_HOME}/docs/html DESTINATION ${OPENROAD_SHARE}/man)
endif()
####################################################################
# Add a configuration for ReleaseWithAsserts
set(CMAKE_CXX_FLAGS_RELEASEWITHASSERTS "${CMAKE_CXX_FLAGS_RELEASE} -UNDEBUG" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASEWITHASSERTS "${CMAKE_C_FLAGS_RELEASE} -UNDEBUG" CACHE STRING "" FORCE)
# ==============================================================================
# OPENROAD BUILD CONFIGURATION SUMMARY
# ==============================================================================
message(STATUS "")
message(STATUS "=========================================================")
message(STATUS " OpenROAD Configuration Summary ")
message(STATUS "=========================================================")
message(STATUS " C++ Standard : ${CMAKE_CXX_STANDARD}")
message(STATUS " Build Type : ${CMAKE_BUILD_TYPE}")
message(STATUS " GUI Support : ${BUILD_GUI}")
message(STATUS " Python Bindings: ${BUILD_PYTHON}")
message(STATUS " Tests Enabled : ${ENABLE_TESTS}")
message(STATUS "=========================================================")
message(STATUS " Configuration complete.")
message(STATUS "")
|