Hellhound
Hellhound

Reputation: 531

How to add CMake includes and libraries to Visual Studio Solution?

I use CMake to generate a Visual Studio 2010 project and solution file. Actually I could set different settings, like warning level, incremental building flag ect. from CMake. But I can't set additional includes and libraries, listed in the VC++ Directory configuration tab. Actually I've to set up those directories manually. This is stupid and boring...

I tried to set the following CMake variables: CMAKE_INCLUDE_PATH, INCLUDE_DIRECTORY but nothing happend. If i open the project, the additional include directory of the solution is always empty (only standard MSVE settings are given).

I also tired to set this variables after executable creation, but this has also no effect.

This is what i do directly in the header of the cmake file:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(${MODULE_NAME})
IF (MSVC)
   # Activate C++ exception handling
   IF (NOT CMAKE_CXX_FLAGS MATCHES "/EHsc")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") 
   ENDIF ()

   # Set Warning level always to 4
   IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
     string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
   ELSE ()
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
   ENDIF ()

   #read path of dependency modules  
   file(READ "msvc.deps" MSVC_PROPERTIES)
   STRING(REGEX REPLACE ";" "\\\\;" MSVC_PROPERTIES "${MSVC_PROPERTIES}")
   STRING(REGEX REPLACE "\n" ";" MSVC_PROPERTIES "${MSVC_PROPERTIES}")

   FOREACH(e ${MSVC_PROPERTIES})
     SET(INCLUDE ${INCLUDE} ${e})
     MESSAGE(STATUS "[INFO]: Value ${e}")
   ENDFOREACH(e)
   INCLUDE_DIRECTORIES(${INCLUDE})
ENDIF ()

In the .deps file I've added to path of my dependeny modules, line separated:

c:\binrev\development\boost\1.47\includes
c:\binrev\repository\modules\brCore\trunk\includes

Both are read successfully but couldn't be set as additional include directory in my MSVC solution.

Best regards, Hellhound

Upvotes: 13

Views: 35650

Answers (3)

Xu Cao
Xu Cao

Reputation: 21

Yes. Although it does not appear in "Include Directories" under the "VC++ Directories" tab, it does show up in the "Additional Include Directories" under C/C++ -> General.

Upvotes: 1

Adam Bowen
Adam Bowen

Reputation: 11230

CMake is pretty well documented, if I have understood your question then the commands I think you're looking for are

Although some configuration is done by setting variables, most of it is done using commands to add certain information to parts of the build and slightly less frequently by setting properties on targets.

Upvotes: 10

wilx
wilx

Reputation: 18228

I believe that include_directories ("path") somewhere in the CMakeLists.txt does add the path to C++ includes path.

Upvotes: 2

Related Questions