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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
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)
if (IS_ABSOLUTE "${filename}")
set (srcfile "${filename}")
set (tmpfile "${filename}.new.c")
set (dstfile "${filename}.c")
else(IS_ABSOLUTE "${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")
endif(IS_ABSOLUTE "${filename}")
get_filename_component(module ${filename} NAME_WE)
get_filename_component(_name ${dstfile} NAME)
string(REGEX REPLACE "${_name}$" "" dstdir ${dstfile})
if (IS_DIRECTORY ${dstdir})
else()
file(MAKE_DIRECTORY ${dstdir})
endif()
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 libluajit)
set(var ${${varname}})
set(${varname} ${var} ${dstfile} PARENT_SCOPE)
endfunction()
function(bin_source varname srcfile dstfile)
set(var ${${varname}})
set(${varname} ${var} ${dstfile} PARENT_SCOPE)
set (srcfile "${CMAKE_CURRENT_SOURCE_DIR}/${srcfile}")
set (dstfile "${CMAKE_CURRENT_SOURCE_DIR}/${dstfile}")
set (tmpfile "${dstfile}.tmp")
get_filename_component(module ${dstfile} NAME_WE)
ADD_CUSTOM_COMMAND(OUTPUT ${dstfile}
COMMAND ${ECHO} 'const unsigned char ${module}_bin[] = {' > ${tmpfile}
COMMAND ${CMAKE_BINARY_DIR}/extra/bin2c "${srcfile}" >> ${tmpfile}
COMMAND ${ECHO} '}\;' >> ${tmpfile}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmpfile} ${dstfile}
COMMAND ${CMAKE_COMMAND} -E remove ${tmpfile}
DEPENDS ${srcfile} bin2c)
endfunction()
|