Any update for CMake enabled? - cmake

The road-map of bazel said it would support CMake on 2018.Q3, any update for it?
Thanks.
Added: the roadmap link: https://bazel.build/roadmaps/external-deps.html#2018-q3

rules_foreign_cc has experimental CMake integration.
Example from the README:
cmake_external(
name = "eigen",
# These options help CMake to find prebuilt OpenBLAS, which will be copied into
# $EXT_BUILD_DEPS/openblas by the cmake_external script
cache_entries = {
"BLA_VENDOR": "OpenBLAS",
"BLAS_LIBRARIES": "$EXT_BUILD_DEPS/openblas/lib/libopenblas.a",
},
headers_only = True,
lib_source = "#eigen//:all",
# Dependency on other cmake_external rule; can also depend on cc_import, cc_library rules
deps = [":openblas"],
)

Related

How create a nix package with haskell stack

I need to create the nix package from a project stack with postgres template.
Basically it is the following: I have a virtual machine with NixOS and I need to portlet my project to another one with NixOS. For this I will use the nix copy command, but before I need to somehow "install" my project so that it is in /nix/store.
I tried to do the same looking at another issue posted "Generating a Nix package from a stack project".
come on. What I did was:
cd /home/ProjetoApp
stack new TesteYesod yesod-postgres
cd TestYesod
stack init --resolver lts-11.22
stack install yesod-bin --install-ghc
I added in stack.yaml:
nix
pure: true
enable: true
packages: [postgresql]
So far so good. I can compile and execute only stack. Then I was trying to generate a nix package. In stack.yaml I did:
nix
pure: true
enable: true
shell-file: default.nix
And in default.nix I did:
{nixpkgs ? import <nixpkgs> { }, ghc ? nixpkgs.ghc}:
with nixpkgs;
haskell.lib.buildStackProject {
name ="teste-yesod-1.0.0";
src = ./.;
buildInputs = [ postgresql ];
inherit ghc;
}
If I do:
nix build
Occurs:
builder for '/nix/store/rckhmkgrkb6nzn7dkqqldfdm8cilpya2-teste-yesod
1.0.0.drv' failed with exit code 1; last 5 log lines:
unpacking sources
unpacking source archive /nix/store/
n62hzn4igi1b7khksa6sp3cq8gk4h344-TesteYesod
source root is TestYesod
patching sources
configuring
[0 built (1 failed), 0.0 MiB DL]
error: build of '/nix/store/rckhmkgrkb6nzn7dkqqldfdm8cilpya2-teste-yesod-
1.0.0.drv' failed
If. How to instruct nix that the source is spread across multiple directories?
If you want a quick fix, the following should work:
{ nixpkgs ? import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/d42ef371c9b1b532400b0f2820885e575f4f1617.tar.gz";
sha256 = "0irb4zb6hdgaah238244jk2xf63xfb20xy3plb1194pd4xbgdr3r";
}) {}
, ghc ? nixpkgs.ghc
}:
with nixpkgs;
haskell.lib.buildStackProject {
name ="TesteYesod";
src = ./.;
buildInputs = [ postgresql ];
inherit ghc;
}
What's the problem? It seems that in the current 18.09 release, buildStackProject is broken. The non-existent error message is caused by a subtly failing preConfigure script, which contains the following:
addStackArgsHook = ''
for pkg in ''${pkgsHostHost[#]} ''${pkgsHostBuild[#]} ''${pkgsHostTarget[#]}
do
[ -d "$pkg/lib" ] && \
export STACK_IN_NIX_EXTRA_ARGS+=" --extra-lib-dirs=$pkg/lib"
[ -d "$pkg/include" ] && \
export STACK_IN_NIX_EXTRA_ARGS+=" --extra-include-dirs=$pkg/include"
done
'';
In your case, stack is the last dependency to be processed in the loop (and perhaps in all buildStackProject invocations in 18.09, I'm not sure), but it contains no /lib or /include directory, so the exit code with which the preConfigure script exits is 1, and so the whole build process quits. This is just because of the shorthand &&, it would work if there was a proper if.
It is however fixed in master already (https://github.com/NixOS/nixpkgs/pull/53618), so simply using a newer nixpkgs should fix that problem. Pinning the nixpkgs is something you want to do anyway if you want to use Nix's replicability guarantees to the fullest, as you can't know you're using the same nixpkgs commit, so you may be using different versions of system packages.
(If you want to know how I debugged this - it seemed the problem was in the preConfigure step, so I took a look at the code in generic-stack-builder.nix, saw that preConfigure was overridable, copy-pasted the code from there into default.nix and added a set -x at the top. That showed me the problem above, and prompted me to go look at that file in master to see if there weren't changes since 18.09. Another workaround could be simply adding true to the preConfigure script if it wasn't already fixed in master, but that wasn't necessary.)
(Also, I've opened https://github.com/NixOS/nixpkgs/issues/55548 to backport the fix to 18.09.)

Antlr4 with C++ and CMake

I'm trying to use antlr4 with C++. I have the following CMakeLists.txt in my root directory:
cmake_minimum_required(VERSION 3.10)
project(demo VERSION 0.1 DESCRIPTION "demo")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_CXX_STANDARD 17)
#############################################################################
# ANTLR SPECIFIC CMAKE COMMANDS
# This is derived from: https://github.com/blorente/antlr-4.7-cpp-cmake-base
#############################################################################
# Set the ocation of the JAR.
set(ANTLR4CPP_JAR_LOCATION ${CMAKE_SOURCE_DIR}/antlr/jar/antlr.jar)
# Add external build for antlrcpp.
include (${CMAKE_SOURCE_DIR}/antlr/runtime/ExternalAntlr4Cpp.cmake)
# add antrl4cpp artifacts to project environment.
include_directories( ${ANTLR4CPP_INCLUDE_DIRS} )
link_directories( ${ANTLR4CPP_LIBS} )
# message(WARNING "Found antlr4cpp libs: ${ANTLR4CPP_LIBS} and includes: ${ANTLR4CPP_INCLUDE_DIRS} ")
# Build the lexer/parser .h/.cpp files off the g4 grammar files.
antlr4cpp_process_grammar(demo demoparser
${CMAKE_SOURCE_DIR}/grammar/DemoLexer.g4
${CMAKE_SOURCE_DIR}/grammar/DemoParser.g4)
# include the generated files from the grammar/lexer.
include_directories(${antlr4cpp_include_dirs_demoparser})
#############################################################################
# Build demo
add_executable(demo main.cpp ${antlr4cpp_src_files_demoparser})
# Add dependencies for antlr
add_dependencies(demo antlr4cpp antlr4cpp_generation_demoparser)
target_link_libraries(demo antlr4-runtime)
I have, more or less, copied the example from: the "official" cmake/antlr tutorial. For brevity I have omitted the contents of include (${CMAKE_SOURCE_DIR}/antlr/runtime/ExternalAntlr4Cpp.cmake)
So the files are all in the same structure, except the jar. I just include it as a project file and, as you can see from the set(ANTLR4CPP_JAR_LOCATION) command, it resides where I want it.
When I build this, I get this error:
dyld: Library not loaded: libantlr4-runtime.4.7.1.dylib
Referenced from: /path/to/demo/cmake-build-debug/demo
Reason: image not found
However, when I look in: /path/to/demo/cmake-build-debug/external/antlr4cpp/lib/ I see the libantlr4-runtime.4.7.1.dylib file that should be referenced by using the target_link_libraries(demo antlr4-runtime) command. There are static libraries in there as well.
Am I missing something? Why is CMake not finding the static or dylib files it's supposed to?
I didn't realize, right before I started this, that I ran brew install antlr4-cpp-runtime. Which installed the headers to the path. I did this on my machine, but not on any of the other machines that build this project. The outstanding problem is why is it not deterministic is if the runtime isn't installed. But it works immediately upon installing the runtime.

Automated translation management with Cmake and Qt5

I used to use the following qt4 commands for creation of translation files:
SET(PROJECTNAME "TEST")
SET(${PROJECTNAME}_TRANSLATIONS
${PROJECTNAME}_de.ts
)
SET(${PROJECTNAME}_TRANSLATIONS_COMPILED
${PROJECTNAME}_de.qm
)
QT4_CREATE_TRANSLATION (${PROJECTNAME}_TRANSLATION_FILES
${${PROJECTNAME}_FORMS}
${${PROJECTNAME}_HEADERS}
${${PROJECTNAME}_SOURCES}
${${PROJECTNAME}_RESSOURCES}
${${PROJECTNAME}_TRANSLATIONS}
)
How to port this kind of translation cmake snippet to work with Qt5 ?
The answer can be found in the Qt5-Cmake docs, here:
http://qt-project.org/doc/qt-5.0/qtdoc/cmake-manual.html#qt5linguisttools-macros
so, to your Cmakelists add:
find_package(Qt5LinguistTools)
then use:
QT5_CREATE_TRANSLATION(...)
Note for Ubuntu users (Oct.2013): you will need to install qttools5-dev

Cmake with bitbake recipe

I am trying to build an yocto image with my own package. I have OpenCV code on github which uses cmake.
I trying to write a recipe for it and facing lot of errors. Can any one give some hints on what functions or parameters to include in my recipe. My recipe looks as following
DESCRIPTION = "cameracapture application"
SECTION = "examples"
LICENSE = "CLOSED"
PR = "r0"
DEPENDS += "opencv"
SRC_URI = "git://https://github.com/zafrullahsyed/cameracapture.git;protocol=https;tag=v0.1"
EXTRA_OECMAKE=""
do_configure() {
cmake ../
}
inherit pkgconfig cmake
I followed these tutorials to write my recipe with cmake but in vain:
Bitbake Player recipe
Cmake-Bitbake-QT
The correct way of writing own recipes with cmake as follows:
DESCRIPTION = "cameracapture application"
SECTION = "examples"
LICENSE = "CLOSED"
PR = "r0"
DEPENDS = "opencv"
SRC_URI = "git://github.com/zafrullahsyed/cameracapture.git;protocol=https;tag=v0.1"
S = "${WORKDIR}/git"
inherit pkgconfig cmake
do_install() {
install -d ${D}${bindir}
install -m 0755 cameracapture ${D}${bindir}
}
Previously I didn't add do_install that's the reason yocto downloads the recipe but unable to include it Image.
If the CMakeLists.txt uses the install command then bitbake will do the install for you and you won't need to define you own do_install.
install(TARGETS cameracapture DESTINATION bin)
add the source directory in your recipe.
example
S = "${WORKDIR}/cameracapture
S is the source code path where your CMakeList.txt.
any how your are inheriting the cmake bbclass in your recipe, so it will take care of all configure , compile and install functionalities.
after doing this you can remove you do_configure function in the above recipe also.
you can add your make options if any to the below macro (as you kept empty).
example
EXTRA_OECMAKE = "all"

How to design a custom cmake FindOOXX module with versioning like FindQt4?

I would like to design a cmake FindOOXX module for Autodesk Maya with support of versioning, just like what FindQt4.cmake provides. ex,
find_package(Qt4 4.4.3)
include(${QT_USE_FILE})
add_executable(myexe main.cpp)
target_link_libraries(myexe ${QT_LIBRARIES})
Does anyone has a simple but complete cmake module sample like this?
In the CMake modules directory there is a file readme.txt which contains useful information for CMake module writers. This is the relevant section from that file on how version numbers are passed to the module:
If any version numbers are given to the command it will set the
following variables before loading the module:
XXX_FIND_VERSION = full requested version string
XXX_FIND_VERSION_MAJOR = major version if requested, else 0
XXX_FIND_VERSION_MINOR = minor version if requested, else 0
XXX_FIND_VERSION_PATCH = patch version if requested, else 0
XXX_FIND_VERSION_TWEAK = tweak version if requested, else 0
XXX_FIND_VERSION_COUNT = number of version components, 0 to 4
XXX_FIND_VERSION_EXACT = true if EXACT option was given
You can find the Qt4 find script in your CMake install folder under share\cmake-2.8\Modules.

Resources