Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 414
Hellhound Avatar asked Jan 16 '12 11:01

Hellhound


People also ask

How do I add a library to CMake project?

To add a library in CMake, use the add_library() command and specify which source files should make up the library. Rather than placing all of the source files in one directory, we can organize our project with one or more subdirectories. In this case, we will create a subdirectory specifically for our library.

How do I use CMake code in Visual Studio?

Open the Command Palette (Ctrl+Shift+P) and run the CMake: Build command, or select the Build button from the Status bar. You can select which targets you'd like to build by selecting CMake: Set Build Target from the Command Palette. By default, CMake Tools builds all targets.

What does CMake include do?

Load and run CMake code from a file or module. Loads and runs CMake code from the file given. Variable reads and writes access the scope of the caller (dynamic scoping).


2 Answers

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

  • include_directories(...),
  • link_directories(...) and
  • target_link_libraries(...).

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.

like image 153
Adam Bowen Avatar answered Sep 22 '22 12:09

Adam Bowen


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

like image 20
wilx Avatar answered Sep 20 '22 12:09

wilx