summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorRadek Novacek <rnovacek@redhat.com>2012-07-23 13:47:48 +0200
committerRadek Novacek <rnovacek@redhat.com>2012-07-23 14:35:13 +0200
commit3f906be3f651313c1b8709732ea0bdebba296784 (patch)
treea9878fa3203f46359b9b800abe52ae3d689351ac /cmake
parentf20dc83a0a0c833e9e018d73257cbbc34d7c3756 (diff)
downloadopenlmi-providers-3f906be3f651313c1b8709732ea0bdebba296784.tar.gz
openlmi-providers-3f906be3f651313c1b8709732ea0bdebba296784.tar.xz
openlmi-providers-3f906be3f651313c1b8709732ea0bdebba296784.zip
Introduce konkretcmpi_generate cmake macro
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/CuraMacros.cmake75
1 files changed, 75 insertions, 0 deletions
diff --git a/cmake/modules/CuraMacros.cmake b/cmake/modules/CuraMacros.cmake
new file mode 100644
index 0000000..cf38db9
--- /dev/null
+++ b/cmake/modules/CuraMacros.cmake
@@ -0,0 +1,75 @@
+
+# This macro takes name of the MOF for one provider and header files using
+# konkretcmpi. It also generates provider skeleton if it doesn't exist.
+#
+# @param[in] MOF name of the MOF file (should be in mof/ directory of the project root)
+# @param[out] CIM_PROVIDERS list of sources of the provider generated from the MOF
+# @param[out] CIM_HEADERS list of header file generated from the MOF
+#
+macro(konkretcmpi_generate MOF CIM_PROVIDERS CIM_HEADERS)
+ # Check if MOF exists
+ find_file(MOF_FILE
+ ${MOF}
+ PATHS ${CMAKE_SOURCE_DIR}/mof/
+ )
+ if (MOF_FILE STREQUAL "MOF_FILE-NOTFOUND")
+ message(FATAL_ERROR "MOF file ${MOF} not found")
+ endif (MOF_FILE STREQUAL "MOF_FILE-NOTFOUND")
+
+ # Read CIM classes out of MOF file
+ execute_process(COMMAND sed -e "/class/ !D" -e "s/class \\(.*\\):.*/\\1/g"
+ INPUT_FILE ${MOF_FILE}
+ OUTPUT_VARIABLE CIM_CLASSES
+ )
+
+ if (${CIM_CLASSES} STREQUAL "")
+ message(FATAL_ERROR "No class found in the MOF file ${MOF_FILE}")
+ endif (${CIM_CLASSES} STREQUAL "")
+
+ # And fill list with them
+ string(REGEX MATCHALL "[a-zA-Z_-]+" CIM_CLASSES ${CIM_CLASSES})
+
+ # Get headers and sources names from the list of CIM classes
+ set(${CIM_HEADERS} "")
+ set(${CIM_PROVIDERS} "")
+ set(GENERATE_PROVIDERS "")
+ set(NEW_PROVIDERS "")
+ foreach(CLASS ${CIM_CLASSES})
+ # Add generated header to the list
+ set(${CIM_HEADERS} ${CIM_HEADERS} ${CLASS}.h)
+ # Get name of the source file
+ set(PROVIDER ${CLASS}Provider.c)
+ # If the provider doesn't exist, generate it
+ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROVIDER})
+ # Part of generating command - passed to konkret
+ set(GENERATE_PROVIDERS ${GENERATE_PROVIDERS} -s ${CLASS})
+ # List of freshly generated providers
+ set(NEW_PROVIDERS ${NEW_PROVIDERS} ${PROVIDER})
+ endif (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROVIDER})
+ # Add provider source to the list
+ set(${CIM_PROVIDERS} ${CIM_PROVIDERS} ${PROVIDER})
+ endforeach(CLASS ${CIM_CLASSES})
+
+ # Generate headers for CIM classes
+ set(ENV{KONKRET_SCHEMA_DIR} "/usr/share/mof/cim-current")
+ execute_process(COMMAND ${KONKRETCMPI_KONKRET}
+ #-m /usr/share/sblim-cmpi-base/Linux_Base.mof
+ -m ${MOF_FILE}
+ ${GENERATE_PROVIDERS}
+ ${CIM_CLASSES}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ RESULT_VARIABLE RES
+ OUTPUT_VARIABLE OUT
+ ERROR_VARIABLE ERR
+ )
+
+ # Show error message when konkret fails
+ if (NOT ${RES} EQUAL 0)
+ message(FATAL_ERROR "KonkretCMPI failed: ${RES} ${ERR}")
+ endif (NOT ${RES} EQUAL 0)
+
+ # Move pregenerated sources for providers to source directory
+ foreach(PROVIDER ${NEW_PROVIDERS})
+ file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/${PROVIDER} ${CMAKE_CURRENT_SOURCE_DIR}/${PROVIDER})
+ endforeach(PROVIDER ${NEW_PROVIDERS})
+endmacro(konkretcmpi_generate MOF PROVIDERS HEADERS)