forked from YosysHQ/prjtrellis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
181 lines (157 loc) · 8.16 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.5)
project(libtrellis)
option(BUILD_PYTHON "Build Python Integration" ON)
option(BUILD_SHARED "Build shared Trellis library" ON)
option(STATIC_BUILD "Create static build of Trellis tools" OFF)
set(PROGRAM_PREFIX "" CACHE STRING "Name prefix for executables")
set(CMAKE_CXX_STANDARD 14)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -bigobj -EHsc")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -O3")
endif()
set(CMAKE_DEFIN)
set(link_param "")
if (STATIC_BUILD)
set(Boost_USE_STATIC_LIBS ON)
if(MSVC)
add_definitions(-DBOOST_PYTHON_STATIC_LIB)
set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
elseif (NOT APPLE)
set(link_param "-static")
endif()
else()
if(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
endif()
if (WASI)
set(USE_THREADS OFF)
add_definitions(
-DBOOST_EXCEPTION_DISABLE
-DBOOST_NO_EXCEPTIONS
-DBOOST_SP_NO_ATOMIC_ACCESS
-DBOOST_AC_DISABLE_THREADS
-DBOOST_NO_CXX11_HDR_MUTEX
-DBOOST_NO_CXX11_HDR_ATOMIC
)
else()
set(USE_THREADS ON)
endif()
set(boost_libs filesystem program_options system)
if (USE_THREADS)
list(APPEND boost_libs thread)
else()
add_definitions(-DNO_THREADS)
endif()
set(Boost_NO_BOOST_CMAKE ON)
find_package(PythonInterp 3.5 REQUIRED)
if (BUILD_PYTHON)
find_package(PythonLibs 3.5 REQUIRED)
set(PythonInstallTarget "pytrellis")
endif()
find_package(Boost REQUIRED COMPONENTS ${boost_libs})
find_package(Git)
if (NOT DEFINED PYBIND11_INCLUDE_DIR)
# Use bundled pybind11
set(PYBIND11_INCLUDE_DIR "3rdparty/pybind11/include")
endif()
include_directories(include/ ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${PYBIND11_INCLUDE_DIR})
aux_source_directory(include/ INCLUDE_FILES)
aux_source_directory(src/ SOURCE_FILES)
if (BUILD_SHARED)
add_library(trellis SHARED ${INCLUDE_FILES} ${SOURCE_FILES})
else()
add_library(trellis STATIC ${INCLUDE_FILES} ${SOURCE_FILES})
endif()
target_link_libraries(trellis LINK_PUBLIC ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
if (BUILD_PYTHON)
target_link_libraries(trellis LINK_PUBLIC ${PYTHON_LIBRARIES})
endif()
if (BUILD_PYTHON)
PYTHON_ADD_MODULE(pytrellis ${INCLUDE_FILES} ${SOURCE_FILES})
target_compile_definitions(pytrellis PRIVATE INCLUDE_PYTHON=1)
if (APPLE)
target_link_libraries(pytrellis LINK_PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} "-undefined dynamic_lookup -bundle")
else()
target_link_libraries(pytrellis LINK_PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
endif()
endif()
include(GNUInstallDirs)
file(RELATIVE_PATH TRELLIS_RPATH_LIBDIR /${CMAKE_INSTALL_BINDIR} /${CMAKE_INSTALL_LIBDIR})
file(RELATIVE_PATH TRELLIS_RPATH_DATADIR /${CMAKE_INSTALL_BINDIR} /${CMAKE_INSTALL_DATADIR})
function(setup_rpath name)
if(APPLE)
set_target_properties(${name} PROPERTIES
BUILD_WITH_INSTALL_RPATH ON
INSTALL_RPATH "@loader_path/${TRELLIS_RPATH_LIBDIR}/${PROGRAM_PREFIX}trellis"
INSTALL_NAME_DIR "@rpath")
elseif(UNIX)
set_target_properties(${name} PROPERTIES
BUILD_WITH_INSTALL_RPATH ON
INSTALL_RPATH "\$ORIGIN/${TRELLIS_RPATH_LIBDIR}/${PROGRAM_PREFIX}trellis")
endif()
endfunction()
# Avoid perturbing build if git version hasn't changed
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
set(LAST_GIT_VERSION "")
if (NOT DEFINED CURRENT_GIT_VERSION)
execute_process(COMMAND git describe --tags OUTPUT_VARIABLE CURRENT_GIT_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
string(STRIP "${CURRENT_GIT_VERSION}" CURRENT_GIT_VERSION)
if (EXISTS "${CMAKE_BINARY_DIR}/generated/last_git_version")
file(READ "${CMAKE_BINARY_DIR}/generated/last_git_version" LAST_GIT_VERSION)
endif()
if (NOT ("${LAST_GIT_VERSION}" STREQUAL "${CURRENT_GIT_VERSION}") OR NOT GIT_EXECUTABLE)
configure_file(
${CMAKE_SOURCE_DIR}/tools/version.cpp.in
${CMAKE_BINARY_DIR}/generated/version.cpp
)
endif()
file(WRITE "${CMAKE_BINARY_DIR}/generated/last_git_version" CURRENT_GIT_VERSION)
add_executable(${PROGRAM_PREFIX}ecpbram ${INCLUDE_FILES} tools/ecpbram.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_include_directories(${PROGRAM_PREFIX}ecpbram PRIVATE tools)
target_compile_definitions(${PROGRAM_PREFIX}ecpbram PRIVATE TRELLIS_RPATH_DATADIR="${TRELLIS_RPATH_DATADIR}" TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}" TRELLIS_PROGRAM_PREFIX="${PROGRAM_PREFIX}")
target_link_libraries(${PROGRAM_PREFIX}ecpbram trellis ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${link_param})
setup_rpath(${PROGRAM_PREFIX}ecpbram)
add_executable(${PROGRAM_PREFIX}ecppack ${INCLUDE_FILES} tools/ecppack.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_include_directories(${PROGRAM_PREFIX}ecppack PRIVATE tools)
target_compile_definitions(${PROGRAM_PREFIX}ecppack PRIVATE TRELLIS_RPATH_DATADIR="${TRELLIS_RPATH_DATADIR}" TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}" TRELLIS_PROGRAM_PREFIX="${PROGRAM_PREFIX}")
target_link_libraries(${PROGRAM_PREFIX}ecppack trellis ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${link_param})
setup_rpath(${PROGRAM_PREFIX}ecppack)
add_executable(${PROGRAM_PREFIX}ecpunpack ${INCLUDE_FILES} tools/ecpunpack.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_include_directories(${PROGRAM_PREFIX}ecpunpack PRIVATE tools)
target_compile_definitions(${PROGRAM_PREFIX}ecpunpack PRIVATE TRELLIS_RPATH_DATADIR="${TRELLIS_RPATH_DATADIR}" TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}" TRELLIS_PROGRAM_PREFIX="${PROGRAM_PREFIX}")
target_link_libraries(${PROGRAM_PREFIX}ecpunpack trellis ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${link_param})
setup_rpath(${PROGRAM_PREFIX}ecpunpack)
add_executable(${PROGRAM_PREFIX}ecppll ${INCLUDE_FILES} tools/ecppll.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_include_directories(${PROGRAM_PREFIX}ecppll PRIVATE tools)
target_compile_definitions(${PROGRAM_PREFIX}ecppll PRIVATE TRELLIS_RPATH_DATADIR="${TRELLIS_RPATH_DATADIR}" TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}" TRELLIS_PROGRAM_PREFIX="${PROGRAM_PREFIX}")
target_link_libraries(${PROGRAM_PREFIX}ecppll trellis ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${link_param})
setup_rpath(${PROGRAM_PREFIX}ecppll)
add_executable(${PROGRAM_PREFIX}ecpmulti ${INCLUDE_FILES} tools/ecpmulti.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_include_directories(${PROGRAM_PREFIX}ecpmulti PRIVATE tools)
target_compile_definitions(${PROGRAM_PREFIX}ecpmulti PRIVATE TRELLIS_RPATH_DATADIR="${TRELLIS_RPATH_DATADIR}" TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}" TRELLIS_PROGRAM_PREFIX="${PROGRAM_PREFIX}")
target_link_libraries(${PROGRAM_PREFIX}ecpmulti trellis ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${link_param})
setup_rpath(${PROGRAM_PREFIX}ecpmulti)
if (WASI)
foreach (tool ecpbram ecppack ecpunpack ecppll ecpmulti)
# set(CMAKE_EXECUTABLE_SUFFIX) breaks CMake tests for some reason
set_property(TARGET ${PROGRAM_PREFIX}${tool} PROPERTY SUFFIX ".wasm")
endforeach()
endif()
if (BUILD_SHARED)
install(TARGETS trellis ${PROGRAM_PREFIX}ecpbram ${PROGRAM_PREFIX}ecppack ${PROGRAM_PREFIX}ecppll ${PROGRAM_PREFIX}ecpunpack ${PROGRAM_PREFIX}ecpmulti ${PythonInstallTarget}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROGRAM_PREFIX}trellis
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
else()
install(TARGETS ${PROGRAM_PREFIX}ecpbram ${PROGRAM_PREFIX}ecppack ${PROGRAM_PREFIX}ecpunpack ${PROGRAM_PREFIX}ecppll ${PROGRAM_PREFIX}ecpmulti
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
install(DIRECTORY ../database DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROGRAM_PREFIX}trellis PATTERN ".git" EXCLUDE)
install(DIRECTORY ../misc DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROGRAM_PREFIX}trellis)
install(DIRECTORY ../util/common DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROGRAM_PREFIX}trellis/util)
install(DIRECTORY ../timing/util DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROGRAM_PREFIX}trellis/timing)
install(PROGRAMS ../timing/util/cell_html.py DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROGRAM_PREFIX}trellis/timing/util)
install(PROGRAMS ../timing/util/cell_timings.py DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROGRAM_PREFIX}trellis/timing/util)