Skip to content

Commit b6e5bf1

Browse files
committed
CMake: Rebase From Main & Tests Working
1 parent c87bf56 commit b6e5bf1

File tree

9 files changed

+294
-48
lines changed

9 files changed

+294
-48
lines changed

CMakeLists.txt

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,158 @@ if (ENABLE_ZLIB)
283283
endif()
284284

285285
set_property(SOURCE kernel/log.cc APPEND PROPERTY COMPILE_DEFINITIONS YOSYS_SRC="${PROJECT_SOURCE_DIR}")
286+
287+
#### yosys-config setup ####
288+
# compiler
289+
get_filename_component(_CXX_BASENAME "${CMAKE_CXX_COMPILER}" NAME)
290+
set(YOSYS_CFG_CXX "${_CXX_BASENAME}"
291+
CACHE STRING "C++ compiler that appears in yosys-config")
292+
293+
# compile flags
294+
set(_CFG_CXXFLAGS
295+
-Wall -Wextra -ggdb
296+
"-I\"${CMAKE_INSTALL_PREFIX}/share/yosys/include\""
297+
-MD -MP -D_YOSYS_ -fPIC
298+
-I${CMAKE_INSTALL_PREFIX}/include
299+
-std=c++${CXXSTD} -O3)
300+
301+
if (ENABLE_READLINE)
302+
list(APPEND _CFG_CXXFLAGS -DYOSYS_ENABLE_READLINE)
303+
endif()
304+
if (ENABLE_PLUGINS)
305+
list(APPEND _CFG_CXXFLAGS -DYOSYS_ENABLE_PLUGINS)
306+
endif()
307+
if (ENABLE_GLOB)
308+
list(APPEND _CFG_CXXFLAGS -DYOSYS_ENABLE_GLOB)
309+
endif()
310+
if (ENABLE_ZLIB)
311+
list(APPEND _CFG_CXXFLAGS -DYOSYS_ENABLE_ZLIB)
312+
endif()
313+
if (ENABLE_TCL)
314+
list(APPEND _CFG_CXXFLAGS -I${TCL_INCLUDE_PATH} -DYOSYS_ENABLE_TCL)
315+
endif()
316+
if (ENABLE_ABC)
317+
list(APPEND _CFG_CXXFLAGS -DYOSYS_ENABLE_ABC)
318+
endif()
319+
if (ENABLE_COVER)
320+
list(APPEND _CFG_CXXFLAGS -DYOSYS_ENABLE_COVER)
321+
endif()
322+
323+
string (REPLACE ";" " " YOSYS_CFG_CXXFLAGS "${_CFG_CXXFLAGS}")
324+
325+
# link flags
326+
set(YOSYS_CFG_LINKFLAGS "-rdynamic" CACHE STRING "link flags for yosys-config")
327+
328+
# libraries
329+
set(_CFG_LIBS -lstdc++ -lm)
330+
if (NOT (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD"))
331+
list(APPEND _CFG_LIBS -lrt)
332+
endif()
333+
if (ENABLE_READLINE)
334+
list(APPEND _CFG_LIBS -lreadline)
335+
endif()
336+
if (ENABLE_PLUGINS)
337+
list(APPEND _CFG_LIBS -lffi)
338+
if (NOT APPLE)
339+
list(APPEND _CFG_LIBS -ldl)
340+
endif()
341+
endif()
342+
if (ENABLE_ZLIB)
343+
list(APPEND _CFG_LIBS -lz)
344+
endif()
345+
if (ENABLE_TCL)
346+
get_filename_component(_TCL "${TCL_LIBRARY}" NAME_WE)
347+
string(REGEX REPLACE "^lib" "" _TCL "${_TCL}")
348+
list(APPEND _CFG_LIBS "-l${_TCL}")
349+
endif()
350+
string (REPLACE ";" " " YOSYS_CFG_LIBS "${_CFG_LIBS}")
351+
352+
# bindir / datadir (installation paths)
353+
set(YOSYS_CFG_PREFIX "/usr/local"
354+
CACHE STRING "prefix that yosys-config reports")
355+
356+
set(YOSYS_CFG_BINDIR "${YOSYS_CFG_PREFIX}/bin")
357+
set(YOSYS_CFG_DATDIR "${YOSYS_CFG_PREFIX}/share/yosys")
358+
359+
# abort if something is missing
360+
foreach(var YOSYS_CFG_CXX YOSYS_CFG_CXXFLAGS YOSYS_CFG_LINKFLAGS
361+
YOSYS_CFG_LIBS YOSYS_CFG_BINDIR YOSYS_CFG_DATDIR)
362+
if("${${var}}" STREQUAL "")
363+
message(FATAL_ERROR "${var} is empty – cannot create yosys-config")
364+
endif()
365+
endforeach()
366+
367+
set(CXX "${YOSYS_CFG_CXX}")
368+
set(CXXFLAGS "${YOSYS_CFG_CXXFLAGS}")
369+
set(LINKFLAGS "${YOSYS_CFG_LINKFLAGS}")
370+
set(LIBS "${YOSYS_CFG_LIBS}")
371+
set(BINDIR "${YOSYS_CFG_BINDIR}")
372+
set(DATDIR "${YOSYS_CFG_DATDIR}")
373+
374+
configure_file(misc/yosys-config.in ${CMAKE_BINARY_DIR}/yosys-config @ONLY)
375+
file(CHMOD ${CMAKE_BINARY_DIR}/yosys-config
376+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
377+
GROUP_READ GROUP_EXECUTE
378+
WORLD_READ WORLD_EXECUTE)
379+
380+
add_custom_target(yosys-config-copy ALL
381+
DEPENDS ${CMAKE_BINARY_DIR}/yosys-config)
382+
383+
#### INSTALL ####
384+
install(TARGETS yosys
385+
RUNTIME DESTINATION .)
386+
387+
if (ENABLE_ABC)
388+
install(PROGRAMS $<TARGET_FILE:abc>
389+
DESTINATION .
390+
RENAME yosys-abc)
391+
endif()
392+
393+
install(PROGRAMS ${CMAKE_BINARY_DIR}/yosys-config DESTINATION .)
394+
395+
#### TESTING ####
396+
include(cmake/TestFiles.cmake)
397+
enable_testing()
398+
399+
set(_YOSYS_TEST_ENV
400+
"PATH=${PROJECT_SOURCE_DIR}:$ENV{PATH};")
401+
402+
foreach(dir IN LISTS SH_TEST_DIRS)
403+
string(REPLACE "/" "_" name "${dir}")
404+
add_test(
405+
NAME seed-tests.${name}
406+
COMMAND bash -c
407+
"cd \"${PROJECT_SOURCE_DIR}/${dir}\" && bash run-test.sh ${SEEDOPT}"
408+
)
409+
set_tests_properties(seed-tests.${name} PROPERTIES
410+
ENVIRONMENT "${_YOSYS_TEST_ENV}"
411+
DEPENDS yosys)
412+
endforeach()
413+
414+
foreach(dir IN LISTS SH_ABC_TEST_DIRS)
415+
string(REPLACE "/" "_" name "${dir}")
416+
add_test(
417+
NAME abcopt-tests.${name}
418+
COMMAND bash -c
419+
"cd \"${PROJECT_SOURCE_DIR}/${dir}\" && bash run-test.sh ${ABCOPT} ${SEEDOPT}"
420+
)
421+
set_tests_properties(abcopt-tests.${name} PROPERTIES
422+
ENVIRONMENT "${_YOSYS_TEST_ENV}"
423+
DEPENDS yosys)
424+
endforeach()
425+
426+
foreach(dir IN LISTS MK_TEST_DIRS)
427+
string(REPLACE "/" "_" name "${dir}")
428+
add_test(
429+
NAME makefile-tests.${name}
430+
COMMAND bash -c
431+
"
432+
cd \"${PROJECT_SOURCE_DIR}/${dir}\" &&
433+
bash run-test.sh &&
434+
${CMAKE_MAKE_PROGRAM} -f run-test.mk
435+
"
436+
)
437+
set_tests_properties(makefile-tests.${name} PROPERTIES
438+
ENVIRONMENT "${_YOSYS_TEST_ENV}"
439+
DEPENDS yosys)
440+
endforeach()

build.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
# This script builds the project using CMake in a way that is compatible with
4+
# the existing Makefile build system.
5+
6+
# 1. Initialize the submodules
7+
git submodule update --init --recursive
8+
9+
# 2. Build the project
10+
mkdir -p build
11+
cmake -B build
12+
cmake --build build --parallel $(nproc)
13+
14+
# 3. Install the project into test install dir
15+
cmake --install build --prefix .
16+
17+
# 4. Test the project
18+
# ctest -j$(nproc) --test-dir build --output-on-failure
19+
# Or Rerun Failed Tests
20+
# ctest -j$(nproc) --test-dir build --rerun-failed --output-on-failure

cmake/TestFiles.cmake

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
set(MK_TEST_DIRS
2+
tests/arch/anlogic
3+
tests/arch/ecp5
4+
tests/arch/efinix
5+
tests/arch/gatemate
6+
tests/arch/gowin
7+
tests/arch/ice40
8+
tests/arch/intel_alm
9+
tests/arch/machxo2
10+
tests/arch/microchip
11+
tests/arch/nanoxplore
12+
tests/arch/nexus
13+
tests/arch/quicklogic/pp3
14+
tests/arch/quicklogic/qlf_k6n10f
15+
tests/arch/xilinx
16+
tests/opt
17+
tests/sat
18+
tests/sim
19+
tests/svtypes
20+
tests/techmap
21+
tests/various
22+
)
23+
if(ENABLE_VERIFIC AND NOT YOSYS_NOVERIFIC)
24+
list(APPEND MK_TEST_DIRS tests/verific)
25+
endif()
26+
list(APPEND MK_TEST_DIRS tests/verilog)
27+
28+
29+
set(SH_TEST_DIRS
30+
tests/simple
31+
tests/simple_abc9
32+
tests/hana
33+
tests/asicworld
34+
tests/share
35+
tests/opt_share
36+
tests/fsm
37+
tests/memlib
38+
tests/bram
39+
tests/svinterfaces
40+
tests/xprop
41+
tests/select
42+
tests/peepopt
43+
tests/proc
44+
tests/blif
45+
tests/arch
46+
tests/rpc
47+
tests/memfile
48+
tests/fmt
49+
tests/cxxrtl
50+
tests/liberty
51+
)
52+
if(ENABLE_FUNCTIONAL_TESTS)
53+
list(APPEND SH_TEST_DIRS tests/functional)
54+
endif()
55+
56+
57+
set(SH_ABC_TEST_DIRS
58+
tests/memories
59+
tests/aiger
60+
tests/alumacc
61+
)

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
yosys = pkgs.clangStdenv.mkDerivation {
1919
name = "yosys";
2020
src = ./. ;
21-
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 zlib git pkg-configUpstream llvmPackages.bintools ];
21+
buildInputs = with pkgs; [ clang bison flex libffi tcl tk readline python3 zlib git pkg-configUpstream llvmPackages.bintools ];
2222
checkInputs = with pkgs; [ gtest ];
2323
propagatedBuildInputs = [ abc-verifier ];
2424
preConfigure = "make config-clang";
@@ -41,7 +41,7 @@
4141
packages.default = yosys;
4242
defaultPackage = yosys;
4343
devShell = pkgs.mkShell {
44-
buildInputs = with pkgs; [ clang llvmPackages.bintools gcc bison flex libffi tcl readline python3 zlib git gtest abc-verifier verilog boost python3Packages.boost ];
44+
buildInputs = with pkgs; [ gtkwave cmake clang llvmPackages.bintools gcc bison flex libffi tcl tk readline python3 zlib git gtest abc-verifier verilog boost python3Packages.boost ];
4545
};
4646
}
4747
);

kernel/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ target_sources(yosys_kernel INTERFACE
4646
fmt.h
4747
functional.cc
4848
functional.h
49+
gzip.cc
50+
gzip.h
4951
hashlib.h
52+
io.cc
5053
json.cc
5154
json.h
5255
log.cc

passes/cmds/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ target_sources(yosys_passes_cmds INTERFACE
4949
portarcs.cc
5050
wrapcell.cc
5151
setenv.cc
52+
test_select.cc
53+
abstract.cc
5254
)
5355

5456
if (NOT DISABLE_SPAWN)

passes/pmgen/CMakeLists.txt

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,71 @@
11
add_library(yosys_passes_pmgen INTERFACE)
22

3-
function(pmgen_command _name)
3+
function(pmgen_command _name _path)
44
add_custom_command(
5-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}_pm.h
6-
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py -o ${CMAKE_CURRENT_BINARY_DIR}/${_name}_pm.h -p ${_name} ${CMAKE_CURRENT_SOURCE_DIR}/${_name}.pmg
7-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py ${CMAKE_CURRENT_SOURCE_DIR}/${_name}.pmg
8-
COMMENT "Generating passes/pmgen/${_name}_pm.h..."
5+
OUTPUT ${CMAKE_BINARY_DIR}/${_path}/${_name}_pm.h
6+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py -o ${CMAKE_BINARY_DIR}/${_path}/${_name}_pm.h -p ${_name} ${CMAKE_SOURCE_DIR}/${_path}/${_name}.pmg
7+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py ${CMAKE_SOURCE_DIR}/${_path}/${_name}.pmg
8+
COMMENT "Generating ${_path}/${_name}_pm.h..."
99
)
1010
endfunction()
1111

12-
pmgen_command(test_pmgen)
13-
pmgen_command(ice40_dsp)
14-
pmgen_command(ice40_wrapcarry)
15-
pmgen_command(xilinx_dsp)
16-
pmgen_command(xilinx_dsp48a)
17-
pmgen_command(xilinx_dsp_CREG)
18-
pmgen_command(xilinx_dsp_cascade)
19-
pmgen_command(microchip_dsp)
20-
pmgen_command(microchip_dsp_CREG)
21-
pmgen_command(microchip_dsp_cascade)
22-
pmgen_command(xilinx_srl)
12+
pmgen_command(test_pmgen passes/pmgen)
13+
pmgen_command(ice40_dsp techlibs/ice40)
14+
pmgen_command(ice40_wrapcarry techlibs/ice40)
15+
pmgen_command(xilinx_dsp techlibs/xilinx)
16+
pmgen_command(xilinx_dsp48a techlibs/xilinx)
17+
pmgen_command(xilinx_dsp_CREG techlibs/xilinx)
18+
pmgen_command(xilinx_dsp_cascade techlibs/xilinx)
19+
pmgen_command(microchip_dsp techlibs/microchip)
20+
pmgen_command(microchip_dsp_CREG techlibs/microchip)
21+
pmgen_command(microchip_dsp_cascade techlibs/microchip)
22+
pmgen_command(xilinx_srl techlibs/xilinx)
2323

2424
add_custom_command(
25-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/peepopt_pm.h
26-
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py -o ${CMAKE_CURRENT_BINARY_DIR}/peepopt_pm.h -p peepopt
27-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_shiftmul_right.pmg
28-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_shiftmul_left.pmg
29-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_shiftadd.pmg
30-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_muldiv.pmg
31-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_formal_clockgateff.pmg
25+
OUTPUT ${CMAKE_BINARY_DIR}/passes/opt/peepopt_pm.h
26+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py -o ${CMAKE_BINARY_DIR}/passes/opt/peepopt_pm.h -p peepopt
27+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_shiftmul_right.pmg
28+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_shiftmul_left.pmg
29+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_shiftadd.pmg
30+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_muldiv.pmg
31+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_muldiv_c.pmg
32+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_formal_clockgateff.pmg
3233
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py
33-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_shiftmul_right.pmg
34-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_shiftmul_left.pmg
35-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_shiftadd.pmg
36-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_muldiv.pmg
37-
${CMAKE_CURRENT_SOURCE_DIR}/peepopt_formal_clockgateff.pmg
34+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_shiftmul_right.pmg
35+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_shiftmul_left.pmg
36+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_shiftadd.pmg
37+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_muldiv.pmg
38+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_muldiv_c.pmg
39+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt_formal_clockgateff.pmg
3840
COMMENT "Generating passes/pmgen/peepopt_pm.h..."
3941
)
4042

4143
target_sources(yosys_passes_pmgen INTERFACE
4244
test_pmgen.cc
43-
ice40_dsp.cc
44-
ice40_wrapcarry.cc
45-
xilinx_dsp.cc
46-
microchip_dsp.cc
47-
peepopt.cc
48-
xilinx_srl.cc
45+
${CMAKE_SOURCE_DIR}/techlibs/ice40/ice40_dsp.cc
46+
${CMAKE_SOURCE_DIR}/techlibs/ice40/ice40_wrapcarry.cc
47+
${CMAKE_SOURCE_DIR}/techlibs/xilinx/xilinx_dsp.cc
48+
${CMAKE_SOURCE_DIR}/techlibs/microchip/microchip_dsp.cc
49+
${CMAKE_SOURCE_DIR}/passes/opt/peepopt.cc
50+
${CMAKE_SOURCE_DIR}/techlibs/xilinx/xilinx_srl.cc
4951
)
5052

51-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/test_pmgen_pm.h)
53+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/passes/pmgen/test_pmgen_pm.h)
5254

53-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ice40_dsp_pm.h)
54-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ice40_wrapcarry_pm.h)
55+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/ice40/ice40_dsp_pm.h)
56+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/ice40/ice40_wrapcarry_pm.h)
5557

56-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/xilinx_dsp_pm.h)
57-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/xilinx_dsp48a_pm.h)
58-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/xilinx_dsp_CREG_pm.h)
59-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/xilinx_dsp_cascade_pm.h)
58+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/xilinx/xilinx_dsp_pm.h)
59+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/xilinx/xilinx_dsp48a_pm.h)
60+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/xilinx/xilinx_dsp_CREG_pm.h)
61+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/xilinx/xilinx_dsp_cascade_pm.h)
6062

61-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/microchip_dsp_pm.h)
62-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/microchip_dsp_CREG_pm.h)
63-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/microchip_dsp_cascade_pm.h)
63+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/microchip/microchip_dsp_pm.h)
64+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/microchip/microchip_dsp_CREG_pm.h)
65+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/microchip/microchip_dsp_cascade_pm.h)
6466

65-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/peepopt_pm.h)
67+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/passes/opt/peepopt_pm.h)
6668

67-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/xilinx_srl_pm.h)
69+
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/xilinx/xilinx_srl_pm.h)
6870

6971
target_link_libraries(yosys PRIVATE yosys_passes_pmgen)

0 commit comments

Comments
 (0)