ʹÓÃCMake¹¹½¨LinuxÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ
ʹÓÃcmake¹¹½¨linuxÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐòµÄÉèÖü¼ÇÉ
СÐò£º
Ëæ×ÅÊÖÒÕµÄһֱǰ½ø£¬ÖÇÄÜÊÓƵ¼à¿ØÔÚÏÖ´úÉç»áÖÐÊ©Õ¹×ÅÔ½À´Ô½Ö÷ÒªµÄ×÷Óá£ÔÚÇå¾²¼à¿Ø¡¢½»Í¨ÖÎÀíµÈÁìÓò£¬ÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐòµÄÐèÇóÈÕÒæÔöÌí¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃCMakeÀ´¹¹½¨Ò»¸öÊÊÓÃÓÚLinuxϵͳµÄÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐò£¬²¢·ÖÏíһЩÏà¹ØµÄÉèÖü¼ÇÉ¡£
Ò»¡¢CMake¼ò½é£º
CMakeÊÇÒ»¸ö¿çƽ̨µÄ×Ô¶¯»¯¹¹½¨ÏµÍ³¹¤¾ß£¬¿ÉÒÔÌìÉú³£¼ûµÄ¹¹½¨¹¤¾ß£¬ÈçMakefile¡¢Visual Studio½â¾ö¼Æ»®µÈ¡£Ëüͨ¹ýCMakeLists.txtÎļþÐÎòÏîÄ¿µÄ¹¹½¨¹æÔò£¬´Ó¶øʵÏÖ¿çƽ̨¹¹½¨µÄÄ¿µÄ¡£CMake¾ßÓо«Á·Ò×Óᢹ¦Ð§Ç¿Ê¢µÄÌص㣬±»ÆÕ±éÓ¦ÓÃÓÚÖÖÖÖÈí¼þÏîÄ¿µÄ¹¹½¨Àú³ÌÖС£
¶þ¡¢¹¹½¨Ò»¸öÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐòµÄ»ù±¾ÉèÖãº
ÔÚ×îÏÈ֮ǰ£¬ÎÒÃÇÊ×ÏÈÐèҪװÖúÃCMake¹¤¾ß¡£È»ºó£¬½¨ÉèÒ»¸öеÄCMakeLists.txtÎļþ£¬²¢ÔÚÆäÖбàдÒÔÏ´úÂ룺
cmake_minimum_required(VERSION 3.10) project(SmartVideoMonitor) set(CMAKE_CXX_STANDARD 11) set(SOURCE_FILES main.cpp #Ö÷³ÌÐòÎļþ video.cpp #ÊÓƵ´¦Àí´úÂëÎļþ utils.cpp) #¹¤¾ßÀà´úÂëÎļþ add_executable(SmartVideoMonitor ${SOURCE_FILES}) target_link_libraries(SmartVideoMonitor opencv_core #OpenCVµÄ½¹µã¿â opencv_highgui #OpenCVµÄGUI¿â opencv_video #OpenCVµÄÊÓƵ´¦Àí¿â pthread) #¶àÏß³ÌÖ§³Ö¿â
µÇ¼ºó¸´ÖÆ
Õâ¶Î´úÂë½ç˵ÁËÒ»¸öÃûΪSmartVideoMonitorµÄÏîÄ¿£¬Ö¸¶¨ÁËÖ÷³ÌÐòÎļþ(main.cpp)¡¢ÊÓƵ´¦Àí´úÂëÎļþ(video.cpp)ºÍ¹¤¾ßÀà´úÂëÎļþ(utils.cpp)¡£È»ºóͨ¹ýadd_executable()ÏÂÁÕâЩԴÎļþ±àÒëΪ¿ÉÖ´ÐÐÎļþ¡£
ÔÚ×îºóÒ»ÐеÄtarget_link_libraries()ÖУ¬ÎÒÃÇÁ´½ÓÁËһЩÐèÒªµÄ¿âÎļþ£¬ÈçOpenCVµÄ½¹µã¿â¡¢GUI¿â¡¢ÊÓƵ´¦Àí¿âÒÔ¼°¶àÏß³ÌÖ§³Ö¿âpthread¡£
Èý¡¢Ìí¼ÓĿ¼ºÍÎļþµÄËÑË÷·¾¶£º
ÔÚÏÖʵµÄÏîÄ¿ÖУ¬ÎÒÃÇͨ³£»á½«´úÂëÎļþºÍÍ·Îļþ»®·Ö°²ÅÅÓÚ²î±ðµÄĿ¼ÖУ¬ÎªÁËÄܹ»×¼È·µØÕÒµ½ÕâЩÎļþ£¬ÎÒÃÇÐèÒªÌí¼ÓËÑË÷·¾¶¡£ÒÔÏÂÊÇÌí¼ÓËÑË÷·¾¶µÄʾÀý´úÂ룺
include_directories(include #Í·ÎļþµÄËÑË÷·¾¶ src) #Ô´ÎļþµÄËÑË÷·¾¶
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃǽ«Í·ÎļþĿ¼includeºÍÔ´ÎļþĿ¼srcÌí¼ÓΪËÑË÷·¾¶£¬ÕâÑùÔÚÏîÄ¿ÖÐÒýÓÃÕâЩÎļþʱ£¬CMake¾ÍÄܹ»×Ô¶¯ËÑË÷µ½ËüÃÇ¡£
ËÄ¡¢Ìí¼Ó×ÓĿ¼µÄ¹¹½¨£º
ÔÚÒ»¸ö´óÐÍÏîÄ¿ÖУ¬ÎÒÃÇͨ³£»á½«²î±ðµÄÄ£¿é°²ÅÅÓÚ²î±ðµÄ×ÓĿ¼ÖУ¬ÎªÁËÄܹ»×¼È·µØ¹¹½¨ÕâЩ×ÓĿ¼£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂ룺
add_subdirectory(video) #Ìí¼Óvideo×ÓĿ¼ add_subdirectory(utils) #Ìí¼Óutils×ÓĿ¼
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃÇͨ¹ýadd_subdirectory()ÏÂÁvideo×ÓĿ¼ºÍutils×ÓĿ¼Ìí¼Óµ½ÏîÄ¿ÖС£ÕâÑù£¬CMake¾Í»á½øÈëÕâЩ×ÓĿ¼£¬²éÕÒ²¢¹¹½¨ÏìÓ¦µÄ´úÂëÎļþ¡£
Îå¡¢×Ô½ç˵±àÒëÑ¡Ï
ÓÐʱ£¬ÎÒÃÇÐèÒª×Ô½ç˵һЩ±àÒëÑ¡ÏÒÔÖª×ãÌض¨µÄÐèÇó¡£CMakeÌṩÁËÒ»ÖÖÇáÓ¯µÄ·½·¨À´ÊµÏÖÕâ¸öÄ¿µÄ£¬Ê¾Àý´úÂëÈçÏ£º
option(ENABLE_DEBUG "Enable debug mode" OFF) #½ç˵һ¸öÃûΪENABLE_DEBUGµÄÑ¡ÏĬÈÏ¹Ø±Õ if(ENABLE_DEBUG) add_compile_definitions(DEBUG) #¿ªÆôºê½ç˵DEBUG set(CMAKE_BUILD_TYPE Debug) #ÉèÖù¹½¨ÀàÐÍΪDebugģʽ endif()
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪENABLE_DEBUGµÄÑ¡ÏĬÈϹرա£ÈôÊÇÆôÓÃÁËÕâ¸öÑ¡Ï¾Í»á¿ªÆôÒ»¸öÃûΪDEBUGµÄºê½ç˵£¬²¢½«¹¹½¨ÀàÐÍÉèÖÃΪDebugģʽ¡£ÕâÑù£¬ÎÒÃǾÍÄܹ»Æ¾Ö¤ÐèÒªÀ´¿ªÆô»ò¹Ø±Õµ÷ÊÔģʽ¡£
Áù¡¢×ܽ᣺
ͨ¹ý±¾ÎĵÄÏÈÈÝ£¬ÎÒÃÇÏàʶÁËÔõÑùʹÓÃCMakeÀ´¹¹½¨Ò»¸öÊÊÓÃÓÚLinuxϵͳµÄÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐò£¬²¢·ÖÏíÁËһЩÏà¹ØµÄÉèÖü¼ÇÉ¡£
CMake×÷Ϊһ¸ö¹¦Ð§Ç¿Ê¢ÇÒÒ×ÓÚʹÓõĹ¹½¨ÏµÍ³¹¤¾ß£¬Äܹ»´ó´ó¼ò»¯ÏîÄ¿µÄ¹¹½¨Àú³Ì¡£Í¨¹ýºÏÀíµÄÉèÖúÍÎÞаµÄÑ¡ÏÎÒÃÇÄܹ»¸üºÃµØÊ©Õ¹CMakeµÄÓÅÊÆ£¬Ìá¸ßÏîÄ¿µÄ¿Éά»¤ÐԺͿÉÀ©Õ¹ÐÔ¡£
Ï£Íû±¾ÎÄÄܹ»¶ÔÄúÔÚ¹¹½¨ÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐòʱÓÐËù×ÊÖú£¬²¢Äܹ»Æô·¢ÄúÔÚÏÖʵÏîÄ¿ÖеÄÉèÖÃÀú³Ì¡£Ð»Ð»ÄúµÄÔĶÁ£¡
¸½Â¼£ºÍêÕûµÄCMakeLists.txtÎļþʾÀý
cmake_minimum_required(VERSION 3.10) project(SmartVideoMonitor) set(CMAKE_CXX_STANDARD 11) option(ENABLE_DEBUG "Enable debug mode" OFF) if(ENABLE_DEBUG) add_compile_definitions(DEBUG) set(CMAKE_BUILD_TYPE Debug) message("Enable debug mode") endif() include_directories(include src) set(SOURCE_FILES main.cpp video.cpp utils.cpp) add_subdirectory(video) add_subdirectory(utils) add_executable(SmartVideoMonitor ${SOURCE_FILES}) target_link_libraries(SmartVideoMonitor opencv_core opencv_highgui opencv_video pthread)
µÇ¼ºó¸´ÖÆ
²Î¿¼ÎÄÏ×£º
[CMake Documentation](https://cmake.org/documentation/)
ÒÔÉϾÍÊÇʹÓÃCMake¹¹½¨LinuxÖÇÄÜÊÓƵ¼à¿ØÓ¦ÓóÌÐòµÄÉèÖü¼ÇɵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡