Skip to content

Commit 083ffab

Browse files
committed
CMake: Fixed libyosys and renamed source dir so project can be imported as a subdirectory
1 parent b6e5bf1 commit 083ffab

File tree

5 files changed

+77
-58
lines changed

5 files changed

+77
-58
lines changed

CMakeLists.txt

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.13)
22
project(yosys LANGUAGES CXX C)
33
set(YOSYS_VER "0.50+1")
4+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
45

56
# features (the more the better)
67

@@ -53,12 +54,12 @@ if (ENABLE_ABC)
5354
add_subdirectory(abc EXCLUDE_FROM_ALL)
5455

5556
add_custom_command(
56-
OUTPUT ${CMAKE_BINARY_DIR}/yosys-abc
57+
OUTPUT ${yosys_BINARY_DIR}/yosys-abc
5758
DEPENDS abc # Depend on the target, not the generator expression
58-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:abc> ${CMAKE_BINARY_DIR}/yosys-abc
59+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:abc> ${yosys_BINARY_DIR}/yosys-abc
5960
)
6061

61-
add_custom_target(yosys-abc-copy ALL DEPENDS ${CMAKE_BINARY_DIR}/yosys-abc)
62+
add_custom_target(yosys-abc-copy ALL DEPENDS ${yosys_BINARY_DIR}/yosys-abc)
6263
endif()
6364

6465
set(CMAKE_CXX_STANDARD ${CXXSTD})
@@ -73,13 +74,18 @@ find_package(FLEX 2.6 REQUIRED)
7374
find_package(BISON 3.0 REQUIRED)
7475
find_package(Python3 3.5 REQUIRED COMPONENTS Interpreter)
7576

76-
add_executable(yosys)
77-
#target_include_directories(yosys PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
78-
#target_include_directories(yosys PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
79-
#target_compile_definitions(yosys PRIVATE _YOSYS_)
77+
add_library(yosys STATIC)
78+
#target_include_directories(yosys PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
79+
#target_include_directories(yosys PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
80+
#target_compile_definitions(yosys PUBLIC _YOSYS_)
8081
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
82+
target_include_directories(yosys PUBLIC
83+
${CMAKE_CURRENT_BINARY_DIR}
84+
${CMAKE_CURRENT_SOURCE_DIR}
85+
)
8186

8287
add_compile_definitions(_YOSYS_)
88+
target_compile_definitions(yosys PUBLIC _YOSYS_)
8389

8490
if (ENABLE_READLINE AND ENABLE_EDITLINE)
8591
message(FATAL_ERROR "Not possible to enable both ENABLE_READLINE and ENABLE_EDITLINE")
@@ -88,26 +94,26 @@ endif()
8894
if (ENABLE_READLINE)
8995
find_package(Readline REQUIRED)
9096
add_compile_definitions(YOSYS_ENABLE_READLINE)
91-
target_link_libraries(yosys PRIVATE ${READLINE_LIBRARY})
97+
target_link_libraries(yosys PUBLIC ${READLINE_LIBRARY})
9298
endif()
9399

94100
if (ENABLE_EDITLINE)
95101
find_package(Editline REQUIRED)
96102
add_compile_definitions(YOSYS_ENABLE_EDITLINE)
97-
target_link_libraries(yosys PRIVATE ${EDITLINE_LIBRARY})
103+
target_link_libraries(yosys PUBLIC ${EDITLINE_LIBRARY})
98104
endif()
99105

100106
if (ENABLE_TCL)
101107
find_package(TCL 8.6 REQUIRED)
102108
add_compile_definitions(YOSYS_ENABLE_TCL)
103-
target_include_directories(yosys PRIVATE ${TCL_INCLUDE_PATH})
104-
target_link_libraries(yosys PRIVATE ${TCL_LIBRARY})
109+
target_include_directories(yosys PUBLIC ${TCL_INCLUDE_PATH})
110+
target_link_libraries(yosys PUBLIC ${TCL_LIBRARY})
105111
endif()
106112

107113
if (ENABLE_ZLIB)
108114
find_package(ZLIB REQUIRED)
109115
add_compile_definitions(YOSYS_ENABLE_ZLIB)
110-
target_link_libraries(yosys PRIVATE ZLIB::ZLIB)
116+
target_link_libraries(yosys PUBLIC ZLIB::ZLIB)
111117
endif()
112118

113119
if (ENABLE_COVER)
@@ -140,7 +146,7 @@ if (ENABLE_ABC)
140146
add_compile_definitions(YOSYS_ENABLE_ABC)
141147
if (LINK_ABC)
142148
add_compile_definitions(YOSYS_LINK_ABC)
143-
target_link_libraries(yosys PRIVATE $<TARGET_FILE:libabc>)
149+
target_link_libraries(yosys PUBLIC $<TARGET_FILE:libabc>)
144150
add_dependencies(yosys libabc)
145151
endif()
146152
endif()
@@ -149,7 +155,7 @@ if (ENABLE_PLUGINS)
149155
find_package(LibFFI REQUIRED)
150156
add_compile_definitions(YOSYS_ENABLE_PLUGINS)
151157
include_directories(${LIBFFI_INCLUDE_DIR})
152-
target_link_libraries(yosys PRIVATE ${LIBFFI_LIBRARY})
158+
target_link_libraries(yosys PUBLIC ${LIBFFI_LIBRARY})
153159
endif()
154160

155161
if (DISABLE_SPAWN)
@@ -284,6 +290,19 @@ endif()
284290

285291
set_property(SOURCE kernel/log.cc APPEND PROPERTY COMPILE_DEFINITIONS YOSYS_SRC="${PROJECT_SOURCE_DIR}")
286292

293+
if (ENABLE_LIBYOSYS)
294+
add_library(yosys_shared SHARED)
295+
target_link_libraries(yosys_shared PUBLIC yosys)
296+
set_target_properties(yosys_shared PROPERTIES OUTPUT_NAME yosys)
297+
install(TARGETS yosys_shared
298+
LIBRARY DESTINATION .)
299+
endif()
300+
301+
add_executable(yosys_exe
302+
kernel/driver.cc)
303+
target_link_libraries(yosys_exe PUBLIC yosys)
304+
set_target_properties(yosys_exe PROPERTIES OUTPUT_NAME yosys)
305+
287306
#### yosys-config setup ####
288307
# compiler
289308
get_filename_component(_CXX_BASENAME "${CMAKE_CXX_COMPILER}" NAME)
@@ -371,14 +390,14 @@ set(LIBS "${YOSYS_CFG_LIBS}")
371390
set(BINDIR "${YOSYS_CFG_BINDIR}")
372391
set(DATDIR "${YOSYS_CFG_DATDIR}")
373392

374-
configure_file(misc/yosys-config.in ${CMAKE_BINARY_DIR}/yosys-config @ONLY)
375-
file(CHMOD ${CMAKE_BINARY_DIR}/yosys-config
393+
configure_file(misc/yosys-config.in ${yosys_BINARY_DIR}/yosys-config @ONLY)
394+
file(CHMOD ${yosys_BINARY_DIR}/yosys-config
376395
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
377396
GROUP_READ GROUP_EXECUTE
378397
WORLD_READ WORLD_EXECUTE)
379398

380399
add_custom_target(yosys-config-copy ALL
381-
DEPENDS ${CMAKE_BINARY_DIR}/yosys-config)
400+
DEPENDS ${yosys_BINARY_DIR}/yosys-config)
382401

383402
#### INSTALL ####
384403
install(TARGETS yosys
@@ -390,7 +409,7 @@ if (ENABLE_ABC)
390409
RENAME yosys-abc)
391410
endif()
392411

393-
install(PROGRAMS ${CMAKE_BINARY_DIR}/yosys-config DESTINATION .)
412+
install(PROGRAMS ${yosys_BINARY_DIR}/yosys-config DESTINATION .)
394413

395414
#### TESTING ####
396415
include(cmake/TestFiles.cmake)

kernel/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ find_package(Git)
1010
if(Git_FOUND)
1111
execute_process(
1212
COMMAND ${GIT_EXECUTABLE} rev-parse --short=9 HEAD
13-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
13+
WORKING_DIRECTORY ${yosys_SOURCE_DIR}
1414
OUTPUT_VARIABLE CURRENT_GIT_VERSION
1515
OUTPUT_STRIP_TRAILING_WHITESPACE
1616
)
@@ -34,7 +34,7 @@ target_sources(yosys_kernel INTERFACE
3434
constids.inc
3535
cost.cc
3636
cost.h
37-
driver.cc
37+
# driver.cc
3838
drivertools.cc
3939
drivertools.h
4040
ff.cc

passes/pmgen/CMakeLists.txt

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ add_library(yosys_passes_pmgen INTERFACE)
22

33
function(pmgen_command _name _path)
44
add_custom_command(
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
5+
OUTPUT ${yosys_BINARY_DIR}/${_path}/${_name}_pm.h
6+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py -o ${yosys_BINARY_DIR}/${_path}/${_name}_pm.h -p ${_name} ${yosys_SOURCE_DIR}/${_path}/${_name}.pmg
7+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py ${yosys_SOURCE_DIR}/${_path}/${_name}.pmg
88
COMMENT "Generating ${_path}/${_name}_pm.h..."
99
)
1010
endfunction()
@@ -22,50 +22,50 @@ pmgen_command(microchip_dsp_cascade techlibs/microchip)
2222
pmgen_command(xilinx_srl techlibs/xilinx)
2323

2424
add_custom_command(
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
25+
OUTPUT ${yosys_BINARY_DIR}/passes/opt/peepopt_pm.h
26+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py -o ${yosys_BINARY_DIR}/passes/opt/peepopt_pm.h -p peepopt
27+
${yosys_SOURCE_DIR}/passes/opt/peepopt_shiftmul_right.pmg
28+
${yosys_SOURCE_DIR}/passes/opt/peepopt_shiftmul_left.pmg
29+
${yosys_SOURCE_DIR}/passes/opt/peepopt_shiftadd.pmg
30+
${yosys_SOURCE_DIR}/passes/opt/peepopt_muldiv.pmg
31+
${yosys_SOURCE_DIR}/passes/opt/peepopt_muldiv_c.pmg
32+
${yosys_SOURCE_DIR}/passes/opt/peepopt_formal_clockgateff.pmg
3333
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pmgen.py
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
34+
${yosys_SOURCE_DIR}/passes/opt/peepopt_shiftmul_right.pmg
35+
${yosys_SOURCE_DIR}/passes/opt/peepopt_shiftmul_left.pmg
36+
${yosys_SOURCE_DIR}/passes/opt/peepopt_shiftadd.pmg
37+
${yosys_SOURCE_DIR}/passes/opt/peepopt_muldiv.pmg
38+
${yosys_SOURCE_DIR}/passes/opt/peepopt_muldiv_c.pmg
39+
${yosys_SOURCE_DIR}/passes/opt/peepopt_formal_clockgateff.pmg
4040
COMMENT "Generating passes/pmgen/peepopt_pm.h..."
4141
)
4242

4343
target_sources(yosys_passes_pmgen INTERFACE
4444
test_pmgen.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
45+
${yosys_SOURCE_DIR}/techlibs/ice40/ice40_dsp.cc
46+
${yosys_SOURCE_DIR}/techlibs/ice40/ice40_wrapcarry.cc
47+
${yosys_SOURCE_DIR}/techlibs/xilinx/xilinx_dsp.cc
48+
${yosys_SOURCE_DIR}/techlibs/microchip/microchip_dsp.cc
49+
${yosys_SOURCE_DIR}/passes/opt/peepopt.cc
50+
${yosys_SOURCE_DIR}/techlibs/xilinx/xilinx_srl.cc
5151
)
5252

53-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/passes/pmgen/test_pmgen_pm.h)
53+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/passes/pmgen/test_pmgen_pm.h)
5454

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)
55+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/ice40/ice40_dsp_pm.h)
56+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/ice40/ice40_wrapcarry_pm.h)
5757

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)
58+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/xilinx/xilinx_dsp_pm.h)
59+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/xilinx/xilinx_dsp48a_pm.h)
60+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/xilinx/xilinx_dsp_CREG_pm.h)
61+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/xilinx/xilinx_dsp_cascade_pm.h)
6262

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)
63+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/microchip/microchip_dsp_pm.h)
64+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/microchip/microchip_dsp_CREG_pm.h)
65+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/microchip/microchip_dsp_cascade_pm.h)
6666

67-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/passes/opt/peepopt_pm.h)
67+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/passes/opt/peepopt_pm.h)
6868

69-
target_sources(yosys_passes_pmgen PRIVATE ${CMAKE_BINARY_DIR}/techlibs/xilinx/xilinx_srl_pm.h)
69+
target_sources(yosys_passes_pmgen PRIVATE ${yosys_BINARY_DIR}/techlibs/xilinx/xilinx_srl_pm.h)
7070

7171
target_link_libraries(yosys PRIVATE yosys_passes_pmgen)

techlibs/gatemate/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ add_custom_command(
1010
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/make_lut_tree_lib.py
1111
OUTPUT lut_tree_cells.genlib lut_tree_map.v
1212
COMMENT "Generating techlibs/gatemate/lut_tree_map.v..."
13-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
13+
WORKING_DIRECTORY ${yosys_BINARY_DIR}
1414
)
1515

1616
target_sources(yosys_techlibs_gatemate PRIVATE

techlibs/quicklogic/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ add_library(yosys_techlibs_quicklogic INTERFACE)
33
function(pmgen_command _name)
44
add_custom_command(
55
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}_pm.h
6-
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/passes/pmgen/pmgen.py -o ${CMAKE_CURRENT_BINARY_DIR}/${_name}_pm.h -p ${_name} ${CMAKE_CURRENT_SOURCE_DIR}/${_name}.pmg
7-
DEPENDS ${CMAKE_SOURCE_DIR}/passes/pmgen/pmgen.py ${CMAKE_CURRENT_SOURCE_DIR}/${_name}.pmg
6+
COMMAND ${Python3_EXECUTABLE} ${yosys_SOURCE_DIR}/passes/pmgen/pmgen.py -o ${CMAKE_CURRENT_BINARY_DIR}/${_name}_pm.h -p ${_name} ${CMAKE_CURRENT_SOURCE_DIR}/${_name}.pmg
7+
DEPENDS ${yosys_SOURCE_DIR}/passes/pmgen/pmgen.py ${CMAKE_CURRENT_SOURCE_DIR}/${_name}.pmg
88
COMMENT "Generating passes/pmgen/${_name}_pm.h..."
99
)
1010
endfunction()

0 commit comments

Comments
 (0)