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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2019-2025, The OpenROAD Authors

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/src/cmake")

# The location used by etc/DependencyInstaller.sh
list(APPEND CMAKE_PREFIX_PATH
  "/opt/or-tools/lib64/cmake"
  "/opt/or-tools/lib/cmake"
)

# Link to where ortools was found
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

include("openroad")


if(USE_SYSTEM_OPENSTA)
  if(NOT OPENSTA_HOME)
    message(FATAL_ERROR "Please set external OPENSTA_HOME path.")
  endif()
else()
  set(OPENSTA_HOME ${PROJECT_SOURCE_DIR}/src/sta)
endif()

set(ODB_HOME ${PROJECT_SOURCE_DIR}/src/odb)
set(DBSTA_HOME ${PROJECT_SOURCE_DIR}/src/dbSta)
set(RESIZER_HOME ${PROJECT_SOURCE_DIR}/src/rsz)
set(GUI_HOME ${PROJECT_SOURCE_DIR}/src/gui)

set(OPENROAD_SOURCE
  Design.cc
  Timing.cc
  Tech.cc
  tcl_readline_setup.cc
  OpenRoad.cc
  Main.cc
  )

if(USE_SYSTEM_BOOST)
  set(Boost_USE_STATIC_LIBS OFF)
else()
  set(Boost_USE_STATIC_LIBS ON)
endif()

if(USE_SYSTEM_OPENSTA)
  find_package(CUDD REQUIRED)

  if(NOT OPENSTA_LIBRARY)
    find_library(OPENSTA_LIBRARY NAMES OpenSTA
                 PATHS
                 /usr/lib
                 /usr/lib64
                 /usr/local/lib
                 /usr/local/lib64)
    if(OPENSTA_LIBRARY)
      message(STATUS "Found OpenSTA: ${OPENSTA_LIBRARY}")
    else()
      message(FATAL_ERROR "OpenSTA not found, set the OPENSTA_LIBRARY manually.")
    endif()
  endif()
  if(NOT OPENSTA_INCLUDE_DIR)
    set(OPENSTA_INCLUDE_DIR "/usr/include/sta")
  endif()
  include_directories(${OPENSTA_INCLUDE_DIR})
  message(STATUS "Using OPENSTA_INCLUDE_DIR=${OPENSTA_INCLUDE_DIR}")
  add_library(OpenSTA STATIC IMPORTED)
  set_target_properties(OpenSTA PROPERTIES
    IMPORTED_LOCATION "${OPENSTA_LIBRARY}"
    INTERFACE_INCLUDE_DIRECTORIES "${OPENSTA_INCLUDE_DIR}"
    INTERFACE_LINK_LIBRARIES CUDD::CUDD
  )
else()
  # local build of opensta
  set(OPENSTA_LIBRARY "sta_swig")
endif()

if(USE_SYSTEM_ABC)
  if(NOT ABC_LIBRARY)
    find_library(ABC_LIBRARY NAMES abc
                 PATHS
                 /usr/lib
                 /usr/lib64
                 /usr/local/lib
                 /usr/local/lib64)
    if(ABC_LIBRARY)
      message(STATUS "Found ABC: ${ABC_LIBRARY}")
      # make sure link dl symbols
      list(APPEND ABC_LIBRARY "dl")
    else()
      message(FATAL_ERROR "ABC not found, set the ABC_LIBRARY manually.")
    endif()
  endif()
  if(NOT ABC_INCLUDE_DIR)
    set(ABC_INCLUDE_DIR "/usr/include/abc")
  endif()
  add_definitions(-DABC_USE_STDINT_H=1)
  include_directories(${ABC_INCLUDE_DIR})
  message(STATUS "Using ABC_INCLUDE_DIR=${ABC_INCLUDE_DIR}")
else()
  # local build of abc
  set(ABC_LIBRARY "libabc")
endif()

################################################################

# OSX tcl is deprecated and prints a warning, so look for a user installed
# version before using the system version.
# I tried to override the library search order instead but failed.
# CMAKE_FIND_FRAMEWORK LAST bypasses the version in the framework directory
# but not the one in /usr/lib.
# This calls cmake/FindTCL.cmake
# Do not use REQUIRED because it also requires TK.
find_package(TCL)

option(BUILD_TCLX "Build with tclX included" ON)
if (BUILD_TCLX AND TCLX_LIBRARY)
  message(STATUS "TclX library: ${TCLX_LIBRARY}")
endif()
if (BUILD_TCLX AND TCLX_H)
  message(STATUS "TclX header: ${TCLX_H}")
endif()

find_package(SWIG 4.3 REQUIRED)
include(UseSWIG)

find_package(Boost CONFIG REQUIRED)
message(STATUS "boost: ${Boost_VERSION}")

find_package(absl REQUIRED)
message(STATUS "absl: ${absl_VERSION}")

if (ENABLE_TESTS)
  find_package(GTest REQUIRED)
  message(STATUS "GTest: ${GTest_VERSION}")
endif()

find_package(Python3 COMPONENTS Development REQUIRED)
option(BUILD_PYTHON "Build the Python3 interface" ON)

option(ALLOW_WARNINGS "Flag to allow compilation with compiler warnings: on by default" ON)
if (NOT ALLOW_WARNINGS)
  add_compile_options(
    $<$<CXX_COMPILER_ID:GNU>:-Werror>
  )
endif()

add_compile_options(
  -Wall
  -Wmissing-field-initializers
  -Wredundant-decls
  -Wformat-security
  -Wno-sign-compare
  -D_GLIBCXX_ASSERTIONS
  $<$<CXX_COMPILER_ID:Clang>:-Wno-gnu-zero-variadic-macro-arguments>
  # Needed for floating point stability in FFT (fft_test will check this).
  # See also https://kristerw.github.io/2021/11/09/fp-contract/
  -ffp-contract=off
  # Apple clang 14.0.0 deprecates sprintf, which generates 900 warnings.
  $<$<CXX_COMPILER_ID:AppleClang>:-Wno-deprecated-declarations>
  $<$<CXX_COMPILER_ID:AppleClang>:-Wmismatched-tags>
  $<$<BOOL:${ASAN}>:-fsanitize=address>
  $<$<BOOL:${ASAN}>:-fno-omit-frame-pointer>
  $<$<BOOL:${ASAN}>:-g>
  $<$<BOOL:${TSAN}>:-fsanitize=thread>
  $<$<BOOL:${TSAN}>:-g>
  $<$<BOOL:${UBSAN}>:-fsanitize=undefined>
  $<$<BOOL:${UBSAN}>:-g>
  $<$<BOOL:${UBSAN}>:-fno-omit-frame-pointer>
)

if (ASAN)
  add_link_options(-fsanitize=address)
  message(STATUS "Address Sanitizer is enabled")
endif()

if (TSAN)
  add_link_options(-fsanitize=thread)
  message(STATUS "Thread Sanitizer is enabled")
endif()

if (UBSAN)
  add_link_options(-fsanitize=undefined)
  message(STATUS "Undefined Behavior Sanitizer is enabled")
endif()

################################################################

swig_lib(NAME      ord
         NAMESPACE ord
         I_FILE    OpenRoad.i
         SCRIPTS   ${OPENSTA_HOME}/tcl/Util.tcl
                   OpenRoad.tcl
                   Metrics.tcl
)

target_link_libraries(ord
  PRIVATE
    dbSta
    odb
    OpenSTA
)

################################################################
#
# Library dependencies
#
################################################################

# Zlib
include(FindZLIB)
# Translate cmake bool to StaConfig.h ifdef bool
if (ZLIB_FOUND)
  set(ZLIB 1)
else()
  set(ZLIB 0)
endif()

find_package(spdlog REQUIRED)
message(STATUS "spdlog: ${spdlog_VERSION}")
if (${SPDLOG_FMT_EXTERNAL})
  message(WARNING "spdlog: SPDLOG_FMT_EXTERNAL=${SPDLOG_FMT_EXTERNAL}")
endif()

find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)

################################################################

# Shared Tcl TAB completion engine — used by the web Tcl console and
# (later) by the CLI linenoise REPL.
add_library(cli_completer STATIC
  cli_completer.cc
)
target_include_directories(cli_completer
  PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
  PRIVATE ${TCL_INCLUDE_PATH}
)
target_link_libraries(cli_completer PUBLIC ${TCL_LIBRARY})
target_compile_features(cli_completer PUBLIC cxx_std_20)

################################################################

# Build flow tools
add_subdirectory(ifp)
add_subdirectory(pad)
add_subdirectory(odb)
if (NOT USE_SYSTEM_OPENSTA)
  # OpenROAD drives its interactive line editing via the linenoise-backed
  # ::tclreadline shim in src/tcl_readline_setup.cc.  We do not want
  # OpenSTA's standalone `sta` binary to pull in GNU readline / tclreadline.
  set(USE_TCL_READLINE OFF)
  set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
  add_subdirectory(sta)
endif()
add_subdirectory(dbSta)
add_subdirectory(rsz)
if(ENABLE_TESTS)
  # tst provides gtest-based fixture libraries used only by test targets, and
  # links GTest::gtest, which only exists when ENABLE_TESTS is on.
  add_subdirectory(tst)
endif()
add_subdirectory(stt)
add_subdirectory(gpl)
add_subdirectory(dpl)
add_subdirectory(exa)
add_subdirectory(fin)
add_subdirectory(ram)
add_subdirectory(ppl)
add_subdirectory(rmp)
add_subdirectory(cgt)
add_subdirectory(cts)
add_subdirectory(cut)
add_subdirectory(grt)
add_subdirectory(tap)
add_subdirectory(rcx)
add_subdirectory(psm)
add_subdirectory(ant)
add_subdirectory(gui)
add_subdirectory(drt)
add_subdirectory(upf)
add_subdirectory(utl)
add_subdirectory(dst)
add_subdirectory(pdn)
add_subdirectory(dft)
add_subdirectory(mpl)
add_subdirectory(par)
add_subdirectory(est)
add_subdirectory(syn)
add_subdirectory(web)

################################################################

add_executable(openroad
  ${OPENROAD_SOURCE}
)

set_target_properties(openroad PROPERTIES
  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

target_compile_options(openroad
  PRIVATE
    -Wextra -pedantic -Wcast-qual
)

# Needed for boost stacktrace
if(APPLE)
  target_compile_definitions(openroad PUBLIC "-D_GNU_SOURCE")
endif()


set_target_properties(openroad PROPERTIES
  # Disable compiler specific extensions like gnu++11.
  CXX_EXTENSIONS OFF
  # Export symbols for stack trace printing
  ENABLE_EXPORTS ON
)
target_compile_features(openroad PUBLIC cxx_std_20)

target_include_directories(openroad
  PUBLIC
    ../include
)

target_link_libraries(openroad
  ifp
  pad
  ord
  gpl
  dpl
  exa
  fin
  ram
  rsz
  ppl
  stt
  dbSta
  OpenSTA
  odb
  odbtcl
  rcx
  rmp
  cgt
  cts
  cut
  grt
  tap
  drt
  dst
  psm
  ant
  upf
  utl
  pdn
  dft
  mpl
  par
  est
  syn
  web
  gui
  cli_completer
  linenoise
  absl::synchronization
  ${ABC_LIBRARY}
  ${TCL_LIBRARY}
  ${CMAKE_THREAD_LIBS_INIT}
  ${Boost_LIBRARIES}
)

target_compile_definitions(openroad PRIVATE BUILD_TYPE="${CMAKE_BUILD_TYPE}")

if (BUILD_TCLX AND TCLX_LIBRARY AND TCLX_H)
  target_compile_definitions(openroad PRIVATE ENABLE_TCLX)
  target_link_libraries(openroad ${TCLX_LIBRARY})
  target_include_directories(openroad PRIVATE ${TCLX_H})
  message(STATUS "Tcl Extended enabled")
else()
  message(STATUS "Tcl Extended disabled")
endif()

if (ZLIB_FOUND)
  target_link_libraries(openroad ${ZLIB_LIBRARIES})
endif()

# Optional CUDD library for OpenSTA
if (TARGET CUDD::CUDD)
  target_link_libraries(openroad CUDD::CUDD)
elseif (CUDD_LIB)
  target_link_libraries(openroad ${CUDD_LIB})
endif()

if (Python3_FOUND AND BUILD_PYTHON)
  message(STATUS "Python3 enabled")
  target_compile_definitions(openroad PRIVATE ENABLE_PYTHON3)

  swig_lib(NAME      ord_py
           NAMESPACE ord
           LANGUAGE  python
           I_FILE    OpenRoad-py.i
           SCRIPTS   ${CMAKE_CURRENT_BINARY_DIR}/ord_py.py
  )

  target_link_libraries(ord_py
    PRIVATE
      dbSta
      odb
      OpenSTA
      ifp
  )
  set(OPENROAD_PYTHON_MODULES
      ord_py
      odb_py
      ifp_py
      utl_py
      ant_py
      grt_py
      gpl_py
      dpl_py
      exa_py
      ppl_py
      tap_py
      cgt_py
      cts_py
      drt_py
      fin_py
#      ram_py
      rcx_py
      rmp_py
      stt_py
      psm_py
      pdn_py
      rsz_py
      syn_py
      dft_py
      par_py
      web_py
  )
  target_link_libraries(openroad ${OPENROAD_PYTHON_MODULES})

else()
  message(STATUS "Python3 disabled")
endif()

messages(
  TARGET openroad
  SOURCE_DIR .
  OUTPUT_DIR ..
  LOCAL
)

# Ancient versions of glibc found on CentOS required librt.
# OSX has an empty version of librt that causes a link error,
# so this is protected from linking there.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
    AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
  find_library(LIBRT rt)
  target_link_libraries(openroad ${LIBRT})
endif()

################################################################
# Install
# cmake .. -DCMAKE_INSTALL_PREFIX=<prefix_path>

# executable
install(TARGETS openroad DESTINATION bin)

################################################################

add_custom_target(openroad_tags etags -o TAGS
  ${OPENROAD_SOURCE}
  ${OPENROAD_HOME}/include/ord/*.hh
  ${OPENROAD_HOME}/src/dbSta/src/*.hh
  ${DBSTA_HOME}/include/db_sta/*.hh
  ${OPENROAD_HOME}/src/dbSta/src/*.cc
  ${RESIZER_HOME}/src/*.hh
  ${RESIZER_HOME}/src/*.cc
  WORKING_DIRECTORY ${OPENROAD_HOME}/src
  DEPENDS ${OPENROAD_SOURCE} ${OPENROAD_HEADERS} ${OPENROAD_TCL_FILES}
)