[英]Building Verilator (C++) with CMake built-in NDK
I tried with this example, but nothing happens:我试过这个例子,但没有任何反应:
cmake_minimum_required(VERSION 3.8)
project(cmake_simulator)
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21)
set(CMAKE_ANDROID_ARCH_ABI x86)
set(CMAKE_ANDROID_NDK /home/icarolima/Android/Sdk/ndk/21.3.6528147)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)
set(CMAKE_TOOLCHAIN_FILE /home/icarolima/Android/Sdk/ndk/21.3.6528147/build/cmake/android.toolchain.cmake)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable")
endif()
# Create a new executable target that will contain all your sources
add_library(simulator SHARED simulator.cpp)
# Add the Verilated circuit to the target
verilate(simulator
INCLUDE_DIRS "."
SOURCES top.sv
VERILATOR_ARGS -Wno-CASEINCOMPLETE -Wno-WIDTH -Wno-COMBDLY -cc +1800-2012ext+sv)
For example, if I change the CMAKE_ANDROID_ARCH_ABI
to anything else, nothing happens.例如,如果我将
CMAKE_ANDROID_ARCH_ABI
更改为其他任何内容,则没有任何反应。 It is like CMake is ignoring the NDK part of the code.这就像 CMake 忽略了代码的 NDK 部分。
But If I change the project to another location, different things happen:但是如果我将项目更改到另一个位置,则会发生不同的事情:
cmake_minimum_required(VERSION 3.8)
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21)
set(CMAKE_ANDROID_ARCH_ABI x86)
set(CMAKE_ANDROID_NDK /home/icarolima/Android/Sdk/ndk/21.3.6528147)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)
project(cmake_simulator)
set(CMAKE_TOOLCHAIN_FILE /home/icarolima/Android/Sdk/ndk/21.3.6528147/build/cmake/android.toolchain.cmake)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable")
endif()
# Create a new executable target that will contain all your sources
add_library(simulator SHARED simulator.cpp)
# Add the Verilated circuit to the target
verilate(simulator
INCLUDE_DIRS "."
SOURCES top.sv
VERILATOR_ARGS -Wno-CASEINCOMPLETE -Wno-WIDTH -Wno-COMBDLY -cc +1800-2012ext+sv)
The error:错误:
CMake Error at /home/icarolima/Android/Sdk/cmake/3.10.2.4988404/share/cmake-3.10/Modules/Platform/Android/Determine-Compiler-NDK.cmake:97 (message):
Android: No toolchain for ABI 'x86' found in the NDK:
/home/icarolima/Android/Sdk/ndk/21.3.6528147
I have no experience with CMake, I think that the problem is the order of the things.我没有使用 CMake 的经验,我认为问题在于事物的顺序。 Can anyone help me?
谁能帮我?
Setting all of these variables (such as CMAKE_SYSTEM_NAME
, CMAKE_SYSTEM_VERSION
, CMAKE_ANDROID_ARCH_ABI
, etc.) should happen in the toolchain file.设置所有这些变量(例如
CMAKE_SYSTEM_NAME
、 CMAKE_SYSTEM_VERSION
、 CMAKE_ANDROID_ARCH_ABI
等)应该在工具链文件中进行。 You may certainly experience some nasty CMake behavior by putting these in the CMakeLists.txt
file itself.通过将这些放在
CMakeLists.txt
文件本身中,您肯定会遇到一些令人讨厌的 CMake 行为。 There is even a sample toolchain file in the CMake documentation you linked here .您在此处链接的 CMake 文档中甚至还有一个示例工具链文件。
Also, the CMAKE_TOOLCHAIN_FILE
variable should be set on the command line when you call cmake
, not in the CMake file itself.此外,
CMAKE_TOOLCHAIN_FILE
变量应该在调用cmake
时在命令行上设置,而不是在 CMake 文件本身中设置。 This reduces your CMakeLists.txt
file to something like this:这将您的
CMakeLists.txt
文件减少为如下所示:
cmake_minimum_required(VERSION 3.8)
project(cmake_simulator)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable")
endif()
# Create a new executable target that will contain all your sources
add_library(simulator SHARED simulator.cpp)
# Add the Verilated circuit to the target
verilate(simulator
INCLUDE_DIRS "."
SOURCES top.sv
VERILATOR_ARGS -Wno-CASEINCOMPLETE -Wno-WIDTH -Wno-COMBDLY -cc +1800-2012ext+sv)
Then, you should call cmake
, specifying the toolchain file to use, like this:然后,您应该调用
cmake
,指定要使用的工具链文件,如下所示:
cmake -DCMAKE_TOOLCHAIN_FILE=/home/icarolima/Android/Sdk/ndk/21.3.6528147/build/cmake/android.toolchain.cmake ..
So, just to clarify, the way I solved it can be seen here: Dockerfile , and here: sandbox_template .所以,为了澄清一下,我解决它的方式可以在这里看到: Dockerfile ,在这里: sandbox_template 。
Thanks for the answers @squareskittles!感谢@squareskittles 的回答!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.