Ask Your Question
1

Create CMake file from Visual Studio Project

asked 2015-03-02 09:23:35 -0600

RiSaMa gravatar image

updated 2015-03-02 09:29:51 -0600

I have finished a project developed in Visual Studio 2013 (Windows) using OpenCV. Now, my manager told me he needs the code files and the CMAKE file.

I'm reading this documents:

but I don't understand properly and I don't know if they are what I need...

I can explain a little bit more my project: My project has:

  • main.cpp
  • Some .cpp created by myshelf.
  • Some .h created by myshelf.
  • I use OpenCV libraries (lib, dll, ...).
  • I use Vimba libraries (lib, dll, ...).

I have never worked with CMAKE files... Could anyone lead me about how create this file/s?? I'm really missed...

THANKS in advance!!! Any help is welcome!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-03-03 01:39:17 -0600

LBerger gravatar image

updated 2015-03-03 04:31:02 -0600

Hi, I give you my cmakefiles for my apllication using opencv openscenegraph plplot. I don't know if it's a good example but it works for me : VS2012 32 and 64 bits and linux mint

find_package(OpenSceneGraph  3.2.1 REQUIRED osgDB osgUtil osgGA osgViewer osgText osgSim)
find_package(OpenCV  REQUIRED)
find_package(wxWidgets COMPONENTS core base net adv aui html  qa richtext stc ribbon xml gl REQUIRED)
find_package(PLplot  REQUIRED)

cmake_minimum_required(VERSION 2.8)

PROJECT (wxOpenCVMain)

set (wxOpenCV_VERSION_MAJOR 0)
set (wxOpenCV_VERSION_MINOR 0)

file(GLOB wxOpenCVMain_SRCS
    "*.h"
    "*.cpp"
    toolbar.rc)
ADD_EXECUTABLE (wxOpenCVMain ${wxOpenCVMain_SRCS})

configure_file (
    "${PROJECT_SOURCE_DIR}/wxOpenCVConfig.h.in"
    "${PROJECT_SOURCE_DIR}/wxOpenCVConfig.h"
    )

if (wxWidgets_FOUND)
    include_directories(${wxWidgets_INCLUDE_DIRS})
    target_link_libraries (wxOpenCVMain ${wxWidgets_LIBRARIES} )
endif (wxWidgets_FOUND)
if (OPENSCENEGRAPH_FOUND)
    include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
    target_link_libraries (wxOpenCVMain ${OPENSCENEGRAPH_LIBRARIES} )

endif (OPENSCENEGRAPH_FOUND)
message("OPENCV = ${OpenCV_INCLUDE_DIRS}")
if (OpenCV_FOUND)
    include_directories( ${OpenCV_INCLUDE_DIRS} )
#   include_directories("${OPENCV_CONFIG_PATH}/include")
    target_link_libraries( wxOpenCVMain ${OpenCV_LIBS} )
else (OpenCV_FOUND)
message("PB->OPENCV = ${OpenCV_INCLUDE_DIRS}")
endif (OpenCV_FOUND)
if (PLplot_FOUND)
    include_directories(${PLplot_INCLUDE_DIR})
    target_link_libraries (wxOpenCVMain ${PLplot_wxwidgets_LIBRARY} ${PLplot_cxx_LIBRARY} )
endif (PLplot_FOUND)

IF(WIN32) # Check if we are on Windows
    message( STATUS         "WINDOWS")
    if(MSVC) # Check if we are using the Visual Studio compiler
        set_target_properties(wxOpenCVMain PROPERTIES  COMPILE_DEFINITIONS "")
    message( STATUS         "${WX_LIB_DIR}")
        IF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
            SET(wxWidgets_DEFINITIONS WXUSINGDLL)
            DBG_MSG_V("detected SHARED/DLL tree WX_LIB_DIR=${WX_LIB_DIR}")
        ENDIF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")

        if  (CMAKE_CL_64)
            set_target_properties(wxOpenCVMain PROPERTIES  COMPILE_DEFINITIONS "${wxWidgets_DEFINITIONS};__WXMSW__;_CRT_SECURE_NO_WARNINGS")
        else()
            set_target_properties(wxOpenCVMain PROPERTIES  COMPILE_DEFINITIONS "${wxWidgets_DEFINITIONS};__WXMSW__;_CRT_SECURE_NO_WARNINGS")
        endif()
        set_target_properties(wxOpenCVMain PROPERTIES LINK_FLAGS_DEBUG "/FORCE:MULTIPLE /SUBSYSTEM:WINDOWS")
        set_target_properties(wxOpenCVMain PROPERTIES LINK_FLAGS_RELEASE  "/SUBSYSTEM:WINDOWS /FORCE:MULTIPLE")     
    else()
        if (NOT CMAKE_COMPILER_IS_GNUCXX)
            message (SEND_ERROR  "You are using an unsupported Windows compiler! (Not MSVC or GCC)")
        endif()
    endif()
else()
    if(UNIX)
        set_target_properties(wxOpenCVMain PROPERTIES  COMPILE_DEFINITIONS "__WXGTK__")
    else()
        message ("You are on an unsupported platform! (Not Win32 or Unix)")
    endif()
endif()

If you want to include a library which is not known by CMAKE you have to look in share\cmake-3.0\Modules. Example CMake does not know LibreOfficeSDK I have write this line in CmakeList.txt

set(LOSDK $ENV{LibreOfficeSDK})

FIND_PATH(
  LOSDK_INCLUDE_DIR
  NAMES main.h 
  PATHS /usr/local/include /usr/include  ${LOSDK}/include/sal
)

Again I'm not a specialist of Cmake may be you should ask you question on cmake Forum

edit flag offensive delete link more

Comments

Thanks for your answer. It was usefull but I have a problem Vimba libraries doesn't work with find_package.... I have code files, and libraries (dll, lib). How can write the proper lines for include this vimba libraries??

THANKS!!!

RiSaMa gravatar imageRiSaMa ( 2015-03-03 04:06:45 -0600 )edit

I have achieve create the makeFile. It's working properly in Windows. I execute cmake and from the code files it create the visual studio project properly and it works fine.

BUT when I try to execute the make command in LINUX I get errors :S: *In function ..... error: 'infinity' des not name a type const auto.... *.... error: 'infinity' was not declared in this scope *.... error: 'infinity' was not declared in this scope *.... error: 'infinity' was not declared in this scope

The line where is the problem is this one:

const auto infinity = std::numeric_limits<int>::infinity();

It's a line from this project: https://github.com/soimy/munkres-open...

I think the problem is defining a infinity limit... Could anyone lead me to solve this problem?

THANKS!!!

RiSaMa gravatar imageRiSaMa ( 2015-03-04 04:59:21 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-03-02 09:23:35 -0600

Seen: 1,073 times

Last updated: Mar 03 '15