Visual Studio to CMake Mapping

Reference to https://cognitivewaves.wordpress.com/cmake-and-visual-studio/

#
Visual Studio
CMake Command
1 Solution file (.sln) project
2 Project file (.vcproj) target name in the command add_executable or add_library
3 executable (.exe) add_executable
4 static library (.lib) add_library
5 dynamic library (.dll) add_library(SHARED)
6 Source Folders source_group
7 Project Folders set_property(TARGET PROPERTY FOLDER )
8 Properties->C/C++->Preprocessor->Preprocessor Definitions add_definitions
9 Properties->C/C++->General->Additional Include Directories include_directories
10 Properties->Linker->General->Additional Library Directories link_directories
11 Properties->Linker->Input->Additional Dependencies target_link_libraries
12

Sample CMakeList with Qt and OpenCV

project(CameraFramework)
cmake_minimum_required(VERSION 3.2.3)

set(PROJECT_NAME		"CameraFramework")
set(PROJECT_AUTHOR_NAME     	"Vic Huang")
set(PROJECT_VERSION		"1.0.0")

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed. 
set(CMAKE_AUTOMOC ON)

# Set prefix path
set(CMAKE_PREFIX_PATH 	C:/Qt/Qt5.7.0/5.7/msvc2013/lib/cmake/Qt5Widgets)

#INCLUDE_DIRECTORIES($ENV{MY_SDK}/OpenCV/build/include)			
#LINK_DIRECTORIES($ENV{MY_SDK}/OpenCV/build/x86/vc12/lib)


########
# Qt 5 #
########
find_package (Qt5Widgets REQUIRED)

##########
# OpenCV #
##########
set(OpenCV_STATIC OFF)
find_package(OpenCV REQUIRED)
include_directories(C:/Libraries/Opencv/sources/include)

file(GLOB_RECURSE SOURCE_FILES *.cpp)
file(GLOB_RECURSE HEADER_FILES *.h)

add_executable(${CMAKE_PROJECT_NAME}
  ${UI_HEADERS}
  ${SOURCE_FILES}
  ${HEADER_FILES}
)

target_link_libraries(${CMAKE_PROJECT_NAME}
  Qt5::Widgets
  ${OpenCV_LIBS}
)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s