[Qt-creator] Howto make qt-creator list the header files in the project tree for cmake in CMakelists.txt

Campbell Barton ideasman42 at gmail.com
Fri Nov 5 05:13:53 CET 2010


On Tue, Nov 2, 2010 at 10:23 AM, Daniel Teske <daniel.teske at nokia.com> wrote:
>> Now, if I do
>>
>> file(GLOB HEADERS "include/*.hpp")
>>
>>
>> add_executable( ${BIN} test/main.cpp ${HEADERS} )
>
>> It works but it does not feel like the optimal solution.
>>
>>
>> Is there a better way of doing this?
> Not really. Creator's cmake support relies on cmake knowing the headers.
>
> daniel

Hi, recently I ran into this as well.
we have a macro for adding libs which deals with this for msvc (with
grouping) and qt-creator.
While I'd rather not use this macro it does work well.

Ignore the _NOLIST suffix.
to see this in context its in blenders source dir:
build_files/cmake/macros.cmake

  MACRO(BLENDERLIB_NOLIST
    name
    sources
    includes)

    MESSAGE(STATUS "Configuring library ${name}")

    # Gather all headers
    FILE(GLOB_RECURSE INC_ALL *.h)

    INCLUDE_DIRECTORIES(${includes})
    ADD_LIBRARY(${name} ${INC_ALL} ${sources})

    # Group by location on disk
    SOURCE_GROUP(Files FILES CMakeLists.txt)
    SET(ALL_FILES ${sources} ${INC_ALL})
    FOREACH(SRC ${ALL_FILES})
      STRING(REGEX REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "Files" REL_DIR "${SRC}")
      STRING(REGEX REPLACE "[\\\\/][^\\\\/]*$" "" REL_DIR "${REL_DIR}")
      STRING(REGEX REPLACE "^[\\\\/]" "" REL_DIR "${REL_DIR}")
      IF(REL_DIR)
        SOURCE_GROUP(${REL_DIR} FILES ${SRC})
      ELSE(REL_DIR)
        SOURCE_GROUP(Files FILES ${SRC})
      ENDIF(REL_DIR)
    ENDFOREACH(SRC)
  ENDMACRO(BLENDERLIB_NOLIST)


-- 
- Campbell



More information about the Qt-creator-old mailing list