CLion环境下CMakeList.txt的编写方式
1 UBUNTU 环境
cmake_minimum_required(VERSION 3.15) project(PhoneInHand_linux) set(CMAKE_CXX_STANDARD 14) #SET(LC_ALL "zh_CN.GB2312") #SET(LANG "zh_CN.GB2312") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finput-charset=UTF-8 -fexec-charset=UTF-8") #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finput-charset=UTF-8 -fexec-charset=UTF-8") #set(NCNN_DIR /home/jory.d/build/ncnn-master-latest/build/install) set(NCNN_DIR ncnn) include_directories(${NCNN_DIR}/include/ncnn) link_directories(${NCNN_DIR}/lib) link_libraries(libncnn.a) find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
link_libraries(${OpenCV_LIBS})
# must add FIND_PACKAGE(OpenMP REQUIRED) if (OPENMP_FOUND) message("OPENMP FOUND") MESSAGE(STATUS "Project: ${PROJECT_NAME}") MESSAGE(STATUS "OpenCV library status:") MESSAGE(STATUS " version: ${OpenCV_VERSION}") MESSAGE(STATUS " libraries: ${OpenCV_LIBS}") MESSAGE(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") endif () include_directories(pose/include) link_directories(pose/lib) link_libraries(libpose.a) FILE(GLOB ALL_INCLUDES "src/*.h") FILE(GLOB ALL_SRCS "src/*.cpp") MESSAGE(STATUS "all *.h file: ${ALL_INCLUDES}") MESSAGE(STATUS "all *.cpp file: ${ALL_SRCS}") # make 时关闭警告 add_definitions(-w) add_definitions(-g -D LPFACE_LOG_LEVEL=0) MESSAGE("你哈珀") add_executable(PhoneInHand_linux main.cpp ${ALL_INCLUDES} ${ALL_SRCS} src/test_code1.cpp) target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ncnn human_pose)
2 WIN10
include 和 lib 的文件结构 --3rd_party --opencv-3.4.2 --include --opencv --opencv2 --lib --opencv_world342.lib --pthreads --bin --pthreadGC2.dll --pthreadVC2.dll --include --pthread.h --sched.h --*.h --lib --libpthreadGC2.lib --stb --include --stb_image.h --*.h
-- *.h
-- *.cpp
-- CMakeLists.txt
cmake_minimum_required(VERSION 3.15) project(Cplusplus_Project1) set(CMAKE_CXX_STANDARD 11) enable_language(C) enable_language(CXX) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH}) set(Stb_DIR 3rdparty/stb CACHE PATH "Path where Stb image library can be located") set(PThreads_windows_DIR ${CMAKE_CURRENT_LIST_DIR}/3rdparty/pthreads CACHE PATH "Path where pthreads for windows can be located") include_directories(${Stb_DIR}/include) include_directories(${PThreads_windows_DIR}/include) find_package(Threads REQUIRED) include_directories(./3rd_party/opencv-3.4.2/include) link_directories(./3rd_party/opencv-3.4.2/lib) if (MSVC) include_directories(${PThreads_windows_DIR}/include) link_directories(${PThreads_windows_DIR}/lib) set(c ${CMAKE_CURRENT_LIST_DIR}/3rdparty/opencv-3.4.2) set(OPENCV_INCLUDE_DIRS ${OPENCV_INCLUDE_DIRS}/include) set(OPENCV_LIB_DIRS ${OPENCV_INCLUDE_DIRS}/lib) #find_package(OPENCV REQUIRED) include_directories(${OPENCV_INCLUDE_DIRS}) link_directories(${OPENCV_LIB_DIRS}) endif () add_executable(Cplusplus_Project1 main.cpp helper.h yuv_helper.h img_helper.h inirw.h) target_link_libraries(Cplusplus_Project1 ${OpenCV_LIBS})