• CMakeLists.txt简单项目模板


    1,环境

         Windows 10: VS2019, VS Code,CMake

         Ubuntu 22.04: GCC 11, VS Code, CMake

         OpenCV 4.5.5

    2,简单CMakeLists.txt项目模板

    1. CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
    2. PROJECT(demo VERSION 0.1.0)
    3. ###
    4. ### local script
    5. ###
    6. ADD_DEFINITIONS(-DUSE_CXX)
    7. INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
    8. FILE(GLOB SRC_HEADER_LIST ${CMAKE_SOURCE_DIR}/include/*.h ${CMAKE_SOURCE_DIR}/include/*.hpp)
    9. FILE(GLOB SRC_SOURCE_LIST ${CMAKE_SOURCE_DIR}/sources/*.c ${CMAKE_SOURCE_DIR}/sources/*.cc ${CMAKE_SOURCE_DIR}/sources/*.cpp ${CMAKE_SOURCE_DIR}/sources/*.cxx)
    10. SET(SRC_LIST ${SRC_HEADER_LIST} ${SRC_SOURCE_LIST})
    11. SOURCE_GROUP("Headers" FILES ${SRC_HEADER_LIST})
    12. SOURCE_GROUP("Sources" FILES ${SRC_SOURCE_LIST})
    13. ###
    14. ### 3rdparty
    15. ###
    16. INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/3rdparty/include")
    17. LINK_DIRECTORIES("${CMAKE_SOURCE_DIR}/3rdparty/lib")
    18. SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-rpath-link=${CMAKE_SOURCE_DIR}/3rdparty/lib")
    19. #SET(EXTRA_LIBS )
    20. ###
    21. ### opencv
    22. ###
    23. if (WIN32)
    24. #MESSAGE(STATUS "Windows: ")
    25. SET(OpenCV_DIR "D:/ENV/opencv-4.5.5")
    26. elseif(APPLE)
    27. MESSAGE(STATUS "Apple: ")
    28. else ()
    29. #MESSAGE(STATUS "Linux: ")
    30. SET(OpenCV_DIR "/usr/lib/cmake/opencv4")
    31. endif ()
    32. FIND_PACKAGE(OpenCV REQUIRED)
    33. INCLUDE_DIRECTORIES( ${OpenCV_INCLUDE_DIRS} )
    34. SET(EXTRA_LIBS ${EXTRA_LIBS} ${OpenCV_LIBS})
    35. ###
    36. ### target:
    37. ###
    38. # ADD_LIBRARY( demo SHARED ${SRC_LIST} ${CMAKE_SOURCE_DIR}/demo/main.cpp)
    39. # SET(EXTRA_LIBS ${EXTRA_LIBS} demo)
    40. ADD_EXECUTABLE( demo ${SRC_LIST} ${CMAKE_SOURCE_DIR}/demo/main.cpp)
    41. TARGET_LINK_LIBRARIES( demo ${EXTRA_LIBS} )
    42. TARGET_COMPILE_DEFINITIONS( demo PRIVATE API_EXPORTS)
    43. SET_TARGET_PROPERTIES(demo PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" )

    模板目录结构下载:

    3,CMake的关键字简要介绍

  • 相关阅读:
    发生以下的报错怎么办?
    LeetCode 热题 HOT 100 第八十一天 647. 回文子串 用python3求解
    python-0006-django路由
    Android13 下载apk并安装apk
    碰到CTS问题我该如何处理?
    Windows Service Wrapper 一个将可执行文件封装为windows服务的工具
    物联网中的MQTT协议总结
    基于SSM的个人博客系统设计与实现(Java+MySQL)
    物联网-业务数据智能管理应用设计
    rust语言初识
  • 原文地址:https://blog.csdn.net/mylaf/article/details/126707176