CMakeLists.txt 3.09 KB
Newer Older
1 2
cmake_minimum_required(VERSION 3.11)
project(AutogenOriginDependsOff)
3
include("../AutogenCoreTest.cmake")
4

5 6 7 8 9 10 11 12 13
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# XXX(xcode-per-cfg-src): Enable multi-config code path for Xcode
# when the Xcode generator supports per-config sources.
if(_isMultiConfig AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
  set(mocs_compilation_cpp "mocs_compilation_$<CONFIG>.cpp")
else()
  set(mocs_compilation_cpp "mocs_compilation.cpp")
endif()

14 15 16 17 18 19 20
set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
set(CBD ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CSD})
include_directories(${CBD})

# A GENERATED file ensures there will be an _autogen target in VS
add_custom_command (
21 22
    OUTPUT "${CBD}/config_a.hpp"
    COMMAND ${CMAKE_COMMAND} -E copy "${CSD}/config.hpp.in" "${CBD}/config_a.hpp"
23 24 25 26 27 28 29 30
    )


# Library "a_mc" provides a header that holds a string with the content of
# mocs_compilation.cpp from a_qt.  It therefore must depend on a_qt_autogen.
add_custom_target ( a_mc
    COMMAND ${CMAKE_COMMAND} -E sleep 2
    COMMAND ${CMAKE_COMMAND}
31
        "-DMCF=${CBD}/a_qt_autogen/${mocs_compilation_cpp}"
32 33 34 35 36 37 38 39 40 41
        "-DCF_IN=${CSD}/a_mc.hpp.in"
        "-DCF_OUT=${CBD}/a_mc.hpp"
        -P ${CSD}/configure_content.cmake
    )
add_dependencies ( a_mc a_qt_autogen )

# Library "a_qt"
# - depends on a GENERATED file
# - AUTOMOC enabled
# - depends on a target (a_mc) that depends on a_qt_qutogen
42
add_library ( a_qt a_qt.cpp "${CBD}/config_a.hpp" )
43 44 45 46 47 48
add_dependencies ( a_qt a_mc )
target_link_libraries ( a_qt ${QT_QTCORE_TARGET})
set_target_properties ( a_qt PROPERTIES AUTOMOC TRUE)
# Disable AUTOGEN_ORIGIN_DEPENDS to avoid loop dependencies
set_target_properties ( a_qt PROPERTIES AUTOGEN_ORIGIN_DEPENDS OFF)

49 50 51 52 53
# A GENERATED file ensures there will be an _autogen target in VS
add_custom_command (
    OUTPUT "${CBD}/config_b.hpp"
    COMMAND ${CMAKE_COMMAND} -E copy "${CSD}/config.hpp.in" "${CBD}/config_b.hpp"
    )
54 55 56 57 58 59 60 61 62

# Library "b_mc" provides a header that holds a string function that returns
# the content of mocs_compilation.cpp from b_qt.
# It therefore must depend on b_qt_autogen.
add_custom_command (
    OUTPUT ${CBD}/b_mc.cpp
    DEPENDS b_qt_autogen
    COMMAND ${CMAKE_COMMAND} -E sleep 2
    COMMAND ${CMAKE_COMMAND}
63
        "-DMCF=${CBD}/b_qt_autogen/${mocs_compilation_cpp}"
64 65 66 67 68 69 70 71 72 73
        "-DCF_IN=${CSD}/b_mc.cpp.in"
        "-DCF_OUT=${CBD}/b_mc.cpp"
        -P ${CSD}/configure_content.cmake
    )
add_library ( b_mc ${CSD}/b_mc.hpp ${CBD}/b_mc.cpp )

# Library "b_qt"
# - depends on a GENERATED file
# - AUTOMOC enabled
# - depends on a library (b_mc) that depends on b_qt_qutogen
74
add_library ( b_qt b_qt.cpp "${CBD}/config_b.hpp" )
75 76 77 78 79 80 81 82 83 84 85
target_link_libraries ( b_qt b_mc )
target_link_libraries ( b_qt ${QT_QTCORE_TARGET})
set_target_properties ( b_qt PROPERTIES AUTOMOC TRUE)
# Disable AUTOGEN_ORIGIN_DEPENDS to avoid loop dependencies
set_target_properties ( b_qt PROPERTIES AUTOGEN_ORIGIN_DEPENDS OFF)


# The main target depends on both libraries which depend on the _autogen
# target of the main target.
add_executable ( autogenOriginDependsOff main.cpp )
target_link_libraries ( autogenOriginDependsOff a_qt b_qt )