Reputation: 139
I have a problem concerning the compilation of a program. I don't know why the same CMakeLists.txt is compiling in QTcreator and not in Visual Studio. I am using the exact same compiler which is MinGW for Windows. I have read the documentation, it compiles well EXCEPT if use a translation file untitled_fr_FR.ts.
Please see the CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
#---------------------------------------------------------------------
# I ADD THIS ONE TO COMPILE IN VSCODE AS ASKED IN THE DOCUMENTATION
#---------------------------------------------------------------------
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\Qt\\5.15.0\\mingw81_64")
#---------------------------------------------------------------------
project(untitled LANGUAGES CXX)
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(Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
set(TS_FILES untitled_fr_FR.ts)
add_executable(untitled
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
${TS_FILES}
)
target_link_libraries(untitled PRIVATE Qt5::Widgets)
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
This code works well in QTCreator but gives me this error in VSCode:
[main] Building folder: untitled
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/remi/Desktop/ok/untitled/build --config Debug --target all -- -j 6
[build] [ 16%] Automatic MOC and UIC for target untitled
[build] [ 16%] Built target untitled_autogen
[build] mingw32-make.exe[2]: *** No rule to make target '../', needed by '../untitled_fr_FR.ts'. Stop.
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:95: CMakeFiles/untitled.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:103: all] Error 2
[build] Build finished with exit code 2
***** No rule to make target '../', needed by '../untitled_fr_FR.ts'. Stop.**
How can I solve this one? How can I figure out what QTCreator is changing in the CMake file/env to compile the .ts file?
Thanks a lot for your help, hope I'm clear and I don't bother you.
Upvotes: 2
Views: 966
Reputation: 139
The best way to include translation is not using this method. The CMakeLists.txt to compile the program is :
cmake_minimum_required(VERSION 3.5)
#---------------------------------------------------------------------
# I ADD THIS ONE TO COMPILE IN VSCODE AS ASKED IN THE DOCUMENTATION
#---------------------------------------------------------------------
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\Qt\\5.15.0\\mingw81_64")
#---------------------------------------------------------------------
project(untitled LANGUAGES CXX)
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(Qt5 COMPONENTS Widgets REQUIRED)
add_executable(untitled
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
target_link_libraries(untitled PRIVATE Qt5::Widgets)
If you want to compile it (out of the Qt environment you will need to use this one :
cmake_minimum_required(VERSION 3.5)
#---------------------------------------------------------------------
# I ADD THIS ONE TO COMPILE IN VSCODE AS ASKED IN THE DOCUMENTATION
#---------------------------------------------------------------------
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\Qt\\5.15.0\\mingw81_64")
#---------------------------------------------------------------------
project(untitled LANGUAGES CXX)
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(Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
set(TS_FILES mainwindow.ts)
add_executable(untitled
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
${TS_FILES}
)
target_link_libraries(untitled PRIVATE Qt5::Widgets)
qt5_create_translation(QM_FILES ${TS_FILES})
And rename untitled_fr_FR.ts in mainwindow.ts
Upvotes: 1