I want to build Clang from source but not LLVM. Clang has LLVM as a hard dependency, but instead of building LLVM from source, it should be possible to depend on a pre-installed(pre-built) LLVM binary.
I know this is possible because clang has the following CMake flags -
LLVM_DIR
LLVM_LIBRARY_DIR
LLVM_MAIN_INCLUDE_DIR
LLVM_TOOLS_BINARY_DIR
and Clang's CMakeLists.txt also has provisions to rely on a previously installed version of LLVM. (https://github.com/llvm-mirror/clang/blob/master/CMakeLists.txt#L14)
I got the LLVM 9 binary and Clang 9 source code from here - http://releases.llvm.org/download.html#9.0.0
I am trying to build Clang with -
cmake -DLLVM_BUILD_TOOLS=Off -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=host ../
But, I get the following errors -
CMake Error at /home/reik/Downloads/clang/lib/cmake/llvm/AddLLVM.cmake:467 (add_library):
add_library cannot create target "SampleAnalyzerPlugin" because an imported
target with the same name already exists.
Call Stack (most recent call first):
/home/reik/Downloads/clang/lib/cmake/llvm/AddLLVM.cmake:665 (llvm_add_library)
lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:6 (add_llvm_library)
CMake Error at /home/reik/Downloads/clang/lib/cmake/llvm/AddLLVM.cmake:585 (target_link_libraries):
Cannot specify link libraries for target "SampleAnalyzerPlugin" which is
not built by this project.
Call Stack (most recent call first):
/home/reik/Downloads/clang/lib/cmake/llvm/AddLLVM.cmake:665 (llvm_add_library)
lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:6 (add_llvm_library)
In the above code snippet, /home/reik/Downloads/clang is the LLVM binary. (To note, the LLVM binary comes with Clang binary)
It seems like since the LLVM binary comes with Clang installed, there is some sort of conflict in add_library since some things already exist (Found a related thread here - http://lists.llvm.org/pipermail/llvm-dev/2016-November/107616.html) -> So I think I am missing some sort of configuration steps when building Clang as a standalone project.
Or maybe I just need an LLVM binary that comes without clang installed but I have been unable to find any such thing on LLVM's official website.
Could anyone please help me with this?
i build clang standalone with these commands, then it worked.
on macos 10.15.6, xcode12.1, cmake 3.18.3
1.
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang-11.0.0.src.tar.xz
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-x86_64-apple-darwin.tar.xz
tar xvjf clang+llvm-11.0.0-x86_64-apple-darwin.tar.xz
tar xjvf clang-11.0.0.src.tar.xz
mkdir build && cd build
cmake ../clang-11.0.0.src -DLLVM_CONFIG=../clang+llvm-11.0.0-x86_64-apple-darwin/bin/llvm-config
make -j2
I think you are giving the wrong path to cmake. I think you were pointing to the sub-directory named clang. You should instead point to llvm-project-llvmorg-9.0.0/llvm itself.
Run something like the following:
cmake -DLLVM_BUILD_TOOLS=Off -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=host $LLVM_SRC
Related
I'm using CLion with MinGW-GCC on the Windows-x64 platform - This is the background of the problem.
I was trying to install gtest before. But a lot of confusion arose in the middle.
First time I ran those commands(in googletest-release-1.12.1\) according to the instructions of googletest-release-1.12.1\googletest\README.md:
mkdir build
cd build
cmake ..
But I got error messages like:
CMake Error at CMakeLists.txt:51 (project):
Failed to run MSBuild command:
C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe
to get the value of VCTargetsPath:
Then I changed my last command to
cmake -G "MinGW Makefiles" ..
because I use make provided by MinGW. I don't know whether it's right but, it ran properly.
then I called
make
make install
make ran smoothly. But when I ran make install, I got these messages:
Install the project...
-- Install configuration: ""
-- Installing: C:/Program Files (x86)/googletest-distribution/include
CMake Error at googlemock/cmake_install.cmake:41 (file):
file INSTALL cannot make directory "C:/Program Files
(x86)/googletest-distribution/include": No such file or directory.
Call Stack (most recent call first):
cmake_install.cmake:42 (include)
make: *** [Makefile:109: install] Error 1
I have no idea at all this time. So I changed my way. According to this answer, I copied the whole library into my project and edited CMakeLists.txt like this:
cmake_minimum_required(VERSION 3.23)
project(gtest_study)
set(CMAKE_CXX_STANDARD 20)
add_subdirectory(googletest-release-1.12.1)
include_directories(googletest-release-1.12.1/googletest/include)
include_directories(googletest-release-1.12.1/googlemock/include)
add_executable(gtest_study main.cpp)
target_link_libraries(gtest_study gtest gtest_main)
target_link_libraries(gtest_study gmock gmock_main)
So my questions are:
Is there any difference between the two which build it using make and cmake metioned firstly, and just use commands like include_directories and target_link_libraries in CMakeLists.txt? (maybe like .h and .dll file? Or just completely the same? I don't know)
When I use make install to install a library on Windows, what should I do in particular? Specify some directory (I don't know which one) or what?
Although in my system environment I use MinGW-makefile, in CLion which the libraries are eventually used, I use ninja as the generator for CMake (it just comes with CLion, not installed for the system). Do I have to specify it and how? (-G "Ninja"doesn't work in my native env)
The difference between
cmake ..
and
cmake -G "MinGW Makefiles" ..
Is the choice of generator: The former uses the default generator, the latter uses the generator you specified. (cmake --help should put a * next to the default generator.)
Based on the error message I assume this is a visual studio generator and you may not be able to run that one properly from within a MinGW terminal.
In the latter case the default install directory seems to be based on the target OS (Windows) but does not seem to incorporate the fact that you're running from a MinGW terminal where the default install path (C:/Program Files (x86)/googletest-distribution) is not valid.
You could try to fix this by providing it during cmake configuration (passing -D 'CMAKE_INSTALL_PREFIX=/c/Program Files (x86)/googletest-distribution' before the source dir) or by providing the install directory during the installation.
The following process should allow you to install the lib. I'm using my preferred way of building here, i.e. not using build system dependent commands, but using cmake to run the build/install commands. I assume the working directory to be the root directory of the gtest sources:
cmake -G "MinGW Makefiles" -S . -B build
cmake --build build
cmake --install build --prefix '/c/Program Files (x86)/googletest-distribution'
The last command needs to be run with admin privileges, the first 2 I don't recommend running as admin. You could instead install to a directory where you do have the permissions to create directories even without admin privileges.
The difference between using the process described above and using add_subdirectory is that the former results in a installation on the system which can be used via find_package and the google test libs won't be rebuilt for every project where you do this.
...
project(gtest_study)
...
# you may need to pass the install location via -D CMAKE_PREFIX_PATH=<install_location> during configuration for this to work
find_package(GTest REQUIRED)
target_link_libraries(gtest_study PRIVATE GTest::gtest_main GTest::gmock)
The latter builds the google test project as part of your own project build and for every project where you use this approach a seperate version of the google test libs is built. Note: there should be no need to specify the include dirs yourself, since this kind of information is attached to the cmake target and gets applied to the linking target automatically:
#include_directories(googletest-release-1.12.1/googletest/include)
#include_directories(googletest-release-1.12.1/googlemock/include)
add_executable(gtest_study main.cpp)
target_link_libraries(gtest_study PRIVATE gtest_main gmock)
As for 3.: The CMake generator used for building GTest should be independent of the generator of the project using it. The thing that's important is that the compilers used by the build systems are compatible. I cannot go into detail about this, since I've never used CLion and therefore have too little knowlege about the compilers used by it. (Personally I'm working with Visual Studio on Windows.)
I am very new (my first time) to installing software through command lines and source files and C++. So the solution could be quite simple but I just simply don't understand it.
My objective here is to install the GODDeSS-Package following these instructions.
I am currently under the section "How to install the example simulation" and I am stuck on the final step (step 8). To my knowledge, I believe I have installed all the prerequisite software correctly listed from steps 1-3.
Following the procedures when I arrive at step 8, I execute the following command and receive this error:
$cmake C:/Users/Patrick/Desktop/Research/GODDeSS-Package/goddess-package/GODDeSS_4_3/source
...
Could NOT find Boost (missing: regex) (found version "1.59.0")
...
I used the ellipse to show there is text before and after that error message. However this is not the main problem. I was able to over come this with a add-on argument (which I don't really understand how it works) -DBoost_USE_STATIC_LIBS=ON
So after this modification, I get the following results:
$cmake C:/Users/Patrick/Desktop/Research/GODDeSS-Package/goddess-package/GODDeSS_4_3/source -DBoost_USE_STATIC_LIBS=ON
...
-- Generating done
-- Build files have been written to: C:/Users/Patrick/Desktop/Research/GODDeSS-Package/goddess-build
So I assume part 1 of step 8 done correctly? ...since it says "Generating done".
Now here is where I run into the problem. the next command is:
$make -j install
But I don't have a Makefile in the generated files!
Here is a picture of my build directory which I have generated the files into:
Build Directory Picture
I have done some reading and it seems like cmake is Building for Visual Studios 16 2019 so it creates the .sln files instead (theres alot of them! Almost one in every folder). I'm not entire sure how to deal with this situation. Instead I tried to force cmake to generate me a Makefile by using the add-on command -G "MinGW Makefiles" I picked MinGW randomly just because it was one of the few options that generated a Makefile.
So I created a fresh build directory and used the following command:
cmake -G "MinGW Makefiles" C:/Users/Patrick/Desktop/James_L_Pinfold_Research/GODDeSS-Package/goddess-package/GODDeSS_4_3/source -DBoost_USE_STATIC_LIBS=ON
But I get the following error:
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
So now I'm stuck... I see 2 paths I can go down. 1. Make use of the .sln files created by cmake to install the package... or 2. Somehow make cmake create a Makefile so I can use the make command. Neither of which how to do.
I'm having a hard time trying to find documentations of how to install this package but I have yet to succeed. What can I try next?
I am using Windows 10, Terminal: Git Bash, Visual Studios 2019, Boost_1_5_9, zlib1211, geant4_10_02_p03, and cmake-3.17.2
I'm interested in CMake, so decided to learn about it. I followed the CMake Tutorial until the point where it states "That is all there is to it. At this point you should be able to build the tutorial", so I thought, let's try it!
Alas, it seems it wasn't all so simple. I initially attempted to run cmake -A "Unix Makefiles" after consulting cmake --help, but no luck there either. Rather, it gives me the following:
CMake Error at CMakeLists.txt:2 (project):
Generator
Unix Makefiles
does not support platform specification, but platform
Unix Makefiles
was specified.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
I began searching around on the Internet and found this, but it gave me the exact same error. Other answers I found seemed to be Windows-related, but myself I'm on Fedora 29.
I want to generate a makefile using CMake, any suggestions? (I have gcc and g++ installed, by the way)
On Fedora, generating Unix Makefiles (e.g. Makefile, which GNU Make will be able to use) is probably the default. In general, don't specify a generator: then you'll get what makes the most sense on your installed OS. Some OS do pick a different default: FreeBSD uses Ninja, for instance.
When running CMake you may need to specify the source-directory. If CMake has been run before, successfully, you can leave off the directory. When there are no other options or arguments to CMake, you'll need to give the directory.
If you've copy-pasted the CMakeLists and C++ files from the tutorial page, this will create whatever build-system comes from the default generator:
cmake .
Do note that if you don't give CMake any arguments at all, then it gives you a usage string. That's why there's that . there, to build from the current directory. If you want to specify a particular generator,
cmake -G "Unix Makefiles" .
If you are building in a separate directory (generally a good idea)
cmake /path/to/the/sources
Your original error message, by the way, tells you that CMake is, by default, using the generator Unix Makefiles, which doesn't support setting a platform. The no-arguments-at-all behavior seems to have tripped you up afterwards.
After a discussion in the comments, I realised the issue was that I had done it wrong from the start. The solution ultimately was to remove all CMake-related files (except for CMakeLists.txt and do it all over again, this time running cmake .. on its own (without any arguments) from a subdirectory.
I am trying to build linphone on linux Ubuntu 16.04 32 bit system. I have downloaded all the required libraries and install cmake. But i always ended with error as shown below.
cmake /home/silvans/linphone_new/linphone-android/submodules/cmake-builder -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=/home/silvans/linphone_new/linphone-android/liblinphone-sdk/android-arm64 -DCMAKE_INSTALL_PREFIX=/home/silvans/linphone_new/linphone-android/liblinphone-sdk/android-arm64 -DCMAKE_NO_SYSTEM_FROM_IMPORTED=YES -DLINPHONE_BUILDER_WORK_DIR=/home/silvans/linphone_new/linphone-android/WORK/android-arm64 -DCMAKE_TOOLCHAIN_FILE=toolchains/toolchain-android-arm64.cmake -DCMAKE_INSTALL_MESSAGE=LAZY -DLINPHONE_BUILDER_CONFIG_FILE=configs/config-android.cmake -DLINPHONE_BUILDER_EXTERNAL_SOURCE_PATH=/home/silvans/linphone_new/linphone-android/submodules
-- Android: Selected Clang toolchain 'aarch64-linux-android-clang3.6' with GCC toolchain 'aarch64-linux-android-4.9'
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error in CMakeLists.txt:
The CMAKE_C_COMPILER:
/home/silvans/Downloads/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error in CMakeLists.txt:
The CMAKE_CXX_COMPILER:
/home/silvans/Downloads/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang++
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/silvans/linphone_new/linphone-android/WORK/android-
arm64/cmake/CMakeFiles/CMakeOutput.log".
See also "/home/silvans/linphone_new/linphone-android/WORK/android-arm64/cmake/CMakeFiles/CMakeError.log".
As per error shown set the path for CC and CXX as below,
export CC=/usr/bin/gcc
export PATH=$PATH:$CC
export CXX=/usr/bin/g++
export PATH=$PATH:$CXX
But still i am getting the same error message. Please let me know what is wrong in the path variable of C and C++ compilers. How can i set them in the system so that cmake can find the path of both compilers.
Thanks,
Your compiler is not able to locate proper toolchain.
exporting it to /usr/bin/gcc is not correct solution, because i.e. gcc compiler for your native machine and if I'm right here you trying to cross compile.
Follow the link given below:
https://github.com/android-ndk/ndk/issues/111
Linphone wiki:
https://linphone.org/dokuwiki/doku.php/getting-started:android
See if it is helpful.
I am trying to build PoDoFo Library on my Windows Platform (for use as an API). It is done using CMake. The ReadMe file says the following. Unfortunately I am new to CMake and I can't make out much from it.
Building PoDoFo on Windows
CMake 2.6.x is required for Windows. You can download it from
cmake.org .
On Windows, PoDoFo may be built as either a shared or static library.
Building both is not supported. By default only the shared library
will be built. If you want a static library, just disable generation
of the shared library with the extra argument to cmake:
-DPODOFO_BUILD_SHARED=FALSE
Handling library naming on win32
Especially on Windows it is also common for custom built libraries to
have different names to those you might download as pre-built copies.
CMake won't be able to find them if they're called something else
unless you tell it. Use these variables to tell CMake what names to
look for a library under:
•FREETYPE_LIBRARY_NAMES_DEBUG, FREETYPE_LIBRARY_NAMES_RELEASE and FREETYPE_LIBRARY_NAMES
•TIFF_LIBRARY_NAMES_DEBUG, TIFF_LIBRARY_NAMES_RELEASE and TIFF_LIBRARY_NAMES
•LIBJPEG_LIBRARY_NAMES_DEBUG, LIBJPEG_LIBRARY_NAMES_RELEASE and LIBJPEG_LIBRARY_NAMES
•ZLIB_LIBRARY_NAMES_DEBUG, ZLIB_LIBRARY_NAMES_RELEASE,ZLIB_LIBRARY_NAMES
CMake builds on Windows with MinGW
Once MinGW is set up, make sure that the MinGW "bin" directory is on
your PATH, and be sure to set CMAKE_INCLUDE_PATH and
CMAKE_LIBRARY_PATH such that CMake can find the headers and .lib files
for the libraries PoDoFo requires. The GnuWin32 library packages from
http://gnuwin32.sf.net/ are known to work with PoDoFo, so installing
zlib, freetype, and libjpeg from there should do the trick.
To configure and build PoDoFo with a default GnuWin32 install and with
MinGW already on your PATH:
md ..\podofo-debug
cd ..\podofo-debug
cmake -G "MinGW Makefiles" ..\podofo-src -DCMAKE_INCLUDE_PATH=c:\progra~1\gnuwin32\include -DCMAKE_LIBRARY_PATH=c:\progra~1\gnuwin32\lib -DPODOFO_BUILD_SHARED:BOOL=FALSE mingw32-make
I have installed CMake and downloaded the other libraries mentioned like freetype, zlib, libjpeg. Their header and binary files are in their respective folders.
Now what should DCMAKE_INCLUDE_PATH and DCMAKE_LIBRARY_PATH be? Also what is "MinGW Makefiles"? Do I have to supply any extra parameters?
I'll be grateful if someone can explain in simple steps how I can go about it.
EDIT: error while executing CMAKE:
-- Ensure you cppunit installed version is at least 1.12.0
Cppunit not found. No unit tests will be built.
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPack
ageHandleStandardArgs.cmake:97 (message):
Could NOT find FREETYPE (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStan
dardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
cmake/modules/FindFREETYPE.cmake:75 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:372 (FIND_PACKAGE)
To build PoDoFo you need installed GnuWin32, CMake, MinGW32 and PoDoFo sources
download GetGnuWin32
install to c:\getgnuwin32
open cmd.exe
cd c:\getgnuwin32
download.bat
install.bat
Then as suggested in #ibizaman answer
cmake -G "MinGW Makefiles" -DCMAKE_INCLUDE_PATH="C:\gnuwin32\include" -DCMAKE_LIBRARY_PATH="C:\gnuwin32\lib" -DPODOFO_BUILD_STATIC=TRUE ..
FreeType should be installed with GnuWin32 packages
If you followed all the instructions, to compile it should normally be enough to do:
cd <podofo root directory (where CMakeLists.txt is)>
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_INCLUDE_PATH=<path to headers> -DCMAKE_LIBRARY_PATH=<path to libraries> -DPODOFO_BUILD_SHARED:BOOL=FALSE ..
mingw32-make
Step by step:
First, go to the directory where your podofo sources are. You should see a CMakeLists.txt file lying around.
Second (and third), create (and go into) a directory where the compilation will be done. I call it build but it can be any name. This is a best practice since you can simply delete the build directory and come back to a clean state.
Fourth, ask cmake to create the makefile(s) for mingw:
Specify the PODOFO_BUILD_SHARED like advertised in the manual: build shared or static version.
CMAKE_INCLUDE_PATH and CMAKE_LIBRAY_PATH are used to reference to the packages needed to build podofo. If you downloaded the precompiled packages like you did since you have de headers and the binaries, then you need to give to cmake the path to those headers and binaries. You can specify the variables multiple times if needed, e.g.:
cmake -G "MinGW Makefiles" -DCMAKE_INCLUDE_PATH=/path/to/freetype/include -DCMAKE_LIBRARY_PATH=/path/to/freetype/lib -DCMAKE_INCLUDE_PATH=/path/to/zlib/include -DCMAKE_LIBRARY_PATH=/path/to/zlib/lib -DPODOFO_BUILD_SHARED:BOOL=FALSE ..
The "MinGW Makefiles" tells cmake to create makefiles specific to mingw. Else, by default on windows, it creates makefiles specific to Microsoft Visual Studio.
Finaly reference the CMakeLists.txt in the parent directory with .. at the end.
Last, but not least, compile with the mingw version of make.