Issue
I'm porting my codes onto windows which is built and ran on Ubuntu(with cmake in qt 5.15.1). In my project, I want to build my main source files into libraries and then link it into executable(meaningful when we are cooperating in a large project).
Environment:
Windows10 64bits
Visual Studio 2019
Cmake 3.18.1
Qt 5.15.1
However the cmake complains some errors:
Running D:\Qt\Tools\CMake_64\bin\cmake.exe -S E:/test/test -B E:/test/build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug in E:\test\build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug.
-- Configuring done
-- Generating done
-- Build files have been written to: E:/test/build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug
Elapsed time: 00:00.
Running D:\Qt\Tools\CMake_64\bin\cmake.exe -S E:/test/test -B E:/test/build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug in E:\test\build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug.
-- Configuring done
CMake Error in CMakeLists.txt:
Attempt to add a custom rule to output
E:/test/build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/test_autogen/timestamp.rule
which already has a custom rule.
CMake Error in CMakeLists.txt:
Cannot find source file:
E:/test/build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/CMakeFiles/test_autogen_timestamp_deps
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
CMake Error in CMakeLists.txt:
Cannot find source file:
E:/test/build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/CMakeFiles/test_autogen
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
"test" of type STATIC_LIBRARY
depends on "Test_autogen_timestamp_deps" (strong)
depends on "Test_autogen" (strong)
"Test_autogen_timestamp_deps" of type UTILITY
depends on "test" (strong)
"Test_autogen" of type UTILITY
depends on "Test_autogen_timestamp_deps" (strong)
At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries.
CMake Generate step failed. Build files cannot be regenerated correctly.
CMake process exited with exit code 1.
Elapsed time: 00:00.
Here I notice that timestamp
and a cycle link
problem, but they are not created or needed by me on myself side(Maybe they are auto generated by qt?).
To reproduce that problem, you only need to create a minimal default desktop application program with QtCreator, named Test, built by cmake
. And using following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.5)
project( Test LANGUAGES CXX)
set( TEST_SDK test)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
include_directories( ${Qt5Widgets_INCLUDE_DIRS} )
add_library(${TEST_SDK} mainwindow.cpp mainwindow.h mainwindow.ui)
target_link_libraries(${TEST_SDK} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
add_executable( ${PROJECT_NAME} main.cpp)
target_link_libraries( ${PROJECT_NAME} ${TEST_SDK})
Until now, run Cmake
in QtCreator, these errors will show up. In conclusion, there are two main errors:
Attempt to add a custom rule to output
E:/test/build-test-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/test_autogen/timestamp.rule
which already has a custom rule.
and
At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries.
...
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
...
Solution
Ok, finally, I solve this problem by a really accidental way. And I think my initial question is somehow not suitable for my true problem, so I will updated my question and relative contents.
The reason behind this problem is the same name between that of executable and of library (in this questioned case). To make it pass through cmake building process, just change the TEST_SDK
name to any other name(as long as it is different from that executable name), such as changing from test
to test_sdk
:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project( Test LANGUAGES CXX)
set( TEST_SDK test_sdk) # we only need to change this line
...
I don't dig into the reason, but here I think two names(here are Test
for executable and test
for library) are the same on windows?
Answered By - user6709725