4

I have created a simple library project in C++ and added CMake file to automatically generate a Visual Studio project. My small project contains only 2 files:

include/
     testproject/
         testproject.h
src/
    testproject.cpp

CMakeLists.txt

Header file now in External Dependencies (screenshot). How to display it in the section "Headers"? (or any other. Just not "External Dependencies")

CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(PROJECTNAME testproject)

PROJECT(${PROJECTNAME})

FILE(GLOB MY_HEADERS "include/*.h")
FILE(GLOB MY_SOURCES "src/*.cpp")

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
ADD_LIBRARY(
    ${PROJECTNAME} STATIC
    ${MY_HEADERS} ${MY_SOURCES}
)

Note: If change dirs struct to

include/
     testproject.h
src/
    testproject.cpp

CMakeLists.txt

result will be like on a screenshot. Header file in "Header files". But I need in previous project structure

Valeriy
  • 1,365
  • 3
  • 18
  • 45

1 Answers1

4

Use GLOB_RECURSE:

GLOB_RECURSE will generate a list similar to the regular GLOB, except it will traverse all the subdirectories of the matched directory and match the files. Subdirectories that are symlinks are only traversed if FOLLOW_SYMLINKS is given or cmake policy CMP0009 is not set to NEW. See cmake –help-policy CMP0009 for more information.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(PROJECTNAME testproject)

PROJECT(${PROJECTNAME})

FILE(GLOB_RECURSE MY_HEADERS "include/*.h")
FILE(GLOB MY_SOURCES "src/*.cpp")

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
ADD_LIBRARY(
    ${PROJECTNAME} STATIC
    ${MY_HEADERS} ${MY_SOURCES}
)
Valeriy
  • 1,365
  • 3
  • 18
  • 45