diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Coverage.cmake | 34 | ||||
-rw-r--r-- | cmake/UseConstantBuilder.cmake | 19 | ||||
-rw-r--r-- | cmake/UseGSettings.cmake | 42 | ||||
-rw-r--r-- | cmake/UseGdbusCodegen.cmake | 35 | ||||
-rw-r--r-- | cmake/UseGlibGeneration.cmake | 71 |
5 files changed, 201 insertions, 0 deletions
diff --git a/cmake/Coverage.cmake b/cmake/Coverage.cmake new file mode 100644 index 0000000..160dac2 --- /dev/null +++ b/cmake/Coverage.cmake @@ -0,0 +1,34 @@ +if (CMAKE_BUILD_TYPE MATCHES coverage) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage") + + find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin") + if (NOT GCOVR_EXECUTABLE) + message(STATUS "Gcovr binary was not found, can not generate XML coverage info.") + else () + message(STATUS "Gcovr found, can generate XML coverage info.") + add_custom_target (coverage-xml + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" --exclude="obj.*" -x -r "${CMAKE_SOURCE_DIR}" + --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml) + endif() + + find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin") + find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT}) + if (NOT LCOV_EXECUTABLE) + message(STATUS "Lcov binary was not found, can not generate HTML coverage info.") + else () + if(NOT GENHTML_EXECUTABLE) + message(STATUS "Genthml binary not found, can not generate HTML coverage info.") + else() + message(STATUS "Lcov and genhtml found, can generate HTML coverage info.") + add_custom_target (coverage-html + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum + COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info + ) + endif() + endif() +endif() diff --git a/cmake/UseConstantBuilder.cmake b/cmake/UseConstantBuilder.cmake new file mode 100644 index 0000000..06c8d05 --- /dev/null +++ b/cmake/UseConstantBuilder.cmake @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.6) +if(POLICY CMP0011) + cmake_policy(SET CMP0011 NEW) +endif(POLICY CMP0011) + +macro(add_constant_template outfiles name const_name input) + set(file_target "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") + add_custom_command( + OUTPUT ${file_target} + COMMAND ${CMAKE_COMMAND} + "-Dname=${name}" + "-Dfile_target=${file_target}" + "-Dconst_name=${const_name}" + "-Dinput=${input}" + -P "${CMAKE_SOURCE_DIR}/cmake/ConstantBuilderTemplates.cmake" + DEPENDS "${CMAKE_SOURCE_DIR}/cmake/ConstantBuilderTemplates.cmake" "${input}" + ) + list(APPEND ${outfiles} "${file_target}") +endmacro(add_constant_template) diff --git a/cmake/UseGSettings.cmake b/cmake/UseGSettings.cmake new file mode 100644 index 0000000..92eb681 --- /dev/null +++ b/cmake/UseGSettings.cmake @@ -0,0 +1,42 @@ +# GSettings.cmake, CMake macros written for Marlin, feel free to re-use them. + +option (GSETTINGS_LOCALINSTALL "Install GSettings Schemas locally instead of to the GLib prefix" ${LOCAL_INSTALL}) + +option (GSETTINGS_COMPILE "Compile GSettings Schemas after installation" ${GSETTINGS_LOCALINSTALL}) + +if(GSETTINGS_LOCALINSTALL) + message(STATUS "GSettings schemas will be installed locally.") +endif() + +if(GSETTINGS_COMPILE) + message(STATUS "GSettings shemas will be compiled.") +endif() + +macro(add_schema SCHEMA_NAME) + + set(PKG_CONFIG_EXECUTABLE pkg-config) + # Have an option to not install the schema into where GLib is + if (GSETTINGS_LOCALINSTALL) + SET (GSETTINGS_DIR "${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas/") + else (GSETTINGS_LOCALINSTALL) + execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} glib-2.0 --variable prefix OUTPUT_VARIABLE _glib_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) + SET (GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/") + endif (GSETTINGS_LOCALINSTALL) + + # Run the validator and error if it fails + execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE _glib_comple_schemas OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process (COMMAND ${_glib_comple_schemas} --dry-run --schema-file=${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME} ERROR_VARIABLE _schemas_invalid OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (_schemas_invalid) + message (SEND_ERROR "Schema validation error: ${_schemas_invalid}") + endif (_schemas_invalid) + + # Actually install and recomple schemas + message (STATUS "GSettings schemas will be installed into ${GSETTINGS_DIR}") + install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME} DESTINATION ${GSETTINGS_DIR} OPTIONAL) + + if (GSETTINGS_COMPILE) + install (CODE "message (STATUS \"Compiling GSettings schemas\")") + install (CODE "execute_process (COMMAND ${_glib_comple_schemas} ${GSETTINGS_DIR})") + endif () +endmacro() diff --git a/cmake/UseGdbusCodegen.cmake b/cmake/UseGdbusCodegen.cmake new file mode 100644 index 0000000..aa23ca3 --- /dev/null +++ b/cmake/UseGdbusCodegen.cmake @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 2.6) +if(POLICY CMP0011) + cmake_policy(SET CMP0011 NEW) +endif(POLICY CMP0011) + +find_program(GDBUS_CODEGEN NAMES gdbus-codegen DOC "gdbus-codegen executable") +if(NOT GDBUS_CODEGEN) + message(FATAL_ERROR "Excutable gdbus-codegen not found") +endif() + +function(add_gdbus_codegen) + set(_one_value OUTFILES NAME PREFIX NAMESPACE SERVICE_XML) + set(_multi_value DEPENDS) + cmake_parse_arguments (arg "" "${_one_value}" "${_multi_value}" ${ARGN}) + + if(arg_PREFIX) + set(PREFIX --interface-prefix ${arg_PREFIX}) + endif() + + if(arg_NAMESPACE) + set(NAMESPACE --c-namespace ${arg_NAMESPACE}) + endif() + + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.h" "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.c" + COMMAND "${GDBUS_CODEGEN}" + --generate-c-code "${arg_NAME}" + ${PREFIX} + ${NAMESPACE} + "${arg_SERVICE_XML}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${arg_DEPENDS} "${arg_SERVICE_XML}" + ) + set(${arg_OUTFILES} ${${arg_OUTFILES}} "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.c" PARENT_SCOPE) +endfunction(add_gdbus_codegen) diff --git a/cmake/UseGlibGeneration.cmake b/cmake/UseGlibGeneration.cmake new file mode 100644 index 0000000..67e34b9 --- /dev/null +++ b/cmake/UseGlibGeneration.cmake @@ -0,0 +1,71 @@ +cmake_minimum_required(VERSION 2.6) +if(POLICY CMP0011) + cmake_policy(SET CMP0011 NEW) +endif(POLICY CMP0011) + +find_program(GLIB_MKENUMS glib-mkenums) +find_program(GLIB_GENMARSHAL glib-genmarshal) + +macro(add_glib_marshal outfiles name prefix otherinclude) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" + COMMAND ${GLIB_GENMARSHAL} --header "--prefix=${prefix}" + "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" + > "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" + ) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + COMMAND echo "\\#include \\\"${otherinclude}\\\"" > "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + COMMAND echo "\\#include \\\"glib-object.h\\\"" >> "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + COMMAND echo "\\#include \\\"${name}.h\\\"" >> "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + COMMAND ${GLIB_GENMARSHAL} --body "--prefix=${prefix}" + "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" + >> "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" + "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" + ) + list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") +endmacro(add_glib_marshal) + +macro(add_glib_enumtypes_t outfiles name htemplate ctemplate) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" + COMMAND ${GLIB_MKENUMS} + --template "${htemplate}" + ${ARGN} > "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${ARGN} "${htemplate}" + ) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + COMMAND ${GLIB_MKENUMS} + --template "${ctemplate}" + ${ARGN} > "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${ARGN} ${ctemplate} + "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" + ) + list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") +endmacro(add_glib_enumtypes_t) + +macro(add_glib_enumtypes outfiles name namespace includeguard) + set(htemplate "${CMAKE_CURRENT_BINARY_DIR}/${name}.h.template") + set(ctemplate "${CMAKE_CURRENT_BINARY_DIR}/${name}.c.template") + + # Write the .h template + add_custom_command( + OUTPUT ${htemplate} ${ctemplate} + COMMAND ${CMAKE_COMMAND} + "-Dctemplate=${ctemplate}" + "-Dhtemplate=${htemplate}" + "-Dname=${name}" + "-Dnamespace=${namespace}" + "-Dincludeguard=${includeguard}" + "\"-Dheaders=${ARGN}\"" + -P "${CMAKE_SOURCE_DIR}/cmake/GlibGenerationTemplates.cmake" + DEPENDS "${CMAKE_SOURCE_DIR}/cmake/GlibGenerationTemplates.cmake" ${headers} + ) + + add_glib_enumtypes_t(${outfiles} ${name} ${htemplate} ${ctemplate} ${ARGN}) +endmacro(add_glib_enumtypes) |