OCLint.3.OCLintConfig.cmake-file
OCLintConfig.cmake file
1. Introduction
OCLintConfig.cmake is as a CMake Module which is refered by CMakeLists.txt of oclint modules(oclint-core,oclint-driver,
oclint-metrics,oclint-reporters,oclint-rules). The following is an example:
SET(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/../oclint-core/cmake"
)
INCLUDE(OCLintConfig)
2. What's CMake Module?
"Code reuse is a valuable technique in software development and CMake has been designed to support it.
Allowing CMakeLists files to make use of reusable modules enables the entire community to share
reusable sections of code. For CMake, these sections are called cmake-modules
and can be found
in the Modules subdirectory of your installation." Ref[1]
3. What does OCLintConfig.cmake do?
3.1 Set values for variables
OCLintConfig.cmake set the value for the following variable:
CMAKE_DISABLE_SOURCE_CHANGES
CMAKE_DISABLE_IN_SOURCE_BUILD
CMAKE_MACOSX_RPATH
CMAKE_CXX_FLAGS
CMAKE_SHARED_LINKER_FLAGS
EXECUTABLE_OUTPUT_PATH
3.2 Find and Include the LLVMConfig module
Set the include directory to ${LLVM_INCLUDE_DIRS}.
Set the link directory to ${LLVM_LIBRARY_DIRS}.
Add -D define flags from ${LLVM_DEFINITIONS} to the compilation of source files.
3.3 CLANG_LIBRARIES
LLVM_MAP_COMPONENTS_TO_LIBNAMES(REQ_LLVM_LIBRARIES asmparser bitreader instrumentation mcparser option support frontendopenmp) SET(CLANG_LIBRARIES clangToolingCore clangTooling clangFrontend clangDriver clangSerialization clangParse clangSema clangAnalysis clangEdit clangASTMatchers clangAST clangLex clangBasic)
A. llvm_map_components_to_libnames function
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)
This function (llvm_map_components_to_libnames) is defined in LLVM-Config.cmake. It will map the components to libraries list which is saved
in the first parameter (llvm_libs, in the above code snippet).
llvm-config
"The list of libraries is determined by using the llvm_map_components_to_libnames()
CMake function.
For a list of available components look at the output of running llvm-config --components
." Ref[3]
The install path of llvm by 'brew install llvm' is /usr/local/opt/llvm/bin/llvm-config.
The output of './llvm-config --components' as the following:
$ ./llvm-config --components aggressiveinstcombine all all-targets analysis asmparser asmprinter
binaryformat bitreader bitstreamreader bitwriter cfguard codegen
core coroutines coverage debuginfocodeview debuginfodwarf
debuginfogsym debuginfomsf debuginfopdb demangle
dlltooldriver dwarflinker dwp engine executionengine
extensions filecheck frontendopenacc frontendopenmp
fuzzmutate globalisel instcombine instrumentation
interfacestub interpreter ipo irreader jitlink libdriver
lineeditor linker lto mc mca mcdisassembler mcjit mcparser
mirparser native nativecodegen objcarcopts object objectyaml
option orcjit orcshared orctargetprocess passes profiledata
remarks runtimedyld scalaropts selectiondag support symbolize
tablegen target textapi transformutils vectorize windowsmanifest
x86 x86asmparser x86codegen x86desc x86disassembler x86info xray
B. CLANG_LIBRARIES
Set the CLANG_LIBRARIES variable to the libraries list: clangToolingCore, clangTooling, clangFrontend,
clangDriver, clangSerialization, clangParse, clangSema, clangAnalysis, clangEdit, clangASTMatchers,
clangAST, clangLex, clangBasic.
The header files for these libraries are at the ${LLVM_ROOT_PATH}/clang/include/clang. The source file for
these libraries are ${LLVM_ROOT_PATH}/clang/lib .
Reference
1. Using Modules
https://cmake.org/cmake/help/book/mastering-cmake/chapter/Modules.html
2. add_definitions
Add -D define flags to the compilation of source files.
https://cmake.org/cmake/help/v3.23/command/add_definitions.html
3. Building LLVM with CMake
https://llvm.org/docs/CMake.html