I'm trying to write a CMake function that creates an object library of LLVM bitcode files. Here is what I have so far
function(build_llvm_lib OUTPUT SRC)
if(NOT LLVM_FOUND)
message(FATAL_ERROR "LLVM build requested but LLVM not found")
endif()
set(SRCS ${SRC} ${ARGN})
set(CMAKE_C_OUTPUT_EXTENSION ".bc")
set(CMAKE_CXX_OUTPUT_EXTENSION ".bc")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -emit-llvm")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -emit-llvm")
set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++)
set(CMAKE_AR ${LLVM_TOOLS_BINARY_DIR}/llvm-ar)
set(CMAKE_RANLIB ${LLVM_TOOLS_BINARY_DIR}/llvm-ranlib)
add_library(${OUTPUT} OBJECT ${SRCS})
endfunction(build_llvm_lib)
However, the problem that I'm having is that even though I am setting the CMake variables like CMAKE_CXX_FLAGS
and CMAKE_CXX_OUTPUT_EXTENSION
these don't seem to be having any affect (i.e. they are being ignore) when CMake is run. When I look at the generated Makefile these settings don't appear and when I run make a regular object file is built rather than an LLVM bitcode file.
I'm kind of a CMake newb, so can someone please explain what's going on here? Is there some sort of misunderstanding I'm making here with CMake functions?