1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
macro(add_compile_flags langs)
foreach(_lang ${langs})
string (REPLACE ";" " " _flags "${ARGN}")
set ("CMAKE_${_lang}_FLAGS" "${CMAKE_${_lang}_FLAGS} ${_flags}")
unset (${_lang})
unset (${_flags})
endforeach()
endmacro(add_compile_flags)
macro(set_source_files_compile_flags)
foreach(file ${ARGN})
get_filename_component(_file_ext ${file} EXT)
set(_lang "")
if ("${_file_ext}" STREQUAL ".m")
set(_lang OBJC)
# CMake believes that Objective C is a flavor of C++, not C,
# and uses g++ compiler for .m files.
# LANGUAGE property forces CMake to use CC for ${file}
set_source_files_properties(${file} PROPERTIES LANGUAGE C)
elseif("${_file_ext}" STREQUAL ".mm")
set(_lang OBJCXX)
endif()
if (_lang)
get_source_file_property(_flags ${file} COMPILE_FLAGS)
if ("${_flags}" STREQUAL "NOTFOUND")
set(_flags "${CMAKE_${_lang}_FLAGS}")
else()
set(_flags "${_flags} ${CMAKE_${_lang}_FLAGS}")
endif()
# message(STATUS "Set (${file} ${_flags}")
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS
"${_flags}")
endif()
endforeach()
unset(_file_ext)
unset(_lang)
endmacro(set_source_files_compile_flags)
# A helper function to compile *.lua source into *.lua.c sources
function(lua_source varname filename)
set (srcfile "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
set (tmpfile "${CMAKE_CURRENT_BINARY_DIR}/${filename}.new.c")
set (dstfile "${CMAKE_CURRENT_BINARY_DIR}/${filename}.c")
get_filename_component(module ${filename} NAME_WE)
ADD_CUSTOM_COMMAND(OUTPUT ${dstfile}
COMMAND ${ECHO} 'const char ${module}_lua[] =' > ${tmpfile}
COMMAND ${CMAKE_BINARY_DIR}/extra/txt2c ${srcfile} >> ${tmpfile}
COMMAND ${ECHO} '\;' >> ${tmpfile}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmpfile} ${dstfile}
COMMAND ${CMAKE_COMMAND} -E remove ${tmpfile}
DEPENDS ${srcfile} txt2c)
set(var ${${varname}})
set(${varname} ${var} ${dstfile} PARENT_SCOPE)
endfunction()
|