![](/img/trans.png)
[英]Convert compiler command line to CMakeLists.txt for Casablanca Rest SDK
[英]Convert Linux Debian gcc command to CMakeLists.txt
我希望這個問題不是太瑣碎,但我正在嘗試將 gcc 命令轉換為 CMakeLists.txt。 不幸的是,我無法理解基礎知識,希望您能幫助我。 我想要這樣做的主要原因是我在樹莓上構建整個東西,它有很多性能問題。 所以構建整個東西需要90分鍾。 對於 cmake,我希望在進行更改時能夠更快地完成構建過程。 這在理論上應該是可能的。
這是我的 gcc 命令
gcc -std=c99 -flto=1 -I$HOME/install/include -L$HOME/install/lib main.c MotorSteuerung.c
-lopen62541 -lmbedtls -lmbedx509 -lmbedcrypto -o MotorSteuerung
我已經開始使用 cmake 文件,但不幸的是我不太明白我必須做什么。 特別是 -flto=1 將並行標志限制為 1(否則它不能在樹莓上構建)在經過長時間的搜索后引導我來到這里。 但我也不太明白如何實際集成庫......
cmake_minimum_required(VERSION 3.20)
# set the project name
project(MotorSteuerung)
# Set the output folder where your program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# The following folder will be included
include_directories("${PROJECT_SOURCE_DIR}")
# add the executable
add_executable(Tutorial open62541::open62541)
謝謝你的幫助
您可以使用SET()
設置編譯器標志。 查看CMake 文檔
您可以將CMAKE_CXX_FLAGS
設置為要傳遞給編譯器的標志
Set() 和 CMAKE_CXX_FLAGS 的提示對我幫助很大。 我現在已經把 rest 放在一起試用了。 不幸的是,正如評論中提到的,這對構建時間沒有影響,但現在處理比使用 gcc 命令要好得多。 在這里你可以找到我的 cmake 文件,也許它會幫助你們中的一些人翻譯你的 gcc 命令。
cmake_minimum_required(VERSION 3.10)
# set the project name
project(MotorSteuerung)
message("Cmake Prefix Path is \"${CMAKE_PREFIX_PATH}\"")
# open62541 must be installed.
# If in custom path, then use -DCMAKE_PREFIX_PATH=/home/user/install
find_package(open62541 1.1 REQUIRED COMPONENTS FullNamespace)
#The following folder will be included
include_directories(${CMAKE_PREFIX_PATH}/include)
link_directories(${CMAKE_PREFIX_PATH}/lib)
# add the executable
add_executable(MotorSteuerung main.c MotorSteuerung.c)
#The following libraries will be linked
target_link_libraries(MotorSteuerung open62541 mbedtls mbedx509 mbedcrypto)
#Limit Parallel Linking Jobs with -DMY_LIMIT_FLAG=ON
option(MY_LIMIT_FLAG "If Build fail you can set this ON to Limit parallel Linking Jobs to One" OFF) #OFF by default
if(MY_LIMIT_FLAG)
set(CMAKE_C_FLAGS "-flto=1")
message("Set Parallel Linking Jobs to One")
endif(MY_LIMIT_FLAG)
unset(MY_LIMIT_FLAG CACHE) # <---- this is the important!!
#Set the the C Standart
set_property(TARGET MotorSteuerung PROPERTY C_STANDARD 99)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.