简体   繁体   English

使用 CMake 内置 NDK 构建 Verilator (C++)

[英]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_NAMECMAKE_SYSTEM_VERSIONCMAKE_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.

相关问题 如何更改指向已删除的android-ndk-r9安装的内置C / C ++路径? - How to change built-in C/C++ paths pointing to a deleted android-ndk-r9 installation? 使用NDK构建具有cmake构建文件的Android C ++项目 - Building c++ projects which have cmake build files for Android using NDK 如何使用cmake和Android NDK在C ++中加载线程支持 - How to load thread support in C++ with cmake and Android NDK 使用 NDK(本机 c++ 代码)部分构建 librealsense android 应用程序? - Building librealsense android app with NDK (native c++ code) part? 使用带有LAME的NDK的内置函数警告的不兼容的隐式声明 - Incompatible Implicit Declaration of Built-In Function Warning Using NDK with LAME Android C ++ NDK - Android C++ NDK Ubuntu+CMake,无法静态构建 C/C++ android-ndk 程序 - Ubuntu+CMake, Cannot static-build C/C++ android-ndk programs 有没有办法在C ++中以编程方式执行adb命令? 这部分C ++代码是使用android studio中的ndk build构建的。 那里 - Is there a way to execute adb commands programatically in C++? This C++ part of code is built using ndk build in android studio. There CMAKE不遵循gradle的标志来在Android上构建NDK - CMAKE not obeying flags from gradle for NDK building on Android Android Studio CMake / Ninja不用于构建NDK项目 - Android Studio CMake/Ninja Not Used for Building an NDK project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM