I working with custom fork of Chromium, and need introduce some //third_party dependency , which is CMake based project. Because Chromium uses gn and BUILD.gn as basic "make file" I can't understand how I can build CMake project with context of Chromium build or how to obtain semantically same BUILD.gn .
Because CMakeLists.txt of CMake project is huge, it's a little bit tricky to convert it manually .
Will be grateful for help.
Related
I have a static library libXY and a program exeA using it. I fail to find a proper project setup which allows me to use ninja from within Eclipse CDT to build only what is needed to build.
So far, I had one project with ninja build files created by cmake which defined several targets which was perfect for building from command line:
build everything if anything changed (aka ninja all)
build libXY if any source files changed (aka ninja libXY)
build libXY if any source files changed and build exeA if any source file changed and link (aka ninja exeA)
I imported the project (created with cmake's Eclipse CDT / Ninja generator) into Eclipse CDT, but there, I could only build everything (ninja all). I was unable to get Ctrl-B to build just the library and the proper target, I was unable to define targets within Eclipse.
As plan B, I created a setup where libXY and exeA are independent projects. I am unable to define the dependency from exeA to libXY so that the library is built automatically if any of its source files changed.
Help! What is the proper project architecture?
I am trying to use the assimp library in a cross platform C++ project. I include the repo as a git submodule, so, effectively, if someone downloads my project they will also download the ASSIMP project.
After I go through the assimp build / CMAKE instructions and (on Linux) type make install and from then on in my project I can use:
target_link_libraries(${PROJECT_NAME} assimp)
However, there is no make install on Windows.
The only other way I have been able to include the library on Linux is to put (in my CmakeLists.txt file):
target_link_libraries(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/build/assimp/code/libassimp.so)
This is not cross platform as it hardcodes the name and location of the .so file which will not work on Windows.
How can I expose the library so that I can do something like target_link_libraries(${PROJECT_NAME} assimp) on all platforms?
My directory tree looks like:
- src
- include
- assimp
- bin
Where the assimp directory in the include directory is the git submodule
I think you're going about this the wrong way. You don't need to build assimp in a separate step from your project, and you don't need to make install to make it available.
There are a number of ways of handling third party dependencies in Cmake, since you've already chosen to submodule the assimp repository, we'll start there. Assuming assimp is located in the root of your repository in a directory called assimp/ this would be a barebones project including it:
cmake_minimum_required(VERSION 3.0)
project(Project myassimpproj)
# include your directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
# set any variables you might need to set for your app and assimp
set(BUILD_ASSIMP_TOOLS ON)
set(ASSIMP_BUILD_STATIC_LIB ON)
# add assimp source dir as a subdirectory, effectively making
# assimp's CMakeLists.txt part of your build
add_subdirectory(/path/to/assimp ${CMAKE_BINARY_DIR}/assimp)
add_executable(assimp_target main.cpp)
# be sure to link in assimp, use platform-agnostic syntax for the linker
target_link_libraries(assimp_target assimp)
There may be a better way of phrasing this using generator expressions syntax, but I haven't looked at assimp's CMakeLists.txt to know if it's supported (and this is a more generic way anyway.)
Not every project uses Cmake, so you may not be able to just add_subdirectory(). In those cases, you can effectively "fake" a user call to build them using their build commands on respective platforms. execute_process() runs a command at configure time add_custom_command() and add_custom_target() run commands at build time. You then create a fake target to make integration and cross your fingers they support Cmake someday.
You can also use the ExternalProject commands added to Cmake to create a custom target to drive download, update/patch, configure, build, install and test steps of an external project, but note that this solution and the next download the dependency rather than using the submodule'd source code.
Finally, I prefer to work with prebuilt dependencies, cuts down on build time, and they can be unit tested on their own outside of the project. Conan is an open source, decentralized and multi-platform package manager with very good support for C++ and almost transparent support for Cmake when used the right way. They have grown very stable in the last year. More information on how to use Conan with Cmake can be found here.
My cmake --version is 2.8.12.2.
I configure my project build with these commands:
cmake ../klein/ -DBUILD_KLEIN_DEPS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=1
cmake ../klein/ -DBUILD_KLEIN_DEPS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake ../klein/ -DBUILD_KLEIN_DEPS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=on
CMAKE_EXPORT_COMPILE_COMMANDS=1 cmake ../klein/ -DBUILD_KLEIN_DEPS=1
From a clean build, and from a directory with an existing successful build. And want to see the compiler_commands.json file, but it does not appear.
At which moment should it be created: after cmake, or after make command? Where should it be in ./, or in ../klein directory? My cmake does not say anything about this option while it always complains about unused build variables.
Should it work from in a "dirty" directory, where I've performed one successful build, or does it work only on a fresh run in an empty folder?
Edit:
I use a default generator "Unix Makefiles" on my ubuntu linux machine
Edit2:
I'm not an author of the project under the question (I just want to explore it with rtags which requires compile_commands.json file), and I'm not very familiar with CMake mechanics. However, the CMakeLists.txt is probably configured as a super-build (it indeed downloads and builds dependencies - like llvm, z3, ...), and it includes ExternalProject, however it also builds the project itself (klein) from sources. So it's a mix, as I would say.
Can you specify what generator your using? A quick scan of the cmake source from version 3.1.0 suggests that this command is still only available in the following 2 cases.
if(CMAKE_GENERATOR MATCHES "Unix Makefiles")
and
if(CMAKE_GENERATOR MATCHES "Ninja")
if you're using Visual Studio directly you're out of luck unless you want to add a patch to CMake. Otherwise, I know many Windows developers who've gone to Ninja. One advantage is that it's vastly faster than Visual Studio for building. If you are, in fact using Ninja or Unix Makefiles, then it's worth digging deeper.
This has been asked here before but I couldn't find a solution which works for me.
Sample CMakeLists.txt file for LLVM project - This was the original question.
However, there are a couple of issues I am facing when making a project with LLVM.
Platform: Windows 7
Compiler: MingW
1) Firstly, I am using the svn version of llvm which is currently at 3.1. Currently, Binaries for MingW are not present for llvm 3.0 too so I decided to go with the latest itself and build it with mingw. So although the build works fine, I cannot seem to find the llvm-config perl script in the bin folder. I tried searching the entire dir yet I can only find an llvm-config folder and a dependencies file.
2) I tried building llvm for Visual studio 2010 yet that didn't work with cmake so I had to use MingW.
3) Now, this is sequence in which I add libs to CMake -
LLVMXCoreInfo
LLVMMipsAsmPrinter
LLVMMipsCodeGen
LLVMMipsInfo
LLVMMBlazeAsmPrinter
LLVMMBlazeCodeGen
LLVMMBlazeInfo
LLVMLinker
LLVMipo
LLVMInterpreter
LLVMInstrumentation
LLVMJIT
LLVMExecutionEngine
LLVMMC
LLVMBitWriter
LLVMX86Disassembler
LLVMX86AsmParser
LLVMX86AsmPrinter
LLVMX86CodeGen
LLVMX86Info
LLVMAsmParser
LLVMARMAsmParser
LLVMMCParser
LLVMARMAsmPrinter
LLVMARMCodeGen
LLVMARMInfo
LLVMArchive
LLVMBitReader
LLVMSelectionDAG
LLVMAsmPrinter
LLVMCodeGen
LLVMScalarOpts
LLVMInstCombine
LLVMTransformUtils
LLVMipa
LLVMAnalysis
LLVMTarget
LLVMMC
LLVMCore
LLVMSupport
imagehlp
psapi
m
4) However, adding InitializeNativeTarget(), starts giving me linking errors which I think come because of the dependencies not being in right order.
5) I want to use the llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native) and hence I added this to my CMakeLists.txt
INCLUDE(cmake/LLVM-Config.cmake)
However, this doesn't work. CMake Error at cmake/LLVM-Config.cmake:141 (message):
Library `jit' not found in list of llvm libraries.
Now, the question is really too long but I basically wanted to ask what is the best way to do this in CMake. Could someone post the entire thing (for windows).
Also, is there a way to build it for VS 2010. I tried the instructions on CLang site but those gave me this error in CMake.
" string sub-command REGEX, mode MATCH needs at least 5 arguments total to command."
I really need some help figuring out how to get dependencies to work in llvm and for it to build with VS. I would really appreciate some help.
I'm trying to build a project in a cross-platform manner.
I'm using CMake to generate project files on the fly, but it's not clear how to then compile those project files in a cross-platform way. I found try_compile but it's not clear whether this will do what I want. Any ideas?
For example, say I am using Visual Studio 2010 against project foo. I am expecting CMake to generate foo.sln, and then build it (generate the binaries). I know how to automate the first part, but how do I automate the second?
From the CMake docs:
"CMake is a cross-platform build system generator."
So in other words, once CMake has generated the project files, it's work is really done.
You can invoke the native build tool via CMake using the --build flag, e.g.
cmake --build . --config Release --target install -- /M:4
See here for further info.