Ninja and clang for VS 2019

举报
风吹稻花香 发表于 2021/06/21 13:23:43 2021/06/21
【摘要】   https://stackoverflow.com/questions/55070217/build-project-using-cmake-ninja-and-clang-for-vs-2019   cmake_minimum_required(VERSION 3.11 FATAL_ERROR) #(CMAKE_INSTALL_PREFIX "...

 

https://stackoverflow.com/questions/55070217/build-project-using-cmake-ninja-and-clang-for-vs-2019

 


  
  1. cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
  2. #(CMAKE_INSTALL_PREFIX "C:\\Program Files\\LLVM\\bin")
  3. project(sink)
  4. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++17 -pedantic")
  5. set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
  6. set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
  7. set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
  8. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}/bin")
  9. file(GLOB SOURCES "${SRC_DIR}/*.cpp" "${SRC_DIR}/*.cc" "${SRC_DIR}/*.c")
  10. file(GLOB HEADERS "${INCLUDE_DIR}/*.h" "${INCLUDE_DIR}/*.hpp")
  11. add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

 


  
  1. {
  2. "configurations": [
  3. {
  4. "name": "Debug",
  5. "generator": "Ninja",
  6. "configurationType": "Debug",
  7. "inheritEnvironments": [
  8. "msvc_x64"
  9. ],
  10. "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
  11. "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
  12. "cmakeCommandArgs": "",
  13. "buildCommandArgs": "-v",
  14. "ctestCommandArgs": "",
  15. "variables": [
  16. {
  17. "name": "CMAKE_CXX_COMPILER",
  18. "type": "PATH",
  19. "value": "C:\\Program Files\\LLVM\\bin\\clang-cl.exe"
  20. },
  21. {
  22. "name": "CMAKE_C_COMPILER",
  23. "type": "PATH",
  24. "value": "C:\\Program Files\\LLVM\\bin\\clang-cl.exe"
  25. }
  26. ]
  27. }
  28. ]
  29. }

 


  
  1. cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
  2. project(sink)
  3. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Xclang -std=c++17 -Xclang -pedantic")
  4. set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
  5. set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
  6. set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
  7. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}/bin")
  8. file(GLOB SOURCES "${SRC_DIR}/*.cpp" "${SRC_DIR}/*.cc" "${SRC_DIR}/*.c")
  9. file(GLOB HEADERS "${INCLUDE_DIR}/*.h" "${INCLUDE_DIR}/*.hpp")
  10. add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

 

And CMakeSettings.json:


  
  1. {
  2. "configurations": [
  3. {
  4. "name": "Debug",
  5. "generator": "Ninja",
  6. "configurationType": "Debug",
  7. "inheritEnvironments": [ "msvc_x64" ],
  8. "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
  9. "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
  10. "cmakeCommandArgs": "-DCMAKE_CXX_COMPILER:PATH=\"C:\\Program Files\\LLVM\\bin\\clang-cl.exe\" -DCMAKE_CXX_FLAGS:STRING=\"/DWIN32 /D_WINDOWS /GR /EHsc\" -DCMAKE_CXX_FLAGS_DEBUG:STRING=\"/MDd /Zi /Ob0 /Od /RTC1\"",
  11. "buildCommandArgs": "-v",
  12. "ctestCommandArgs": "",
  13. "variables": []
  14. }
  15. ]
  16. }

 

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/118080952

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。