I am using the following cmake file
cmake_minimum_required(VERSION 3.16)
project(Translated01)
find_package(Boost REQUIRED)
find_package(OpenSSL REQUIRED)
set(CMAKE_CXX_STANDARD 14)
add_executable(Translated01 main.cpp)
During CMake configure phase it writes
...
[cmake] -- Check for working CXX compiler: /usr/bin/g++-7 - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found Boost: /opt/boost (found version "1.73.0")
[cmake] -- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1")
[cmake] -- Configuring done
[cmake] -- Generating done
Which proves it is finding boost in /opt/boost.
Unfortunately, during compile it says it can't find include file
[build] ../main.cpp:3:10: fatal error: boost/beast.hpp: No such file or directory
[build] #include <boost/beast.hpp>
[build] ^~~~~~~~~~~~~~~~~
[build] compilation terminated.
Although, file is there
$ ls /opt/boost/boost/beast.hpp
/opt/boost/boost/beast.hpp
So, how to configure boost for CMake correctly?
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.
Why does Cmake find the library but I can't include it?
I am trying to use the gsl library in C++ but I get gsl/gsl_sf_bessel.h: No such file or directory when I run cmake --build even though it says -- Found GSL: /usr/include (found version "2.7.1") in the terminal after running cmake ...
I am using Ubuntu 22.04
I installed gsl with sudo apt-get install libgsl-dev and it is in /usr/include.
I think it might be a problem with the compiler I am using but I'm not sure how to check.
My CMakeLists.txt file
cmake_minimum_required(VERSION 3.5.1)
project(mujoco_gym)
set(CMAKE_CXX_STANDARD 14)
# It prevents the decay to C++98 when the compiler does not support C++14
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# It disables the use of compiler-specific extensions
# e.g. -std=c++14 rather than -std=gnu++14
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
find_package(GSL REQUIRED)
link_libraries(GSL::gsl)
include_directories(${PROJECT_SOURCE_DIR})
file(GLOB SOURCE_FILES mujoco_gym.cpp)
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries (
${CMAKE_PROJECT_NAME}
${GSL_LIBRARIES}
)
My .cpp file.
#include<stdbool.h> //for bool
#include "stdlib.h"
#include "string.h"
#include <iostream>
#include <gsl/gsl_sf_bessel.h>
int main()
{
double x = 5.0;
std::cout << gsl_sf_bessel_j0(x);
return 0;
}
Cmake and build in the terminal
$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/iii/miniconda3/envs/tf/bin/x86_64-conda-linux-gnu-cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/iii/miniconda3/envs/tf/bin/x86_64-conda-linux-gnu-c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Found GSL: /usr/include (found version "2.7.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/iii/.mujoco/mujoco210/sample/build
$ cmake --build . --config Release
[ 50%] Building CXX object CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o
/home/iii/.mujoco/mujoco210/sample/mujoco_gym.cpp:21:10: fatal error: gsl/gsl_sf_bessel.h: No such file or directory
21 | #include <gsl/gsl_sf_bessel.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/mujoco_gym.dir/build.make:76: CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mujoco_gym.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
$
I am new to C++ as well as VSCode, so this issue might have a really simple answer I'm just overlooking. I'm trying to build an application using the Qt library after having loved its PyQt variant, but I cannot get the simplest possible app to launch from the VSCode terminal.
Here's the program I try to build and run:
// main.cpp - I copied and pasted the Qt documentation example after I had Qt import issues
// (which I have since resolved)
#include <iostream>
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
std::cout << "So far";
QApplication qga (argc, argv);
QPushButton btn ("ayo");
btn.show();
return qga.exec();
}
Here's the CMakeLists.txt file that builds the app:
cmake_minimum_required(VERSION 3.16)
project(trial VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_PREFIX_PATH "C:/Qt/6.3.0/mingw_64/")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt6 REQUIRED COMPONENTS Widgets Gui Core)
qt_standard_project_setup()
add_executable(trial main.cpp)
target_link_libraries(trial PRIVATE Qt6::Widgets Qt6::Gui Qt6::Core)
include(CPack)
These are the components I'm using:
VS Code 2017
CMake (extension)
CMake Tools (extension)
Qt tools (extension)
GCC 8.1.0x86_64-w64-mingw32 compiler
Qt 6.3.0
What confuses me is that the program builds seemingly without error - the program finds Qt and throws no error when compiling. But whenever I launch it from the VS Code terminal, nothing happens. No statement is printed nor is any window launched.
In case it helps, here's the output when I try to launch it:
[variant] Loaded new set of variants
[kit] Successfully loaded 5 kits from C:\Users\astro\AppData\Local\CMakeTools\cmake-tools-kits.json
[proc] Executing command: C:\MinGW64\bin\gcc.exe -v
[main] Configuring folder: qttrial
[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:\MinGW64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\MinGW64\bin\g++.exe -Sc:/Users/astro/Desktop/Git/qttrial -Bc:/Users/astro/Desktop/Git/qttrial/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 8.1.0
[cmake] -- The CXX compiler identification is GNU 8.1.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/MinGW64/bin/gcc.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: C:/MinGW64/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Looking for pthread.h
[cmake] -- Looking for pthread.h - found
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
[cmake] -- Check if compiler accepts -pthread
[cmake] -- Check if compiler accepts -pthread - yes
[cmake] -- Found Threads: TRUE
[cmake] -- Performing Test HAVE_STDATOMIC
[cmake] -- Performing Test HAVE_STDATOMIC - Success
[cmake] -- Found WrapAtomic: TRUE
[cmake] -- Found WrapVulkanHeaders: C:/VulkanSDK/1.3.211.0/Include
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Users/astro/Desktop/Git/qttrial/build
[main] Building folder: qttrial trial
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/astro/Desktop/Git/qttrial/build --config Debug --target trial -j 14 --
[build] [ 25%] Automatic MOC and UIC for target trial
[build] [ 25%] Built target trial_autogen
[build] [ 50%] Building CXX object CMakeFiles/trial.dir/trial_autogen/mocs_compilation.cpp.obj
[build] [ 75%] Building CXX object CMakeFiles/trial.dir/main.cpp.obj
[build] [100%] Linking CXX executable trial.exe
[build] [100%] Built target trial
[build] Build finished with exit code 0
Terminal results:
PS C:\Users\astro\Desktop\Git\qttrial\build> ."C:/Users/astro/Desktop/Git/qttrial/build/trial.exe"
PS C:\Users\astro\Desktop\Git\qttrial\build>
I would be immensely grateful to anyone who can point me in a direction to solve this. Given that there are no error messages, I'm lost as to where to start. If any of you guys need any more information, I'll be happy to supply it. :)
Here is my CMakelists.txt:
cmake_minimum_required(VERSION 3.0)
SET(CMAKE_TOOLCHAIN_FILE "/home/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(test)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)
I'm trying to use vcpkg through SET(CMAKE_TOOLCHAIN_FILE ${vcpkg_root}),but it seems that it doesn't work.Here is the error:
[cmake] CMake Error at CMakeLists.txt:5 (find_package):
[cmake] Could not find a package configuration file provided by
[cmake] "unofficial-sqlite3" with any of the following names:
[cmake]
[cmake] unofficial-sqlite3Config.cmake
[cmake] unofficial-sqlite3-config.cmake
I have verify that unofficial-sqlite3-config.cmake does exists in
/home/xxx/vcpkg/packages/sqlite3_x64-linux/share/unofficial-sqlite3/unofficial-sqlite3-config.cmake
I'm using WSL and vscode as IDE, Now I have no idea how to fix it.
I could not reproduce your issue using the following basic CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(test)
find_package(unofficial-sqlite3 REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)
I installed sqlite3 via vcpkg install sqlite3 and ran the build via
$ echo 'int main() { return 0; }' > main.cpp
$ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/build
As you can see, this worked flawlessly. I'm not sure whether setting your CMake policy level to the downright ancient 3.0 is what matters, or if you're using an old vcpkg checkout (I used the most recent commit at time of writing).
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