Cannot configure CMake to look for Homebrew installed version of Bison - cmake

I'm running macOS 10.14 and I installed bison version 3.2 with brew, but it refuses to link:
$ brew link bison --force
Warning: Refusing to link macOS-provided software: bison
If you need to have bison first in your PATH run:
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.bash_profile
For compilers to find bison you may need to set:
export LDFLAGS="-L/usr/local/opt/bison/lib"
My CMakeLists.txt has the following lines:
find_package(BISON 3.2 REQUIRED)
...
message(STATUS "Found bison ${BISON_VERSION} at: ${BISON_EXECUTABLE}")
cmake fails with the following output:
Could NOT find BISON: Found unsuitable version "2.3", but required is at
least "3.2" (found /usr/bin/bison)
The system-installed bison is at version 2.3, and I know that the Homebrew-installed version is at version 3.2.
The FindBISON module apparently uses the find_program CMake directive, and I've tried adding /usr/local/opt/bison/bin to CMAKE_PROGRAM_PATH, but /usr/bin/bison is always selected first no matter what. How can I force CMake to favor the Homebrew installed version of the Bison executable?

Since some things in macos depend on the Apple-provided versions of flex and bison, homebrew installs them outside of the user's normal $PATH as a "keg". A manual solution is to make sure you (and your users) add the program's brew prefix to their path (can be found by running brew --prefix bison etc.).
An automatic solution is to put this logic in your CMake files. A couple open-source projects have worked around it like this. The earliest example of a fix for this that I could find is from this commit to STP (essential part copied below).
Be sure to clear your CMake cache when messing around with all this, as BISON_EXECUTABLE (etc.) is cached.
# On macOS, search Homebrew for keg-only versions of Bison and Flex. Xcode does
# not provide new enough versions for us to use.
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
execute_process(
COMMAND brew --prefix bison
RESULT_VARIABLE BREW_BISON
OUTPUT_VARIABLE BREW_BISON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
endif()
execute_process(
COMMAND brew --prefix flex
RESULT_VARIABLE BREW_FLEX
OUTPUT_VARIABLE BREW_FLEX_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
set(FLEX_EXECUTABLE "${BREW_FLEX_PREFIX}/bin/flex")
endif()
endif()
find_package(bison REQUIRED)
find_package(flex REQUIRED)

Related

Configure cmake to work with homebrew libraries instead system-provided libraries

I find myself going against the grain configuring cmake paths with ccmake over and over again as with every change of for ex. compiler some of my library paths get lost.
In particular paths to (unlinked) lapack, lapacke, gsl get either lost or set to system defaults instead the ones I've installed with brew.
There has to be a way to tell cmake to "ignore" system libraries and instead look in homebrew paths (say. /opt/homebrew/lib, /opt/homebrew/include etc.).
I'd prefer not to link those libraries as this is not recommend and I'm not experienced in switching environments.
[EDIT] MRE:
git clone https://gitlab.physik.uni-muenchen.de/AG-Scrinzi/tRecX.git
cd tRecX
cmake . -DCMAKE_BUILD_TYPE=Parallel
make -j 8
I add the following to .bash_profile/.zshrc:
export LDFLAGS="-L/opt/homebrew/opt/lapack/lib -L/opt/homebrew/opt/lapack/lib"
export CPPFLAGS="-I/opt/homebrew/opt/lapack/include -I/opt/homebrew/opt/openblas/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/lapack/lib/pkgconfig /opt/homebrew/opt/openblas/lib/pkgconfig"
then I try:
cmake . -DCMAKE_PREFIX_PATH=/opt/homebrew -DCMAKE_FIND_FRAMEWORK=NEVER -DCMAKE_FIND_APPBUNDLE=NEVER -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=FALSE -DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=FALSE -DMPI_CXX_COMPILER=/opt/homebrew/bin/mpicxx -DMPI_C_COMPILER=/opt/homebrew/bin/mpicc -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++-11 -DCMAKE_C_COMPILER=/opt/homebrew/bin/gcc-11
The most common solution is to just set CMAKE_PREFIX_PATH to /opt/homebrew. CMake will then look preferentially in /opt/homebrew for everything. Since you're on Apple, you might need to set CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE to LAST or NEVER, too.
You can skip the standard platform search paths by setting CMAKE_FIND_USE_CMAKE_SYSTEM_PATH to FALSE at the command line, in a preset, or in a toolchain file. You might also wish to disable looking at the PATH environment variable by setting CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH to FALSE.
Finally, if you're in a cross-compiling scenario or toolchain file, you can change the definition of the system directories by setting CMAKE_SYSROOT. Note that the sysroot will have to contain the language runtime libraries (e.g. glibc) and will be passed to the --sysroot flag (or equivalent). Just be aware of those effects, too.
All of this is documented here:
https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure
https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_FRAMEWORK.html#variable:CMAKE_FIND_FRAMEWORK
https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_APPBUNDLE.html#variable:CMAKE_FIND_APPBUNDLE
The following homebrew.cmake toolchain file worked for me:
set(HOMEBREW_PREFIX "/usr/local"
CACHE PATH "Path to Homebrew installation")
set(CMAKE_C_COMPILER "${HOMEBREW_PREFIX}/bin/gcc-11")
set(CMAKE_CXX_COMPILER "${HOMEBREW_PREFIX}/bin/g++-11")
set(CMAKE_PREFIX_PATH
"${HOMEBREW_PREFIX}"
# These libraries are keg-only and not loaded into
# the root prefix by default (to avoid clashes).
"${HOMEBREW_PREFIX}/opt/lapack"
"${HOMEBREW_PREFIX}/opt/openblas"
"${HOMEBREW_PREFIX}/opt/gcc/lib/gcc/11"
)
list(TRANSFORM CMAKE_PREFIX_PATH APPEND "/include"
OUTPUT_VARIABLE CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES)
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "${CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES}")
set(CMAKE_FIND_FRAMEWORK NEVER)
set(CMAKE_FIND_APPBUNDLE NEVER)
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
I built with the following commands:
$ ls
tRecX homebrew.cmake
$ cmake -G Ninja -S tRecX -B tRecX-build \
-DCMAKE_TOOLCHAIN_FILE=$PWD/homebrew.cmake \
-DCBLAS=/usr/local/opt/openblas/lib/libblas.dylib \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-undefined,dynamic_lookup" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-undefined,dynamic_lookup" \
-DCMAKE_BUILD_TYPE=Parallel
[ ... output clipped ... ]
Boost found -- full functionality
Build "Parallel" with C++ flags -D_USE_BOOST_ -O3 -pthread -D_USE_FFTW_, return to default by -UCMAKE_BUILD_TYPE
Compiler: /usr/local/bin/g++-11, change by -DCMAKE_CXX_COMPILER=[path_to_complier]
-- Linking to libraries Boost::system;Boost::filesystem;/usr/local/lib/libfftw3.dylib;/usr/local/opt/gcc/lib/gcc/11/libgfortran.dylib;alglib;/usr/local/lib/libarpack.dylib;Boost::system;Boost::filesystem;/usr/local/opt/lapack/lib/liblapacke.dylib;/usr/local/opt/openblas/lib/libblas.dylib;/usr/local/opt/lapack/lib/liblapack.dylib;/usr/local/opt/lapack/lib/libblas.dylib;m
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/alexreinking/Development/tRecX-build
$ cmake --build tRecX-build
I had to set CBLAS manually because libblas.dylib provides the OpenBLAS CBLAS interface, but the build system specifically looks for a library named libcblas. There's no other option in this case.
The code and build have issues with its linking model and dependencies. I was able to paper over these by setting -Wl,-undefined,dynamic_lookup. However, note that this will just defer linker errors to runtime and might impose a large startup cost.
If you can make commits to the project, I would store these settings in a preset, maybe name it homebrew-parallel or something:
-DCMAKE_TOOLCHAIN_FILE=$PWD/homebrew.cmake \
-DCBLAS=/usr/local/opt/openblas/lib/libblas.dylib \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-undefined,dynamic_lookup" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-undefined,dynamic_lookup" \
-DCMAKE_BUILD_TYPE=Parallel
Then you could just run cmake --preset=homebrew-parallel

Error using cmake to configure and build Axiros AXACT: OpenSSL Directory Not Found [duplicate]

I am trying to install a software that uses cmake to install itself. When I run cmake .. on the command line, it gives me following error in the CMakeLists.txt on the line that says find_package(OpenSSL REQUIRED):
-- Could NOT find Git (missing: GIT_EXECUTABLE)
ZLib include dirs: /usr/include
ZLib libraries: /usr/lib/arm-linux-gnueabihf/libz.so
Compiling with SSL support
CMake Error at /usr/local/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES
OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/local/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-2.8/Modules/FindOpenSSL.cmake:313 (find_package_handle_standard_args)
CMakeLists.txt:436 (find_package)
Here is the part of the file CMakeLists.txt where the error is coming from:
#
# OpenSSL
#
if (WITH_SSL)
message("Compiling with SSL support")
if (USE_CYASSL)
# Use CyaSSL as OpenSSL replacement.
# TODO: Add a find_package command for this also.
message("CyaSSL include dir: ${CYASSL_INCLUDE_DIRS}")
message("CyaSSL libraries: ${CYASSL_LIB}")
# Additional to the root directory we need to include
# the cyassl/ subdirectory which contains the OpenSSL
# compatability layer headers.
foreach(inc ${CYASSL_INCLUDE_DIRS})
include_directories(${inc} ${inc}/cyassl)
endforeach()
list(APPEND LIB_LIST ${CYASSL_LIB})
else()
# TODO: Add support for STATIC also.
find_package(OpenSSL REQUIRED)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
include_directories(${OPENSSL_INCLUDE_DIR})
list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
endif()
endif(WITH_SSL)
I have OpenSSL installed here:
ssl header is here -- > /usr/local/ssl/include/openssl/
ssl library is here -- > /usr/local/ssl/lib/libssl.a
/usr/local/ssl/lib/libcrypto.a
openssl is here -- > /usr/local/ssl/bin
I have in my .profile:
export LD_LIBRARY_PATH=/usr/local/ssl/include/openssl:/usr/lib:/usr/local/lib:/usr/lib/pkgconfig:/usr/local/include/wx-2.8/wx:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
export OPENSSL_ROOT_DIR=/usr/local/ssl
export OPENSSL_LIBRARIES=/usr/local/ssl/lib/
PATH = /usr/local/ssl/bin:$PATH
How can I resolve this error?
EDIT:
Now I am getting this error
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x10): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x30): undefined reference to `dlclose'
I had the same problem (openssl) and this worked for me on Ubuntu 14.04.1 LTS. The solution is the same up to Ubuntu 18.04 (tested).
sudo apt-get install libssl-dev
fixed it on macOS using
brew install openssl
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
Same problem, and fixed it on my CentOS 6.5 using the following command:
yum install openssl-devel
Please install openssl from below link:
https://code.google.com/p/openssl-for-windows/downloads/list
then set the variables below:
OPENSSL_ROOT_DIR=D:/softwares/visualStudio/openssl-0.9.8k_WIN32
OPENSSL_INCLUDE_DIR=D:/softwares/visualStudio/openssl-0.9.8k_WIN32/include
OPENSSL_LIBRARIES=D:/softwares/visualStudio/openssl-0.9.8k_WIN32/lib
If you are using macOS then follow the below steps.
brew upgrade openssl
brew link --force openssl
pkg-config --modversion openssl
#1.1.1l
Clear the cmake build folder and rerun the cmake ..
As mentioned by others, on Ubuntu you should run
sudo apt install libssl-dev
But for me that was not enough, because although the libraries needed for building were installed, they still could not be found. What I had to install in addition was
sudo apt install pkg-config
If you can use pkg-config: pkg_search_module() can find OpenSSL for you.
# Search OpenSSL
find_package(PkgConfig REQUIRED)
pkg_search_module(OPENSSL REQUIRED openssl)
if( OPENSSL_FOUND )
include_directories(${OPENSSL_INCLUDE_DIRS})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
else()
# Error; with REQUIRED, pkg_search_module() will throw an error by it's own
endif()
target_link_libraries(${YOUR_TARGET_HERE} ${OPENSSL_LIBRARIES})
Just for fun, I'll post an alternative working answer for the OP's question:
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/
Just in case...this works for me. Sorry for specific version of OpenSSL, but might be desirable.
# On macOS, search Homebrew for keg-only versions of OpenSSL
# equivalent of # -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
execute_process(
COMMAND brew --prefix OpenSSL
RESULT_VARIABLE BREW_OPENSSL
OUTPUT_VARIABLE BREW_OPENSSL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_OPENSSL EQUAL 0 AND EXISTS "${BREW_OPENSSL_PREFIX}")
message(STATUS "Found OpenSSL keg installed by Homebrew at ${BREW_OPENSSL_PREFIX}")
set(OPENSSL_ROOT_DIR "${BREW_OPENSSL_PREFIX}/")
set(OPENSSL_INCLUDE_DIR "${BREW_OPENSSL_PREFIX}/include")
set(OPENSSL_LIBRARIES "${BREW_OPENSSL_PREFIX}/lib")
set(OPENSSL_CRYPTO_LIBRARY "${BREW_OPENSSL_PREFIX}/lib/libcrypto.dylib")
endif()
endif()
...
find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
# Add the include directories for compiling
target_include_directories(${TARGET_SERVER} PUBLIC ${OPENSSL_INCLUDE_DIR})
# Add the static lib for linking
target_link_libraries(${TARGET_SERVER} OpenSSL::SSL OpenSSL::Crypto)
message(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
else()
message(STATUS "OpenSSL Not Found")
endif()
you are having the FindOpenSSL.cmake file in the cmake module(path usr/shared.cmake-3.5/modules)
# Search OpenSSL
find_package(OpenSSL REQUIRED)
if( OpenSSL_FOUND )
include_directories(${OPENSSL_INCLUDE_DIRS})
link_directories(${OPENSSL_LIBRARIES})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
target_link_libraries(project_name /path/of/libssl.so /path/of/libcrypto.so)
Note for Fedora 27 users: I had to install openssl-devel package to run the cmake successfully.
sudo dnf install openssl-devel
On WSL I still got the error after running sudo apt install libssl-dev.
I had to run whereis openssl and then updated the commented out lines in CMakeCache.txt:
#OPENSSL_CRYPTO_LIBRARY:FILEPATH=OPENSSL_CRYPTO_LIBRARY-NOTFOUND
OPENSSL_CRYPTO_LIBRARY:FILEPATH=/usr/bin/openssl
#OPENSSL_INCLUDE_DIR:PATH=OPENSSL_INCLUDE_DIR-NOTFOUND
OPENSSL_INCLUDE_DIR:PATH=/usr/include/openssl
In addition to the accepted answer, I'm posting some extra information that could have saved me two full days' work and a complete CMake tear up. My machine runs Ubuntu 20.04
Installing libssl-dev as suggested includes two libraries: libssl and libcrypto. The find_package directive in my cmake project was eliminating the reference errors in my project, but it still couldn't find the libraries. That's because all of the accepted answers around tell you to use these lines:
find_package(OpenSSL REQUIRED)
target_link_libraries(MyExecutable OpenSSL Crypto)
Cmake will look for libraries with names libOpenSSL and libCrypto. Both failed due to capitalization, and libopenssl doesn't exist because the file is actually just named libssl. Indeed, check the contents of the libssl-dev package by using:
apt-file list libssl-dev
So, in my case, the solution was to use this cmake directive instead:
target_link_libraries(MyExecutable ssl crypto)
#Morwenn is right.
You need to config the openssl DIR.
Before that you may need to make sure you have it.
you should check whether you have it.
first run openssl version,then if you have it you can win + r run openssl
and you win find the core dir since it may not name as openssl in your system.
This is what I added in the CMakeList.txt (which worked):
# https://cmake.org/cmake/help/latest/command/find_package.html
# in the above link, it states:
# "In Module mode, CMake searches for a file called Find<PackageName>.cmake.
# The file is first searched in the CMAKE_MODULE_PATH, then among the Find
# Modules provided by the CMake installation. If the file is found, it is
# read and processed by CMake. It is responsible for finding the package,
# checking the version, and producing any needed messages. Some find-modules
# provide limited or no support for versioning; check the module documentation."
#
# FindOpenSSL.cmake can be found in path/to/cmake/Modules
#
# https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
#
find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
# Add the include directories for compiling
target_include_directories(${PROJECT_NAME} PUBLIC ${OPENSSL_INCLUDE_DIR})
# Add the static lib for linking
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
message(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
else()
message(STATUS "OpenSSL Not Found")
endif()
I'm using macOS and I preferred to set the environmental variable OPENSSL_ROOT_DIR
brew install openssl#1.1
export OPENSSL_ROOT_DIR=/usr/local/opt/openssl#1.1/
The answer actually depends on the status of your system and the program you are using cmake on. Based on the second errors you are getting, you might need an extra openssl package that is not currently installed on your system. You can search packages using the aptitude search command. I recommend searching for "ssl" rather than "openssl" as the packages sometimes don't contain the word "open".
Another thing you can do to check which packages to install is to find if the manual or documentation of the product you are installing contains information about which packages to install.
Like the other posts comment, one of such packages is libssl-dev, but your program might need some other packages as well.

CMake : Selecting mpich over openmpi

I am using cmake 3.10.2. I have both openmpi and mpich installed. However I need to load only mpich. So I found from the documentation the following
MPI_EXECUTABLE_SUFFIX
A suffix which is appended to all names that are being looked for.
For instance you may set this to .mpich or .openmpi to prefer the one
or the other on Debian and its derivatives.
My CMake file goes like this
set(MPI_EXECUTABLE_SUFFIX ".mpich")
FIND_PACKAGE(MPI REQUIRED)
INCLUDE_DIRECTORIES(${MPI_INCLUDE_DIRS})
LINK_DIRECTORIES(${MPI_LIBRARY_DIRS})
message(${MPI_INCLUDE_PATH})
However this shows
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/usr/lib/x86_64-linux-gnu/openmpi/include...
Where am I going wrong. Could you please help me with this
Also
mpicc -show
gcc -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent/include -I/usr/lib/x86_64-linux-gnu/openmpi/include -pthread -L/usr//lib -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi
mpicc.mpich -show
gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -I/usr/include/mpich -L/usr/lib/x86_64-linux-gnu -lmpich
the best is to use modules for switch between openmpi and mpich:
$ module load mpich
$ module unload mpich
$ module load openmpi
http://modules.sourceforge.net/
The default mpicc is not your choice. You can specify it manually in the cmake file, or update the $PATH variable with your mpicc included before the default one. Personally, I installed the mpich in the /usr/local/ directory.
Regards

Use LLVM in a cmake build

I'm trying to build my own project that use LLVM. I downloaded the source code and the precompiled package on the official web site (last version).
http://releases.llvm.org/download.html
I downloaded :
LLVM source code
Clang for Windows (64-bit)
FYI, I don't build LLVM... only want to use it !
I followed the instruction here :
http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
in the section : "Embedding LLVM in your project"
So, I added this code :
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message("LLVM_INCLUDE_DIRS=${LLVM_INCLUDE_DIRS}")
message("LLVM_DEFINITIONS=${LLVM_DEFINITIONS}")
But I got several cmake error messages, here is my output :
-- Using LLVMConfig.cmake in: C:\\Luciad_src\\libs\\LLVM\\cmake\\modules
LLVM_INCLUDE_DIRS=
LLVM_DEFINITIONS=
CMake Error at C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:31 (list):
list sub-command REMOVE_ITEM requires two or more arguments.
Call Stack (most recent call first):
C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:256 (is_llvm_target_library)
components/query/CMakeLists.txt:15 (llvm_map_components_to_libnames)
Is there a problem with my script, or the packages I use ? Any idea ?
Thanks for your help
You can have the LLVM as binary or source package.
The binary package does not include CMake support. If you compare both installations (binary on the left, source after building and installing it on the right) you can see the difference:
LLVM-5.0.0-win64.exe
<=> llvm-5.0.1.src.tar.xz (build and installed)
So you need to build and install the source package first to get CMake support. On my Windows machine I needed a cmd shell with administrator rights, a Visual Studio installation, go to the downloaded and extracted sources and do:
> mkdir mybuilddir
> cd mybuilddir
> cmake ..
> cmake --build . --config Release --target INSTALL
If I now use your CMake example I get:
-- Found LLVM 5.0.1
-- Using LLVMConfig.cmake in: C:/Program Files (x86)/LLVM/lib/cmake/llvm
LLVM_INCLUDE_DIRS=C:/Program Files (x86)/LLVM/include
LLVM_DEFINITIONS=-DLLVM_BUILD_GLOBAL_ISEL -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Configuring done

cmake with git for windows, MinGW and make

Firstly, I have installed MinGW from https://sourceforge.net/projects/mingw/files/ and the mingw32-gcc-g++ and mingw32-gcc-objs with it. I have added C:\MinGW\bin to my path.
Secondly, I have installed Git for windows (not really important, the result is the same on cmd.exe).
Thirdly, I have installed the complete package "make" with http://gnuwin32.sourceforge.net/packages/make.htm
After that, I have installed cmake 3.5.1 with the .msi.
But when I run cmake ../src the result is :
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:5 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:5 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "C:/Users/pauka/Dropbox/ETUDE/SRI/S8/STA_Stage/sources/tests/bin/CMakeFiles/CMakeOutput.log".
See also "C:/Users/pauka/Dropbox/ETUDE/SRI/S8/STA_Stage/sources/tests/bin/CMakeFiles/CMakeError.log".
So cmake can't find gcc or g++. But when I run gcc -version, the output is good... What should I configure for cmake ?
My CMakeLists.txt is :
# Ajustez en fonction de votre version de CMake
cmake_minimum_required (VERSION 2.8)
# Nom du projet
project (main)
find_package (OpenCV REQUIRED)
# Exécutable "main", compilé à partir du fichier main.cpp
add_executable (tracking_color tracking_color.cpp)
add_executable (feuille feuille.cpp)
add_executable (detect_circles detect_circles.cpp)
add_executable (segmentation segmentation.cpp)
add_executable (watershed_perso watershed_perso.cpp)
add_executable (main main.cpp utils.h)
add_executable (info_coins info_coins.cpp)
# main sera linké avec les bibliothèques d'OpenCV
target_link_libraries (tracking_color ${OpenCV_LIBS})
target_link_libraries (feuille ${OpenCV_LIBS})
target_link_libraries (detect_circles ${OpenCV_LIBS})
target_link_libraries (segmentation ${OpenCV_LIBS})
target_link_libraries (watershed_perso ${OpenCV_LIBS})
target_link_libraries (info_coins ${OpenCV_LIBS})
target_link_libraries (main ${OpenCV_LIBS})
Ok, shame on me,
I had to restart my computer and select "MinGW Makefiles" in the CMake GUI. Click Configure, and after that Generate.
Next, you must not use Git for windows because there is sh.exe and it's a cmake bug.
PS: to use OpenCV, you must compile it :
cd C:\opencv
mkdir my_build
cd my_build
cmake -G "MinGW Makefiles" ../sources
mingw32-make # took 2 hours on my computer
and next add, C:\opencv\my_build and C:\opencv\my_build\bin to the system path.
You can try setting manually the cxx path, see CMAKE_C_COMPILER from link which tells you more or less link this:
CXX=C:\path\to\g++ cmake ..
But, I would recommend you to see why cmake doesn't recognize your cxx compiler. I would double check your environment paths.
Maybe not the best answer but get things going. Install Bash On Ubuntu On Windows and install cmake and make using sudo apt-get install cmake and sudo apt-get install build-essential if you don't already have them installed. However, Bash On Ubuntu On Windows only comes with Windows 10 and for accessing a specific drive you should use /mnt/c instead of C:\
Follow this official tutorial to install Bash On Ubuntu On Windows.
mona#DESKTOP-0JQ770H:/mnt/c$ cmake -version
cmake version 2.8.12.2
mona#DESKTOP-0JQ770H:/mnt/c$ make -version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Additionally, of course you can install git in Bash On Ubuntu On Windows
sudo apt-get install git
mona#DESKTOP-0JQ770H:/mnt/c$ git --version
git version 1.9.1
though I don't suggest using a Linux-based git for pushing to github for a Windows specific SDK/code. I would still stick to Git Bash for dealing with git.
*I used to use CMAKE GUI for dealing with CMake in Windows 10 and then port my stuff to Visual Studio. That is also a neat solution depending on your codebase.