1. 程式人生 > >編寫支援多個編譯器的CMakeLists.txt

編寫支援多個編譯器的CMakeLists.txt

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.0)

# in CMakeLists.txt root_dir: "mkdir build", "cd build", "cmake .."

set(PROJECT_NAME "face_landmarks_demo")

project(${PROJECT_NAME})
set(CMAKE_CONFIGURATION_TYPES "Release")
set(CMAKE_BUILD_TYPE Release)

if(MSVC)
    add_compile_options(-O2)
endif
() #cmake_policy(SET CMP0015 NEW) if(MSVC14) add_compile_options(-std=c++11) # mv exe file to bin_vs2015 dir, not bin_vs2015/Release # or mv bin_vs2015/* to bin_vs2015/Release set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin_vs2015") include_directories( include 3rdparty/opencv340/include
3rdparty/opencv340/include/opencv 3rdparty/opencv340/include/opencv2 3rdparty/dlib-19.9/include ) link_directories( ../3rdparty/opencv340/vs2015/x86/lib ../3rdparty/dlib-19.9/vs2015/x86/lib ) add_executable(${PROJECT_NAME} src/face_landmarks_demo.cpp src/face_landmarks.cpp src/face_detection.cpp) target_link_libraries
(${PROJECT_NAME} dlib opencv_core340 opencv_highgui340 opencv_imgcodecs340 opencv_imgproc340 opencv_ml340 opencv_objdetect340 opencv_videoio340) elseif(MSVC10) # MSVC10 BUG: need define NOMINMAX to solve compile error add_definitions(-DNOMINMAX) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin_vs2010") include_directories( include 3rdparty/opencv2410/include 3rdparty/opencv2410/include/opencv 3rdparty/opencv2410/include/opencv2 3rdparty/dlib-19.1/include ) link_directories( ../3rdparty/opencv2410/vs2010/x86/lib ../3rdparty/dlib-19.1/vs2010/x86/lib ) # add_executable should before target_link_libraries, and after link_directories or include_directories, not sure, otherwise, link_directories will failed in Visual Studio add_executable(${PROJECT_NAME} src/face_landmarks_demo.cpp src/face_landmarks.cpp src/face_detection.cpp) target_link_libraries(${PROJECT_NAME} dlib opencv_core2410 opencv_highgui2410 opencv_imgproc2410 opencv_ml2410 opencv_objdetect2410) endif()