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:

  1. In explorer, navigate to like C:\Program Files (x86)\Windows Kits\10\Include.
  2. 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.
  3. Start cmake to configure the project, it will find the right sdk version.
  4. 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 ..

refer to:
https://www.oschina.net/question/231677_45266

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

refer to: https://bbs.csdn.net/topics/392257691?list=lz