Using CMake
CMake can be used to build more complex projects in build.sh
or bld.bat scripts.
If you are using CMake, be sure to make it a build requirement in the build section. You
may also need to include make or ninja depending on your platform and build tools.
On Windows, nmake can also be used, but that is not explicitly included.
- v0 (meta.yaml)
- v1 (recipe.yaml)
requirements:
build:
- cmake
- ninja # [win]
- make # [not win]
requirements:
build:
- cmake
- if: win
then: ninja
else: make
For CMake projects using the FindPython
module, you can tell CMake which Python to use by passing -DPython_EXECUTABLE="$PYTHON"
(macOS or Linux) or -DPython_EXECUTABLE="%PYTHON%" (Windows) as a command line option.
Older CMake projects may require similar, but slightly different options.
Don't forget that depending on which CMake module is used, you have to use a different option:
- FindPython:
-DPython_EXECUTABLE=.... - FindPython3:
-DPython3_EXECUTABLE=.... - FindPython2:
-DPython2_EXECUTABLE=....
or if you are still on the deprecated FindPythonLibs: -DPYTHON_EXECUTABLE=....
Some optional, but useful CMake options:
-DCMAKE_BUILD_TYPE=ReleaseConfigure as release build. This is better done on the initialcmakecall as some packages construct different build configurations depending on this flag.-DCMAKE_INSTALL_PREFIX=$PREFIXSpecify the install location.-DCMAKE_INSTALL_LIBDIR=libLibraries will land in$PREFIX/lib. Sometimes projects install intolib64or similar directories, but on conda-forge we keep libraries in plainlib.-DBUILD_SHARED_LIBS=ONInstruct CMake to build shared libraries instead of static ones.-DCMAKE_FIND_FRAMEWORK=NEVERand-DCMAKE_FIND_APPBUNDLE=NEVERPrevent CMake from using system-wide macOS packages.-G NinjaBuild the project usingninja.-B<directory>and-S<directory>Specify the build and source directories, respectively.${CMAKE_ARGS}Add variables defined by conda-forge internally. This is required to enable various conda-forge enhancements, like CUDA builds.
As ${CMAKE_ARGS} is a space separated list of options, it needs to be passed without
quoting. Quoting it ("${CMAKE_ARGS}") can lead to build errors as it makes the shell
treat the contents of the variable as a single argument.
Here are some basic commands for you to get started. These are dependent on your source code layout and aren't intended to be used "as is".
- build.sh
- bld.bat
cmake -S . -B build -G Ninja -DPython3_EXECUTABLE="$PYTHON" $CMAKE_ARGS
cmake --build build --config Release
cmake -S . -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPython3_EXECUTABLE="%PYTHON%" %CMAKE_ARGS%
if errorlevel 1 exit /b 1
cmake --build build --config Release
if errorlevel 1 exit /b 1
See also the bld.bat example in the Particularities on Windows section.