Add c-library only option

Allow building of JUST the libbpf library and related headers. No clang,
llvm, python, lua, etc. Not even tests :(

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f2bdd55..b0a75be 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,13 +16,18 @@
 include(CheckCXXCompilerFlag)
 include(cmake/FindCompilerFlag.cmake)
 
+option(ENABLE_CLANG_JIT "Enable Loading BPF through Clang Frontend" ON)
+option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
+CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
+
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
-if(NOT PYTHON_ONLY)
+if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
 find_package(BISON)
 find_package(FLEX)
 find_package(LLVM REQUIRED CONFIG)
 message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS}")
+find_package(LibElf REQUIRED)
 
 # clang is linked as a library, but the library path searching is
 # primitively supported, unlike libLLVM
@@ -52,10 +57,6 @@
   set(BCC_KERNEL_MODULES_DIR "/lib/modules")
 endif()
 
-find_package(LibElf REQUIRED)
-
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
-
 # As reported in issue #735, GCC 6 has some behavioral problems when
 # dealing with -isystem. Hence, skip the warning optimization
 # altogether on that compiler.
@@ -76,11 +77,15 @@
   message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
 endif()
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
-endif()
+endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
 
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
+
+add_subdirectory(src)
+if(ENABLE_CLANG_JIT)
 add_subdirectory(examples)
 add_subdirectory(man)
-add_subdirectory(src)
 add_subdirectory(tests)
 add_subdirectory(tools)
+endif(ENABLE_CLANG_JIT)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 8ad6126..55e92b6 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,7 +1,9 @@
 set(EXAMPLE_PROGRAMS hello_world.py)
 install(PROGRAMS ${EXAMPLE_PROGRAMS} DESTINATION share/bcc/examples)
 
+if(ENABLE_CLANG_JIT)
 add_subdirectory(cpp)
 add_subdirectory(lua)
 add_subdirectory(networking)
 add_subdirectory(tracing)
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 02e4f02..7daca5b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,5 +10,7 @@
 if(NOT PYTHON_ONLY)
 add_subdirectory(cc)
 endif()
+if(ENABLE_CLANG_JIT)
 add_subdirectory(python)
 add_subdirectory(lua)
+endif()
diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt
index 8d4b7dc..72a521c 100644
--- a/src/cc/CMakeLists.txt
+++ b/src/cc/CMakeLists.txt
@@ -28,10 +28,13 @@
 set(bcc_table_sources table_storage.cc shared_table.cc bpffs_table.cc json_map_decl_visitor.cc)
 set(bcc_util_sources ns_guard.cc common.cc)
 set(bcc_sym_sources bcc_syms.cc bcc_elf.c bcc_perf_map.c bcc_proc.c)
+set(bcc_common_headers libbpf.h perf_reader.h)
+set(bcc_table_headers file_desc.h table_desc.h table_storage.h)
+set(bcc_api_headers bpf_common.h bpf_module.h bcc_exception.h bcc_syms.h)
 
+if(ENABLE_CLANG_JIT)
 add_library(bcc-shared SHARED
-  link_all.cc
-  ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources}
+  link_all.cc ${bcc_common_sources} ${bcc_table_sources} ${bcc_sym_sources}
   ${bcc_util_sources})
 set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0)
 set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc)
@@ -48,9 +51,6 @@
 set(bcc_common_libs b_frontend clang_frontend bpf-static
   ${clang_libs} ${llvm_libs} ${LIBELF_LIBRARIES})
 
-option(ENABLE_USDT "Enable User-level Statically Defined Tracing" ON)
-CMAKE_DEPENDENT_OPTION(ENABLE_CPP_API "Enable C++ API" ON "ENABLE_USDT" OFF)
-
 if(ENABLE_CPP_API)
   add_subdirectory(api)
   list(APPEND bcc_common_libs api-static)
@@ -61,20 +61,17 @@
   list(APPEND bcc_common_libs usdt-static)
 endif()
 
+add_subdirectory(frontends)
+
 # Link against LLVM libraries
 target_link_libraries(bcc-shared ${bcc_common_libs})
 target_link_libraries(bcc-static ${bcc_common_libs} bcc-loader-static)
 
-install(TARGETS bcc-shared LIBRARY COMPONENT libbcc
-  DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(FILES bpf_common.h bpf_module.h bcc_syms.h bcc_exception.h file_desc.h
-              libbpf.h perf_reader.h
-              table_desc.h table_storage.h COMPONENT libbcc
-  DESTINATION include/bcc)
-install(DIRECTORY compat/linux/ COMPONENT libbcc
-  DESTINATION include/bcc/compat/linux
-  FILES_MATCHING PATTERN "*.h")
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc COMPONENT libbcc
-  DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-
-add_subdirectory(frontends)
+install(TARGETS bcc-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+install(FILES ${bcc_table_headers} DESTINATION include/bcc)
+install(FILES ${bcc_api_headers} DESTINATION include/bcc)
+install(DIRECTORY compat/linux/ DESTINATION include/bcc/compat/linux FILES_MATCHING PATTERN "*.h")
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbcc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+endif(ENABLE_CLANG_JIT)
+install(FILES ${bcc_common_headers} DESTINATION include/bcc)
+install(TARGETS bpf-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 52782e3..86abec9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -7,6 +7,8 @@
 add_test(NAME style-check COMMAND ${CMAKE_SOURCE_DIR}/scripts/style-check.sh)
 set_tests_properties(style-check PROPERTIES PASS_REGULAR_EXPRESSION ".*")
 
+if(ENABLE_CLANG_JIT)
 add_subdirectory(cc)
 add_subdirectory(python)
 add_subdirectory(lua)
+endif()