CMake Nightly Date Stamp
[kiteware-cmake.git] / Tests / QtAutogen / MocIncludeSymlink / CMakeLists.txt
blobcf60555d4132ea6c19a178d8faeb877765c0f4cb
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")
27 # -- Utility macros
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}")
33     endif()
34 endfunction()
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.")
40   return()
41 endif()
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.")
53   return()
54 endif()
57 # -- Building
58 macro(buildMocInclude sourceDir binaryDir)
59   message("Building MocInclude\n  - source dir: ${sourceDir}\n  - binary dir: ${binaryDir}\n")
60   try_compile(result
61     "${binaryDir}"
62     "${sourceDir}"
63     MocInclude
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
71   )
72   if (result)
73     message(STATUS "--- Build success. ---")
74   else()
75     message(STATUS "\n### Building MocInclude failed. ###\n\n--- Output ---\n${output}")
76     message(FATAL_ERROR "--- Building MocInclude failed. End of output. ---")
77   endif()
78 endmacro()
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})