aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorBrenden Blanco <bblanco@gmail.com>2017-06-26 13:37:34 -0700
committerBrenden Blanco <bblanco@gmail.com>2017-08-25 16:41:36 -0700
commit25f3ccee72f50f14fd51166a9839f86570be9f72 (patch)
tree6e7c90abe29bbe5401f7946d08674bf67c8aba92 /cmake
parentdcb77e60642d8ec4f463881313462a8ebd9ce1d6 (diff)
downloadbcc-25f3ccee72f50f14fd51166a9839f86570be9f72.tar.gz
src/cc: cmake file cleanup and split usdt into subdir
Move two usdt related files to a new subdirectory and link them into the final product. Introduce a cmake option to disable that feature (turning it off currently fails to compile). Move some of the cmake flag computation into a helper cmake file and include that rather than inlining it. Signed-off-by: Brenden Blanco <bblanco@gmail.com>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/clang_libs.cmake42
-rw-r--r--cmake/static_libstdc++.cmake15
2 files changed, 57 insertions, 0 deletions
diff --git a/cmake/clang_libs.cmake b/cmake/clang_libs.cmake
new file mode 100644
index 00000000..907b784f
--- /dev/null
+++ b/cmake/clang_libs.cmake
@@ -0,0 +1,42 @@
+set(llvm_raw_libs bitwriter bpfcodegen irreader linker
+ mcjit objcarcopts option passes nativecodegen lto)
+list(FIND LLVM_AVAILABLE_LIBS "LLVMCoverage" _llvm_coverage)
+if (${_llvm_coverage} GREATER -1)
+ list(APPEND llvm_raw_libs coverage)
+endif()
+list(FIND LLVM_AVAILABLE_LIBS "LLVMCoroutines" _llvm_coroutines)
+if (${_llvm_coroutines} GREATER -1)
+ list(APPEND llvm_raw_libs coroutines)
+endif()
+llvm_map_components_to_libnames(_llvm_libs ${llvm_raw_libs})
+llvm_expand_dependencies(llvm_libs ${_llvm_libs})
+
+# order is important
+set(clang_libs
+ ${libclangFrontend}
+ ${libclangSerialization}
+ ${libclangDriver}
+ ${libclangParse}
+ ${libclangSema}
+ ${libclangCodeGen}
+ ${libclangAnalysis}
+ ${libclangRewrite}
+ ${libclangEdit}
+ ${libclangAST}
+ ${libclangLex}
+ ${libclangBasic})
+
+# prune unused llvm static library stuff when linking into the new .so
+set(_exclude_flags)
+foreach(_lib ${clang_libs})
+ get_filename_component(_lib ${_lib} NAME)
+ set(_exclude_flags "${_exclude_flags} -Wl,--exclude-libs=${_lib}")
+endforeach(_lib)
+set(clang_lib_exclude_flags "${_exclude_flags}")
+
+set(_exclude_flags)
+foreach(_lib ${llvm_libs})
+ get_filename_component(_lib ${_lib} NAME)
+ set(_exclude_flags "${_exclude_flags} -Wl,--exclude-libs=lib${_lib}.a")
+endforeach(_lib)
+set(llvm_lib_exclude_flags "${_exclude_flags}")
diff --git a/cmake/static_libstdc++.cmake b/cmake/static_libstdc++.cmake
new file mode 100644
index 00000000..3c8ac179
--- /dev/null
+++ b/cmake/static_libstdc++.cmake
@@ -0,0 +1,15 @@
+# only turn on static-libstdc++ if also linking statically against clang
+string(REGEX MATCH ".*[.]a$" LIBCLANG_ISSTATIC "${libclangBasic}")
+# if gcc 4.9 or higher is used, static libstdc++ is a good option
+if (CMAKE_COMPILER_IS_GNUCC AND LIBCLANG_ISSTATIC)
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
+ if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -print-libgcc-file-name OUTPUT_VARIABLE GCC_LIB)
+ get_filename_component(GCC_DIR "${GCC_LIB}" DIRECTORY)
+ find_library(GCC_LIBSTDCPP libstdc++.a PATHS "${GCC_DIR}" NO_DEFAULT_PATH)
+ if (GCC_LIBSTDCPP)
+ message(STATUS "Using static-libstdc++")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
+ endif()
+ endif()
+endif()