I wanted to make a GD mod using c++, but when it compiles, i get this error:
[cmake] CMake Error at CMakeLists.txt:5 (project):
[cmake] Generator
[cmake]
[cmake] Unix Makefiles
[cmake]
[cmake] does not support platform specification, but platform
[cmake]
[cmake] darwin
[cmake]
[cmake] was specified.
[cmake]
[cmake]
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring incomplete, errors occurred!
my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.3.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(IlliaGDMod VERSION 1.0.0)
# Use GLOB_RECURSE instead of GLOB
# to recursively add all source files
# under src/
file(GLOB SOURCES
src/*.cpp
)
# Set up the mod binary
add_library(${PROJECT_NAME} SHARED ${SOURCES})
if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Geode SDK not found")
else()
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
endif()
set(GEODE_LINK_NIGHTLY ON)
add_subdirectory($ENV{GEODE_SDK} $ENV{GEODE_SDK}/build)
target_link_libraries(${PROJECT_NAME} geode-sdk)
create_geode_file(${PROJECT_NAME})
I used VSCode 1.72.2, compiler clang
Does anyone have any ideas on why this happens?
also, i used the visual studio code cmake tools to compile it
Related
There is top-level project named 'cppserial', which depends on subproject 'cppstreams', which also depends on subproject 'cpputils'.
The file structure of whole project:
cppserial/
|
CMakeLists.txt
src/
|
cppserial/
source files
libs/
|
cppstreams/
|
CMakeLists.txt
libs/
|
cpputils/
|
CMakeLists.txt
src/
|
cpputils/
source files
src/
|
cppstreams/
source files
cppserial CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(cppserial)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE ...sources...)
add_library(${PROJECT_NAME} STATIC ${SOURCE})
add_subdirectory(libs/cppstreams)
target_link_libraries(${PROJECT_NAME} PUBLIC cppstreams)
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
cppstreams CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(cppstreams)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCES ...sources...)
set(HEADERS ...headers...)
set(BOOST_ROOT D:/Development/CXX/Libraries/Boost)
find_package(Boost REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
add_library(${PROJECT_NAME} STATIC ${HEADERS} ${SOURCES})
add_subdirectory(libs/cpputils)
target_link_libraries(${PROJECT_NAME} PUBLIC cpputils)
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
cpputils CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(cpputils)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCES ...sources...)
set(HEADERS ...headers...)
add_library(${PROJECT_NAME} STATIC ${HEADERS} ${SOURCES})
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
Building:
cd build
cmake ..
cmake --build .
Build output:
[main] Configuring folder: cppserial
[proc] Executing command: D:\Software\CMake\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Sd:/Development/CXX/cppserial -Bd:/Development/CXX/cppserial/build -G "Visual Studio 17 2022"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
[cmake] -- The C compiler identification is MSVC 19.33.31630.0
[cmake] -- The CXX compiler identification is MSVC 19.33.31630.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: D:/Software/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: D:/Software/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found Boost: D:/Development/CXX/Libraries/Boost/lib/cmake/Boost-1.80.0/BoostConfig.cmake (found version "1.80.0")
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/Development/CXX/cppserial/build
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64 for D:\Software\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
Compiling output:
MSBuild version 17.3.1+2badb37d1 for .NET Framework
Checking Build System
Building Custom Rule D:/Development/CXX/cppserial/libs/cppstreams/libs/cpputils/CMakeLists.txt
...source files...
cpputils.vcxproj -> D:\Development\CXX\cppserial\build\libs\cppstreams\libs\cpputils\Debug\cpputils.lib
Building Custom Rule D:/Development/CXX/cppserial/libs/cppstreams/CMakeLists.txt
...source files...
cppstreams.vcxproj -> D:\Development\CXX\cppserial\build\libs\cppstreams\Debug\cppstreams.lib
Building Custom Rule D:/Development/CXX/cppserial/CMakeLists.txt
Building Custom Rule D:/Development/CXX/cppserial/CMakeLists.txt
As you can see, only subprojects are being built. There is no cppserial.lib in the build folder.
I can't understand what could i miss.
I am trying to use OpenCV in VS Code.
Here's what I've done:
Installed OpenCV for windows.
Added "C:\opencv\build\x64\vc15\bin","C:\opencv\build\x64\vc15\lib" PATH environment variable.
Here's my CMakeLists.txt file.
cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)
include(CTest)
enable_testing()
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(opencvtest main.cpp)
target_link_libraries( opencvtest ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
But the file throws the following error:
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\TDM-GCC-64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\TDM-GCC-64\bin\x86_64-w64-mingw32-g++.exe -Hc:/Users/Administrator/Desktop/open -Bc:/Users/Administrator/Desktop/open/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- OpenCV ARCH: x64
[cmake] -- OpenCV RUNTIME: mingw
[cmake] -- OpenCV STATIC: OFF
[cmake] CMake Warning at C:/opencv/build/OpenCVConfig.cmake:190 (message):
[cmake] Found OpenCV Windows Pack but it has no binaries compatible with your
[cmake] configuration.
[cmake]
[cmake] You should manually point CMake variable OpenCV_DIR to your build of OpenCV
[cmake] library.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:7 (find_package)
[cmake]
[cmake]
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake] Found package configuration file:
[cmake]
[cmake] C:/opencv/build/OpenCVConfig.cmake
[cmake]
[cmake] but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
[cmake] NOT FOUND.
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
I am trying to run a C++ file in VS Code that includes <opencv2/opencv.hpp>.
As the error suggests, CMake found your OpenCV installation, but it is not compatible. What is it not compatible with? Your compiler. The OpenCV installation is built with MSVC 15 (it also includes a 14 build). You have asked CMake to use MinGW as your compiler. Libraries need to have been built with the same (well, with some leeway) compiler for everything to work.
You have two options:
Build OpenCV yourself with MinGW, or try a third-party MinGW binary distribution of OpenCV. Web searches for "opencv mingw" turn up some
possibilities.
Use the MSVC compiler for your project. Microsoft offers some free versions of its tools. Just be sure to install the optional older toolsets so that you have access to the VC 15 tools to match OpenCV.
So My Workspace Screenshot After Trying a while i cant Get Cmake To find the required packages even after i did everything as shown in vcpkg
cmake_minimum_required(VERSION 3.0.0)
project(TEst VERSION 0.1.0)
include(CTest)
enable_testing()
set(CMAKE_TOOLCHAIN_FILE "N:/Vc-PKG/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(TEst PRIVATE glfw)
add_executable(TEst main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
and my Vcpkg install directory is N:\Vc-PKG\vcpkg
i also added these lines in vscode
"C_Cpp.default.includePath": [
"N:/Vc-PKG/vcpkg/installed/x64-windows/include",
"N:/Vc-PKG/vcpkg/installed/x86-windows/include",
],
"c-cpp-flylint.cppcheck.includePaths": [
"N:\\Vc-PKG\\vcpkg\\installed\\x64-windows\\include",
"N:\\Vc-PKG\\vcpkg\\installed\\x86-windows\\include",
],
"cmake.generator": "MinGW Makefiles",
The output i get For the following is
[main] Configuring folder: Junks
[proc] Executing command: N:\MSYS64\mingw64\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=N:\MSYS64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=N:\MSYS64\mingw64\bin\x86_64-w64-mingw32-g++.exe "-Hl:/Programming Projects/Vs Code/Junks" "-Bl:/Programming Projects/Vs Code/Junks/build" -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake] Could not find a package configuration file provided by "glfw3" with any of
[cmake] the following names:
[cmake]
[cmake] glfw3Config.cmake
[cmake] glfw3-config.cmake
[cmake]
[cmake] Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
[cmake] "glfw3_DIR" to a directory containing one of the above files. If "glfw3"
[cmake] provides a separate development package or SDK, be sure it has been
[cmake] installed.
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "L:/Programming Projects/Vs Code/Junks/build/CMakeFiles/CMakeOutput.log".
[cmake]
Please any help would be much apricated, sry if i made a mistake this is the 1st time i am posting a question.
You can't set CMAKE_TOOLCHAIN_FILE after the call to project(). That's the command responsible for loading the toolchain file in the first place. Move it before the call to project() or better yet: set it at the command line or in a preset.
Also, unless you're actually using CMake 3.0.0, you shouldn't set it as a minimum. CMake is not forwards compatible, so without actually testing it on the minimum version, you have no way of knowing whether it will work that far back.
I am using visual studio code on Ubuntu 20.04 and cmake tools for visual studio code.
I am trying to use opencv in a project. I used vcpkg to build OpenCV and it is installed:
The cmakeList.txt is as follow:
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_TOOLCHAIN_FILE /home/m/vcpkg/scripts/buildsystems/vcpkg.cmake)
project(testcmake VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
add_executable(testcmake main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
I also added this line to setting.json:
{
"cmake.configureOnOpen": false,
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "/home/m/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
}
but when I run cmake, I am getting this error:
[main] Building folder: cmakeTest
[main] Configuring folder: cmakeTest
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=/home/m/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/gcc-9 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/g++-9 -H/home/m/MyData/sourceCode/cmakeTest -B/home/m/MyData/sourceCode/cmakeTest/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/m/MyData/sourceCode/cmakeTest/build/CMakeFiles/CMakeOutput.log".
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake] By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
[cmake] asked CMake to find a package configuration file provided by "OpenCV", but
[cmake] CMake did not find one.
[cmake]
[cmake] Could not find a package configuration file provided by "OpenCV" with any
[cmake] of the following names:
[cmake]
[cmake] OpenCVConfig.cmake
[cmake] opencv-config.cmake
[cmake]
[cmake] Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
[cmake] "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
[cmake] provides a separate development package or SDK, be sure it has been
[cmake] installed.
[cmake]
[cmake]
Why make can not find opencv using vcpkg?
Edit 1
I compiled OpenCV for x64:
opencv4:x64-linux 4.3.0#1 computer vision library
opencv4[dnn]:x64-linux Enable dnn module
opencv4[jpeg]:x64-linux JPEG support for opencv
opencv4[opengl]:x64-linux opengl support for opencv
opencv4[png]:x64-linux PNG support for opencv
opencv4[tiff]:x64-linux TIFF support for opencv
opencv4[webp]:x64-linux WebP support for opencv
opencv:x64-linux 4.3.0 Computer vision library
opencv[dnn]:x64-linux Enable dnn module
opencv[jpeg]:x64-linux JPEG support for opencv
opencv[opengl]:x64-linux opengl support for opencv
opencv[png]:x64-linux PNG support for opencv
opencv[tiff]:x64-linux TIFF support for opencv
opencv[webp]:x64-linux WebP support for opencv
I know that I should set the vcpkg triplets, how can I set it by default so all applications use it instead of putting it in cmake?
Update 2
I set the triplets as following but still getting the same error:
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_TOOLCHAIN_FILE /home/m/vcpkg/scripts/buildsystems/vcpkg.cmake)
set(VCPKG_TARGET_TRIPLET x64-linux CACHE STRING "VCPKG Target Triplet to use")
project(testcmake VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
add_executable(testcmake main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
I've the following CMakeFiles.txt
cmake_minimum_required (VERSION 3.14.0)
project (awfviewer)
message (STATUS "Building project ${PROJECT_NAME}")
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTORCC ON)
find_package (Boost COMPONENTS program_options filesystem REQUIRED)
find_package (Qt5Core REQUIRED)
include_directories (${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS})
set (PROJECT_SRC
main.cpp
)
set (PROJECT_QRC
${CMAKE_CURRENT_SOURCE_DIR}/Resources/awfviewer.qrc
)
add_executable (${PROJECT_NAME} ${PROJECT_SRC} ${PROJECT_QRC})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
qt5_use_modules (${PROJECT_NAME} Widgets Svg)
Building with CMake 3.14.0 I obtain following output:
[cmake] The C compiler identification is MSVC 19.16.27030.1
[cmake] The CXX compiler identification is MSVC 19.16.27030.1
[cmake] Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
[cmake] Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe -- works
[cmake] Detecting C compiler ABI info
[cmake] Detecting C compiler ABI info - done
[cmake] Detecting C compile features
[cmake] Detecting C compile features - done
[cmake] Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
[cmake] Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe -- works
[cmake] Detecting CXX compiler ABI info
[cmake] Detecting CXX compiler ABI info - done
[cmake] Detecting CXX compile features
[cmake] Detecting CXX compile features - done
[cmake] Building project awfviewer
[cmake] Boost version: 1.69.0
[cmake] Found the following Boost libraries:
[cmake] program_options
[cmake] filesystem
[cmake] Boost version: 1.69.0
[cmake] Boost version: 1.69.0
[cmake] Building project connectiontest
[cmake] Looking for pthread.h
[cmake] Looking for pthread.h - not found
[cmake] Found Threads: TRUE
[cmake] Boost version: 1.69.0
[cmake] Found the following Boost libraries:
[cmake] unit_test_framework
[cmake] log
[cmake] system
[cmake] date_time
[cmake] log_setup
[cmake] filesystem
[cmake] thread
[cmake] regex
[cmake] chrono
[cmake] atomic
[cmake] Building project awfconnectiontest
[cmake] Boost version: 1.69.0
[cmake] Found the following Boost libraries:
[cmake] unit_test_framework
[cmake] log
[cmake] system
[cmake] date_time
[cmake] log_setup
[cmake] filesystem
[cmake] thread
[cmake] regex
[cmake] chrono
[cmake] atomic
[cmake] Configuring done
[cmake] CMake Warning (dev) in src/AWFViewer/CMakeLists.txt:
[cmake] Policy CMP0020 is not set: Automatically link Qt executables to qtmain
[cmake] target on Windows. Run "cmake --help-policy CMP0020" for policy details.
[cmake] Use the cmake_policy command to set the policy and suppress this warning.
[cmake] This warning is for project developers. Use -Wno-dev to suppress it.
[cmake]
[cmake] CMake Warning (dev) in src/AWFViewer/CMakeLists.txt:
[cmake] Policy CMP0020 is not set: Automatically link Qt executables to qtmain
[cmake] target on Windows. Run "cmake --help-policy CMP0020" for policy details.
[cmake] Use the cmake_policy command to set the policy and suppress this warning.
[cmake] This warning is for project developers. Use -Wno-dev to suppress it.
[cmake]
[cmake] CMake Warning (dev) in thirdparty/WRibbon/src/WRibbon/CMakeLists.txt:
[cmake] Policy CMP0020 is not set: Automatically link Qt executables to qtmain
[cmake] target on Windows. Run "cmake --help-policy CMP0020" for policy details.
[cmake] Use the cmake_policy command to set the policy and suppress this warning.
[cmake] This warning is for project developers. Use -Wno-dev to suppress it.
[cmake]
[cmake] CMake Warning (dev) in src/AWFViewer/CMakeLists.txt:
[cmake] Policy CMP0020 is not set: Automatically link Qt executables to qtmain
[cmake] target on Windows. Run "cmake --help-policy CMP0020" for policy details.
[cmake] Use the cmake_policy command to set the policy and suppress this warning.
[cmake] This warning is for project developers. Use -Wno-dev to suppress it.
[cmake]
[cmake] CMake Warning (dev) in thirdparty/WRibbon/src/WRibbon/CMakeLists.txt:
[cmake] Policy CMP0020 is not set: Automatically link Qt executables to qtmain
[cmake] target on Windows. Run "cmake --help-policy CMP0020" for policy details.
[cmake] Use the cmake_policy command to set the policy and suppress this warning.
/// repeat many times
[cmake]
[cmake] Generating done
[cmake] CMake Warning:
[cmake] Manually-specified variables were not used by the project:
[cmake]
[cmake] CMAKE_EXPORT_COMPILE_COMMANDS
[cmake]
[cmake]
[build] Starting build
/// Build starts here
I've read the output of cmake --help-policy CMP0020:
Automatically link Qt executables to qtmain target on Windows.
CMake 2.8.10 and lower required users of Qt to always specify a link
dependency to the qtmain.lib static library manually on Windows.
CMake 2.8.11 gained the ability to evaluate generator expressions
while determining the link dependencies from IMPORTED targets. This
allows CMake itself to automatically link executables which link to Qt
to the qtmain.lib library when using IMPORTED Qt targets. For
applications already linking to qtmain.lib, this should have little
impact. For applications which supply their own alternative WinMain
implementation and for applications which use the QAxServer library,
this automatic linking will need to be disabled as per the
documentation.
The OLD behavior for this policy is not to link executables to
qtmain.lib automatically when they link to the QtCore IMPORTED target.
The NEW behavior for this policy is to link executables to qtmain.lib
automatically when they link to QtCore IMPORTED target.
This policy was introduced in CMake version 2.8.11. CMake version
3.14.0 warns when the policy is not set and uses OLD behavior. Use
the cmake_policy command to set it to OLD or NEW explicitly.
.. note::
The ``OLD`` behavior of a policy is
``deprecated by definition``
and may be removed in a future version of CMake.
But I don't understand what I'm doing wrong by using Qt in the CMake project.
How should I modify the CMakelists.txt in order to use Qt properly and remove the warning?
# Jepessen, I tried to replicate your problem and I got your same error. I bypassed the problem by using an older version of CMake, 3.1 in this case, and also I specified that I wanted to use C++ language using CMAKE_CXX_FLAGS with specific directions -std=c++11. You are totally correct about the documentation you mentioned.
When CMake needs to know the behavior to use it checks if this is specified within the project, and if it is not, then CMake sets the OLD behavior as default. As a consequence of that the warning pops up asking the user to take care of that.
I usually try not to include cmake_policy(policy #) as the majority of them are for older versions and consequently some functionalities could be deprecated and substituted by new versions. Of course there could be situations where cmake_policy(SET CMP<####> NEW) and cmake_policy(SET CMP<####> OLD) have to be specifically addressed.
Below is the working code (it compiles on my computer):
cmake_minimum_required (VERSION 3.1)
project (awfviewer)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
message (STATUS "Building project ${PROJECT_NAME}")
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTORCC ON)
find_package (Boost COMPONENTS program_options filesystem REQUIRED)
find_package (Qt5Core REQUIRED)
include_directories (${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/main ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS})
set (PROJECT_SRC)
set (PROJECT_MAIN
main.cpp
)
add_executable (${PROJECT_NAME} ${PROJECT_SRC})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
In this case the only thing I didn't replicate was creating a QRC file but it does not matter for the small example. Usually CMake is able to recognize and accept older versions of CMake itself given the newer version.
The print screen of what I created in this case is
I hope this could be useful for your project