Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP/RFC] Make cmakeFlags more ergonomic #17886

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ rec {
*/
escapeNixString = s: escape ["$"] (builtins.toJSON s);

/* Takes an array of strings and preps them for eval into a bash array.
Each value has double quotes escape, then is wrapped in double quotes;
the values are concatenated and wrapped in parentheses.

Example:
escapeBashArray ["one" "two three" "four\"five"]
=> "(\"one\"\n\"two three\"\n\"four\\\"five\")"
*/
escapeBashArray = xs: let
dquote = ''"'';
escapeVal = x: dquote + (escape [ dquote ] x) + dquote;
in "(" + (concatMapStringsSep "\n" escapeVal xs) + ")";

/* Obsolete - use replaceStrings instead. */
replaceChars = builtins.replaceStrings or (
del: new: s:
Expand Down Expand Up @@ -447,6 +460,10 @@ rec {
*/
withFeatureAs = with_: feat: value: withFeature with_ feat + optionalString with_ "=${value}";

tabJoin = xs: let
escapeTab = escape [ "\t" ];
in builtins.concatStringsSep "\t" (builtins.map escapeTab xs);

/* Create a fixed width string with additional prefix to match
required width.

Expand Down
12 changes: 6 additions & 6 deletions pkgs/applications/audio/i-score/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ stdenv.mkDerivation rec {
rtaudio
];

cmakeFlags = [
"-GNinja"
"-DISCORE_CONFIGURATION=static-release"
"-DISCORE_ENABLE_LTO=OFF"
"-DISCORE_BUILD_FOR_PACKAGE_MANAGER=True"
];
cmakeFlags = {
generator = "Ninja";
ISCORE_CONFIGURATION = "static-release";
ISCORE_ENABLE_LTO = false;
ISCORE_BUILD_FOR_PACKAGE_MANAGER = true;
};

preConfigure = ''
export CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH:$(echo "${jamomacore}/jamoma/share/cmake/Jamoma")"
Expand Down
5 changes: 4 additions & 1 deletion pkgs/applications/audio/kid3/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ stdenv.mkDerivation rec {
id3lib taglib mp4v2 flac libogg libvorbis zlib readline
qtbase qttools qtmultimedia qtquickcontrols makeWrapper ];

cmakeFlags = [ "-DWITH_APPS=Qt;CLI" ];
cmakeFlags = {
WITH_APPS = "Qt;CLI";
};

NIX_LDFLAGS = "-lm -lpthread";

preConfigure = ''
Expand Down
5 changes: 3 additions & 2 deletions pkgs/applications/audio/musescore/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ stdenv.mkDerivation rec {
sha256 = "00inrw9g8g34g74bhg5gp0rr5nydhjraiyn7vpl7kaqi5yzmhawd";
};

cmakeFlags = [
] ++ lib.optional (lib.versionAtLeast freetype.version "2.5.2") "-DUSE_SYSTEM_FREETYPE=ON";
cmakeFlags = {
USE_SYSTEM_FREETYPE = lib.versionAtLeast freetype.version "2.5.2";
};

nativeBuildInputs = [ cmake pkgconfig ];

Expand Down
18 changes: 9 additions & 9 deletions pkgs/applications/audio/projectm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ stdenv.mkDerivation {

nativeBuildInputs = [ pkgconfig cmake ];

cmakeFlags = ''
-DprojectM_FONT_MENU=${ttf_bitstream_vera}/share/fonts/truetype/VeraMono.ttf
-DprojectM_FONT_TITLE=${ttf_bitstream_vera}/share/fonts/truetype/Vera.ttf
-DINCLUDE-PROJECTM-TEST=OFF
-DINCLUDE-PROJECTM-QT=${if withQt then "ON" else "OFF"}
-DINCLUDE-PROJECTM-LIBVISUAL=${if withLibvisual then "ON" else "OFF"}
-DINCLUDE-PROJECTM-JACK=${if withJack then "ON" else "OFF"}
-DINCLUDE-PROJECTM-PULSEAUDIO=${if withPulseAudio then "ON" else "OFF"}
'';
cmakeFlags = {
projectM_FONT_MENU = "${ttf_bitstream_vera}/share/fonts/truetype/VeraMono.ttf";
projectM_FONT_TITLE = "${ttf_bitstream_vera}/share/fonts/truetype/Vera.ttf";
INCLUDE-PROJECTM-TEST = false;
INCLUDE-PROJECTM-QT = withQt;
INCLUDE-PROJECTM-LIBVISUAL = withLibvisual;
INCLUDE-PROJECTM-JACK = withJack;
INCLUDE-PROJECTM-PULSEAUDIO = withPulseAudio;
};

buildInputs = with stdenv.lib;
[ glew ftgl ]
Expand Down
8 changes: 4 additions & 4 deletions pkgs/applications/audio/tomahawk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ stdenv.mkDerivation rec {
sha256 = "0j84h36wkjfjbsd7ybyji7rcc9wpjdbl0f1xdcc1g7h0nz34pc0g";
};

cmakeFlags = [
"-DLUCENEPP_INCLUDE_DIR=${lucenepp}/include"
"-DLUCENEPP_LIBRARY_DIR=${lucenepp}/lib"
];
cmakeFlags = {
LUCENEPP_INCLUDE_DIR = "${lucenepp}/include";
LUCENEPP_LIBRARY_DIR = "${lucenepp}/lib";
};

nativeBuildInputs = [ pkgconfig ];
buildInputs = [
Expand Down
4 changes: 3 additions & 1 deletion pkgs/applications/audio/yoshimi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ stdenv.mkDerivation rec {

preConfigure = "cd src";

cmakeFlags = [ "-DFLTK_MATH_LIBRARY=${stdenv.glibc.out}/lib/libm.so" ];
cmakeFlags = {
FLTK_MATH_LIBRARY = "${stdenv.glibc.out}/lib/libm.so";
};

meta = with stdenv.lib; {
description = "High quality software synthesizer based on ZynAddSubFX";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/display-managers/slim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ stdenv.mkDerivation rec {

preConfigure = "substituteInPlace CMakeLists.txt --replace /lib $out/lib";

cmakeFlags = [ "-DUSE_PAM=1" ];
cmakeFlags = { USE_PAM = true; };

NIX_CFLAGS_COMPILE = "-I${freetype.dev}/include/freetype -std=c++11";

Expand Down
8 changes: 4 additions & 4 deletions pkgs/applications/editors/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ let

lualibs = [ luaPackages.mpack luaPackages.lpeg luaPackages.luabitop ];

cmakeFlags = [
"-DLUA_PRG=${luaPackages.lua}/bin/lua"
"-DGPERF_PRG=${gperf}/bin/gperf"
];
cmakeFlags = {
LUA_PRG = "${luaPackages.lua}/bin/lua";
GPERF_PRG = "${gperf}/bin/gperf";
};

# triggers on buffer overflow bug while running tests
hardeningDisable = [ "fortify" ];
Expand Down
8 changes: 4 additions & 4 deletions pkgs/applications/editors/neovim/qt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ stdenv.mkDerivation rec {
sha256 = "190yg6kkw953h8wajlqr2hvs2fz65y6z0blmywlg1nff724allaq";
};

cmakeFlags = [
"-DMSGPACK_INCLUDE_DIRS=${libmsgpack}/include"
"-DMSGPACK_LIBRARIES=${libmsgpack}/lib/libmsgpackc.so"
];
cmakeFlags = {
MSGPACK_INCLUDE_DIRS = "${libmsgpack}/include";
MSGPACK_LIBRARIES = "${libmsgpack}/lib/libmsgpackc.so";
};

buildInputs = with pythonPackages; [
neovim qtbase libmsgpack
Expand Down
13 changes: 6 additions & 7 deletions pkgs/applications/gis/qgis/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ stdenv.mkDerivation rec {
# QGIS_MACAPP_BUNDLE=0 stops the installer copying the Qt binaries into the
# installation which causes havoc
# Building RelWithDebInfo allows QGIS_DEBUG to print debugging information
cmakeFlags = stdenv.lib.optional withGrass "-DGRASS_PREFIX7=${grass}/${grass.name}"
++ stdenv.lib.optional stdenv.isDarwin
(["-DCMAKE_FIND_FRAMEWORK=never"]
++ ["-DQGIS_MACAPP_BUNDLE=0"]);
# ++ ["-DCMAKE_BUILD_TYPE=RelWithDebInfo"];


cmakeFlags = (stdenv.lib.optionalAttrs withGrass {
GRASS_PREFIX7 = "${grass}/${grass.name}";
}) // (stdenv.lib.optionalAttrs stdenv.isDarwin {
CMAKE_FIND_FRAMEWORK = "never"
DQGIS_MACAPP_BUNDLE = false;
});

postInstall =
(stdenv.lib.optionalString stdenv.isLinux ''
Expand Down
8 changes: 4 additions & 4 deletions pkgs/applications/graphics/darktable/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ stdenv.mkDerivation rec {
colord colord-gtk libwebp libsecret gnome3.adwaita-icon-theme
osm-gps-map ocl-icd
];
cmakeFlags = [
"-DBUILD_USERMANUAL=False"
];

cmakeFlags = {
BUILD_USERMANUAL = false;
};

# darktable changed its rpath handling in commit
# 83c70b876af6484506901e6b381304ae0d073d3c and as a result the
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/graphics/hugin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake makeWrapper pkgconfig ];

# disable installation of the python scripting interface
cmakeFlags = [ "-DBUILD_HSI:BOOl=OFF" ];
cmakeFlags = { BUILD_HSI = false; };

enableParallelBuilding = true;

Expand Down
12 changes: 7 additions & 5 deletions pkgs/applications/graphics/nomacs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ stdenv.mkDerivation rec {
quazip
gsettings-desktop-schemas];

cmakeFlags = ["-DENABLE_OPENCV=ON"
"-DENABLE_RAW=ON"
"-DENABLE_TIFF=ON"
"-DENABLE_QUAZIP=ON"
"-DUSE_SYSTEM_QUAZIP=ON"];
cmakeFlags = {
ENABLE_OPENCV = true;
ENABLE_QUAZIP = true;
ENABLE_RAW = true;
ENABLE_TIFF = true;
USE_SYSTEM_QUAZIP = true;
};

meta = with stdenv.lib; {
homepage = https://nomacs.org;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/applications/graphics/openimageio/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ stdenv.mkDerivation rec {
unzip
];

cmakeFlags = [
"-DUSE_PYTHON=OFF"
];
cmakeFlags = {
USE_PYTHON = false;
};

preBuild = ''
makeFlags="ILMBASE_HOME=${ilmbase.dev} OPENEXR_HOME=${openexr.dev} USE_PYTHON=0
Expand Down
16 changes: 8 additions & 8 deletions pkgs/applications/graphics/renderdoc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ stdenv.mkDerivation rec {
patchShebangs swig/autogen.sh
'';

cmakeFlags = [
"-DBUILD_VERSION_HASH=${src.rev}"
"-DBUILD_VERSION_DIST_NAME=NixOS"
"-DBUILD_VERSION_DIST_VER=${version}"
"-DBUILD_VERSION_DIST_CONTACT=https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/graphics/renderdoc"
"-DBUILD_VERSION_STABLE=ON"
cmakeFlags = {
BUILD_VERSION_HASH = src.rev;
BUILD_VERSION_DIST_NAME = "NixOS";
BUILD_VERSION_DIST_VER = version;
BUILD_VERSION_DIST_CONTACT = "https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/graphics/renderdoc";
BUILD_VERSION_DIST_STABLE = true;
# TODO: add once pyside2 is in nixpkgs
#"-DPYSIDE2_PACKAGE_DIR=${python36Packages.pyside2}"
];
# PYSIDE2_PACKAGE_DIR = python36Packages.pyside2;
};

# Future work: define these in the above array via placeholders
preConfigure = ''
Expand Down
20 changes: 10 additions & 10 deletions pkgs/applications/graphics/screencloud/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stdenv.mkDerivation rec {
# for tracking usage.
consumerKey = "23e747012c68601f27ab69c6de129ed70552d55b6";
consumerSecret = "4701cb00c1bd357bbcae7c3d713dd216";

src = fetchFromGitHub {
owner = "olav-st";
repo = "screencloud";
Expand All @@ -34,14 +34,14 @@ stdenv.mkDerivation rec {
# to add the argument for us.
dontAddPrefix = true;

cmakeFlags = [
"-DQXT_QXTCORE_INCLUDE_DIR=${qxt}/include/QxtCore"
"-DQXT_QXTCORE_LIB_RELEASE=${qxt}/lib/libQxtCore.so"
"-DQXT_QXTGUI_INCLUDE_DIR=${qxt}/include/QxtGui"
"-DQXT_QXTGUI_LIB_RELEASE=${qxt}/lib/libQxtGui.so"
"-DCONSUMER_KEY_SCREENCLOUD=${consumerKey}"
"-DCONSUMER_SECRET_SCREENCLOUD=${consumerSecret}"
];
cmakeFlags = {
QXT_QXTCORE_INCLUDE_DIR = "${qxt}/include/QxtCore";
QXT_QXTCORE_LIB_RELEASE = "${qxt}/lib/libQxtCore.so";
QXT_QXTGUI_INCLUDE_DIR = "${qxt}/include/QxtGui";
QXT_QXTGUI_LIB_RELEASE = "${qxt}/lib/libQxtGui.so";
CONSUMER_KEY_SCREENCLOUD = "${consumerKey}";
CONSUMER_SECRET_SCREENCLOUD = "${consumerSecret}";
};

setSourceRoot = ''
sourceRoot=$(echo */screencloud)
Expand All @@ -50,7 +50,7 @@ stdenv.mkDerivation rec {
preConfigure = ''
# This needs to be set in preConfigure instead of cmakeFlags in order to
# access the $prefix environment variable.
export cmakeFlags="-DCMAKE_INSTALL_PREFIX=$prefix/opt $cmakeFlags"
cmakeFlags+=("-DCMAKE_INSTALL_PREFIX=$prefix/opt")
'';

# There are a number of issues with screencloud's installation. We need to add
Expand Down
32 changes: 16 additions & 16 deletions pkgs/applications/graphics/seg3d/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ stdenv.mkDerivation {

patches = [ ./cstdio.patch ];

cmakeFlags = [
"-DM_LIBRARY=${stdenv.glibc.out}/lib/libm.so"
"-DDL_LIBRARY=${stdenv.glibc.out}/lib/libdl.so"
"-DBUILD_UTILS=1"
"-DBUILD_SEG3D=1"
"-DBUILD_DATAFLOW=0"
"-DBUILD_SHARED_LIBS=0"
"-DWITH_X11=1"
"-DBUILD_BIOMESH3D=1"
"-DWITH_TETGEN=1"
"-DBUILD_TYPE=Release"
"-DBUILD_TESTING=0"
"-DWITH_WXWIDGETS=ON"
"-DITK_DIR=${itk}/lib/InsightToolkit"
"-DGDCM_LIBRARY=${itk}/lib/libitkgdcm.a"
];
cmakeFlags = {
M_LIBRARY = "${stdenv.glibc.out}/lib/libm.so";
DL_LIBRARY = "${stdenv.glibc.out}/lib/libdl.so";
BUILD_UTILS = true;
BUILD_SEG3D = true;
BUILD_DATAFLOW = false;
BUILD_SHARED_LIBS = false;
WITH_X11 = true;
BUILD_BIOMESH3D = true;
WITH_TETGEN = true;
BUILD_TYPE = "Release";
BUILD_TESTING = false;
WITH_WXWIDGETS = true;
ITK_DIR = "${itk}/lib/InsightToolkit";
GDCM_LIBRARY = "${itk}/lib/libitkgdcm.a";
};


makeFlags = "VERBOSE=1";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/graphics/smartdeblur/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ stdenv.mkDerivation rec {

buildInputs = [ cmake qt4 fftw ];

cmakeFlags = "-DUSE_SYSTEM_FFTW=ON";
cmakeFlags = { USE_SYSTEM_FFTW = true; };

meta = {
homepage = https://github.com/Y-Vladimir/SmartDeblur;
Expand Down
5 changes: 4 additions & 1 deletion pkgs/applications/misc/bibletime/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ stdenv.mkDerivation rec {

buildInputs = [ cmake sword qt4 boost clucene_core ];

cmakeFlags = "-DUSE_QT_WEBKIT=ON -DCMAKE_BUILD_TYPE=Debug";
cmakeFlags = {
USE_QT_WEBKIT = true;
CMAKE_BUILD_TYPE = "Debug";
};

meta = {
description = "A Qt4 Bible study tool";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/misc/dfilemanager/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ stdenv.mkDerivation {

buildInputs = [ cmake qtbase qttools file solid ];

cmakeFlags = "-DQT5BUILD=true";
cmakeFlags = { QT5BUILD = true; };

meta = {
homepage = http://dfilemanager.sourceforge.net/;
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/misc/finalterm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ stdenv.mkDerivation {
substituteInPlace data/org.gnome.finalterm.gschema.xml \
--replace "/bin/bash" "${bashInteractive}/bin/bash"

cmakeFlagsArray=(
-DMINIMAL_FLAGS=ON
cmakeFlags+=(
"-DMINIMAL_FLAGS=ON"
)
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/misc/j4-dmenu-desktop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake ];

# tests are fetching an external git repository
cmakeFlags = [ "-DNO_TESTS:BOOL=ON" ];
cmakeFlags = { NO_TESTS = true; };

meta = with stdenv.lib; {
description = "A wrapper for dmenu that recognize .desktop files";
Expand Down
Loading