内容纲要

CMakeLists.txt

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

function(snippet number)
    add_executable(snippet${number} ${PROJECT_SOURCE_DIR}/src/main.cpp)
    target_compile_definitions(snippet${number} PRIVATE SNIPPET${number})
    #target_link_libraries(snippet${number} pthread)

    target_include_directories(snippet${number} PRIVATE 
        D:/downloads/4.1.2/opencv-4.1.2/build/install/include   
    )    

    add_definitions(        
        -DNDEBUG
    )       

    target_link_libraries(
        snippet${number} 
        opencv_world412.lib
        opencv_img_hash412.lib
        ade.lib
        IlmImf.lib
        ippicvmt.lib
        ippiw.lib
        ittnotify.lib
        libjasper.lib
        libjpeg-turbo.lib
        libpng.lib
        libprotobuf.lib
        libtiff.lib
        libwebp.lib
        quirc.lib
        zlib.lib
    )

    target_link_directories(snippet${number} PRIVATE
        D:/downloads/4.1.2/opencv-4.1.2/build/install/x86/vc15/release/staticlib
    )

    set_property(TARGET snippet${number} PROPERTY FOLDER "opencv-cpp-examples")

endfunction(snippet)

function(get_num num result_var)
    set(result "error")
    string(LENGTH ${num} length)
    if (${length} STREQUAL "1")                
        set(result "00${num}")
    elseif (${length} STREQUAL "2")
        set(result "0${num}")        
    endif()   

    set(${result_var} "${result}" PARENT_SCOPE)
endfunction()

# 循环生成工程
foreach(i RANGE 1 30)
    get_num(${i} number)
    snippet(${number})    
endforeach(i)

参考

发表评论

电子邮件地址不会被公开。 必填项已用*标注