[CMake] Problems with combo CMake/MSVC2013/Qt5

Jakob van Bethlehem jsvanbethlehem at gmail.com
Tue Feb 24 10:48:49 EST 2015


Dear users,

It has been a while since I used CMake and it's the first time I'm using it
on Windows/MSVC2013, so hopefully I'm not missing something obvious. I
tried to create the most basic example that shows the problem.

I'm trying to compile a subfolder of my Qt5 project into a shared library.
The CMakeLists.txt file in the main folder looks like:

  CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
  PROJECT(qtapp)

  set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.4.0/5.4/msvc2013_64_opengl/lib/cmake")
  FIND_PACKAGE(Qt5Widgets REQUIRED)
  FIND_PACKAGE(Qt5Core REQUIRED)
  SET(CMAKE_AUTOMOC ON)
  SET(CMAKE_INCLUDE_CURRENT_DIR ON)

  add_subdirectory(mylib)

  add_executable(mymain WIN32 mymain.cpp)
  target_link_libraries(mymain mylib)

The CMakeLists.txt file in the subfolder looks like this:

  CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
  FILE(GLOB lib_sources *.cpp *.h)
  ADD_LIBRARY(mylib SHARED ${lib_sources})
  TARGET_LINK_LIBRARIES(mylib Qt5::Widgets)

  include(GenerateExportHeader)
  generate_export_header(mylib)

Inside the subfolder I have one header file mylib.h:

  #pragma once
  #include "mylib_export.h"

  class MYLIB_EXPORT MyClass
  {
  public:
      MyClass();

  };

And there is one source file mylib.cpp:

  #include "myclass.h"

  MyClass::MyClass()
  {}

In the main file mymain.cpp in the main folder I try to instantiate an
object:

  #include "mylib/myclass.h"
  int main()
  {
      MyClass klass();
  }

I create a 'build' folder, where I execute 'cmake -G "Visual Studio 12 2013
Win64" ..'; subsequently I open the resulting solution file, which I try to
build.

The problem: for some reason when compiling mymain.cpp I get:
  fatal error C1083: Cannot open include file: 'mylib_export.h': No such
file or directory

I already checked that the build-folder is added as an include directory,
both to the main-project and to the library-project. I already noticed that
compilation will succeed if I #include explicitly from the build directory
inside mylib.h (#include "../build/mylib/mylib_export.h") but that
obviously is not my intention.

What am I doing wrong or what did I miss? Any ideas?

Sincerely,
Jakob van Bethlehem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150224/c8579c5a/attachment.html>


More information about the CMake mailing list