How to include generated source files in CMake to show them in the IDE?

I created the following CMakeLists.txt, who has two goals (source files Client.cppand Server.cpp, both as a function of the two generated files, namely Printer.hand Printer.cpp. These files are generated from the Printer.iceDesign Ice ZeroC slice2cpp.

cmake_minimum_required(VERSION 3.1.1)
project(IceTest)

set(CMAKE_VERBOSE_MAKEFILE true)

file(GLOB ice_SLICE
    "${PROJECT_SOURCE_DIR}/ice/*.ice"
)

string(REPLACE ".ice" ".h" ice_HDR ${ice_SLICE})
string(REPLACE ".ice" ".cpp" ice_SRC ${ice_SLICE})

file(GLOB server_HDR
    "server/*.h"
)

file(GLOB server_SRC
    "server/*.cpp"
)

file(GLOB client_HDR
    "client/*.h"
)

file(GLOB client_SRC
    "client/*.cpp"
)

find_package(Ice REQUIRED Ice IceUtil)

add_custom_command(
    OUTPUT ${ice_HDR} ${ice_SRC}
    COMMAND ${Ice_SLICE2CPP_EXECUTABLE} ${ice_SLICE}
    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/ice
)

add_custom_target(
    Slice2Cpp
    DEPENDS ${ice_HDR} ${ice_SRC}
    COMMENT "Running Slice2Cpp..."
    SOURCES ${ice_SLICE}
)

add_custom_target(
    IceGenerated
    DEPENDS Slice2Cpp
    SOURCES ${ice_HDR} ${ice_SRC}
)

include_directories(IceTestServer ${PROJECT_SOURCE_DIR}/ice ${PROJECT_SOURCE_DIR}/server ${Ice_INCLUDE_DIRS})
include_directories(IceTestClient ${PROJECT_SOURCE_DIR}/ice ${PROJECT_SOURCE_DIR}/client ${Ice_INCLUDE_DIRS})

add_executable(IceTestServer ${ice_HDR} ${ice_SRC} ${server_HDR} ${server_SRC})
add_executable(IceTestClient ${ice_HDR} ${ice_SRC} ${client_HDR} ${client_SRC})

add_dependencies(IceTestServer IceGenerated)
add_dependencies(IceTestClient IceGenerated)

target_link_libraries(IceTestServer ${Ice_LIBRARIES} pthread)
target_link_libraries(IceTestClient ${Ice_LIBRARIES} pthread)

The directory structure is as follows:

IceTest
|-- CMakeLists.txt
|-- client
    |-- Client.cpp
|-- ice
    |-- Printer.ice
    |-- Printer.cpp    <--- Generated
    |-- Printer.h      <--- Generated
|-- server
    |-- Server.cpp

In my CMakeLists.txt, I tried to include the generated file Printer.hand Printer.cppin the IDE (here, QtCreator). The documentation states that adding a SOURCEScustom target ( IceGenerated) is added to the IDE for convenience. However, this does not apply to my purpose: the generated files are not visible from the IDE (they are generated and added to the executable, though). What am I doing wrong?

+4

All Articles