1 cmake_minimum_required(VERSION 3.16)
2 project(MocIncludeSymlink)
3 get_filename_component(AUTOGEN_CORE_TEST_CMAKE "../AutogenCoreTest.cmake" ABSOLUTE)
4 include("${AUTOGEN_CORE_TEST_CMAKE}")
7 # Tests if MocInclude can be build when
8 # - The source directory is a symbolic link
9 # - The build directory is a symbolic link
12 # -- Utility variables
13 set(CS_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
14 set(CB_DIR "${CMAKE_CURRENT_BINARY_DIR}")
16 # Absolute MocInclude path
17 get_filename_component(MocIncludePath "../MocInclude" ABSOLUTE)
18 message("MocIncludePath: ${MocIncludePath}")
20 # Use nested subdirectories to ensure relatives paths are correct as well
21 set(BUILD_DIR_NORMAL "${CB_DIR}/Build/Normal")
22 set(BUILD_DIR_LINKED "${CB_DIR}/Build/Linked")
24 set(SL_SOURCE_DIR "${CB_DIR}/SL_Source")
25 set(SL_BUILD_DIR "${CB_DIR}/SL_Build")
28 function(makeSymLink origin link)
29 message("Creating symbolic link\n Link: ${link}\n To: ${origin}")
30 file(CREATE_LINK ${origin} ${link} RESULT res SYMBOLIC)
31 if(NOT (${res} STREQUAL "0"))
32 message("Symlink creation failed.\n Link: ${link}\n To: ${origin}\n Result: ${res}")
36 # -- Make source directory symlink
37 makeSymLink(${MocIncludePath} ${SL_SOURCE_DIR} linkResult)
38 if(NOT EXISTS ${SL_SOURCE_DIR})
39 message("Directory symlink can't be created. Skipping test.")
43 # -- Make normal build directory
44 file(REMOVE_RECURSE ${BUILD_DIR_NORMAL})
45 file(MAKE_DIRECTORY ${BUILD_DIR_NORMAL})
47 # -- Make linked build directory and symlink
48 file(REMOVE_RECURSE ${BUILD_DIR_LINKED})
49 file(MAKE_DIRECTORY ${BUILD_DIR_LINKED})
50 makeSymLink(${BUILD_DIR_LINKED} ${SL_BUILD_DIR} linkResult)
51 if(NOT EXISTS ${SL_BUILD_DIR})
52 message("Directory symlink can't be created. Skipping test.")
58 macro(buildMocInclude sourceDir binaryDir)
59 message("Building MocInclude\n - source dir: ${sourceDir}\n - binary dir: ${binaryDir}\n")
64 CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
65 "-DCMAKE_AUTOMOC_PATH_PREFIX=ON"
66 "-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
67 "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}"
68 "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
69 "-DAUTOGEN_CORE_TEST_CMAKE:STRING=${AUTOGEN_CORE_TEST_CMAKE}"
70 OUTPUT_VARIABLE output
73 message(STATUS "--- Build success. ---")
75 message(STATUS "\n### Building MocInclude failed. ###\n\n--- Output ---\n${output}")
76 message(FATAL_ERROR "--- Building MocInclude failed. End of output. ---")
80 message("\nTry building with\n - symbolic link source dir\n - non symbolic build dir\n")
81 buildMocInclude(${SL_SOURCE_DIR} ${BUILD_DIR_NORMAL})
83 message("\nTry building with\n - symbolic link source dir\n - symbolic link build dir\n")
84 buildMocInclude(${SL_SOURCE_DIR} ${SL_BUILD_DIR})