1 | target_link_libraries(exeProj1 dl) |
cmake
CMake Qt::Core
In a CMakeLists.txt, a standard name for a Qt component is like Qt6::Core or Qt5::Core. But we should see some projects' CMakeLists.txt contains like Qt::Core, it's a technology for generalization. However, the Qt where we can use this technic must be above Qt 5.15!
refer to:
https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html
Select Windows SDK version when building using cmake
Read cmake online doc carefully, https://cmake.org/cmake/help/latest/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.html
So when we build project which has CMakeLists.txt, we can select Windows SDK version in this way:
- In explorer, navigate to like C:\Program Files (x86)\Windows Kits\10\Include.
- For cmake always finds the newest version to build our project, we can just rename all sdk versions which is newer than we want. e.g. if we want 10.0.19041.0 to build our project, but 10.0.22581.0 is newer, we rename 10.0.22581.0 to 10.0.0.22581.0, the rule is among tokens split by period signs, the third token number is the key word that cmake sorts them to get the largest as newest.
- Start cmake to configure the project, it will find the right sdk version.
- After cmake is done in configuration, rename 10.0.0.22581.0 back to 10.0.22581.0.
Disable features in cmake command line
Identical to "./configure --help", when a project uses cmake, we get building instructions like below,
1 2 3 4 | mkdir bld cd bld cmake .. cmake . -L |
wait a while we will see all the variables cmake defined in cache.
Or directly look into CMakeCache.txt.
If we want to modify a variable to off, or say, disable some functionality,
1 | FEATURE_test_name:BOOL=ON |
we run cmake once again like this,
1 | cmake -DFEATURE_test_name:BOOL=OFF .. |
android cmake命令行
ninja这个工具是google的cmake特有的一个工具,不能用CMake官网下载安装的cmake编译安卓程序。
1 2 3 4 5 6 7 8 9 10 | set SDK_PATH=E:\euhat\android-sdk set path=%SDK_PATH%\cmake\3.10.2.4988404\bin;%path% cd app mkdir manBuild cd manBuild cmake -DANDROID_ABI=armeabi-v7a -DANDROID_STL=c++_shared -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-s" -DANDROID_PLATFORM=android-27 -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=%SDK_PATH%\ndk-bundle -DCMAKE_TOOLCHAIN_FILE=%SDK_PATH%\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_GENERATOR=Ninja .. ninja |
unresolved external symbol _initializeWinsockIfNecessary
这个问题很无语,说一种原因,在用cmake写CMakeLists.txt编译live555时,
1 | project(Project01 CXX C) |
看见没?project关键字后少写了一个C,就不会编译纯C的代码。