File: AppendSerialization.cmake

package info (click to toggle)
mlpack 4.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,272 kB
  • sloc: cpp: 226,039; python: 1,934; sh: 1,198; lisp: 414; makefile: 85
file content (56 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download | duplicates (3)
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
# AppendSerialization.cmake: append imports for serialization and
# deserialization for mlpack model types to the existing list of serialization
# and deserialization imports.

# This function depends on the following variables being set:
#
#  * PROGRAM_MAIN_FILE: the file containing the mlpackMain() function.
#  * SERIALIZATION_FILE: file to append types to
#  * SERIALIZE: It is of bool type. If SERIALIZE is true we have to print
#               Serialize, else Deserialize.
#
function(append_serialization SERIALIZATION_FILE PROGRAM_MAIN_FILE SERIALIZE)
  include("${CMAKE_SOURCE_DIR}/CMake/StripType.cmake")
  strip_type("${PROGRAM_MAIN_FILE}")

  list(LENGTH MODEL_TYPES NUM_MODEL_TYPES)
  if (${NUM_MODEL_TYPES} GREATER 0)
    math(EXPR LOOP_MAX "${NUM_MODEL_TYPES}-1")
    foreach (INDEX RANGE ${LOOP_MAX})
      list(GET MODEL_TYPES ${INDEX} MODEL_TYPE)
      list(GET MODEL_SAFE_TYPES ${INDEX} MODEL_SAFE_TYPE)
      file(READ "${SERIALIZATION_FILE}" SERIALIZATION_FILE_CONTENTS)
      if (SERIALIZE)
        # See if the model type already exists.
        string(FIND
            "${SERIALIZATION_FILE_CONTENTS}"
            "\"${MODEL_SAFE_TYPE}\" = Serialize${MODEL_SAFE_TYPE}Ptr,"
            FIND_OUT)

        # If it doesn't exist, append it.
        if (${FIND_OUT} EQUAL -1)
          # Now append the type to the list of types, and define any serialization
          # function.
          file(APPEND
              "${SERIALIZATION_FILE}"
              "      \"${MODEL_SAFE_TYPE}\" = Serialize${MODEL_SAFE_TYPE}Ptr,\n")
        endif()
      elseif (NOT SERIALIZE)
        # See if the model type already exists.
        string(FIND
            "${SERIALIZATION_FILE_CONTENTS}"
            "\"${MODEL_SAFE_TYPE}\" = Deserialize${MODEL_SAFE_TYPE}Ptr,"
            FIND_OUT)

        # If it doesn't exist, append it.
        if (${FIND_OUT} EQUAL -1)
          # Now append the type to the list of types, and define any deserialization
          # function.
          file(APPEND
              "${SERIALIZATION_FILE}"
              "      \"${MODEL_SAFE_TYPE}\" = Deserialize${MODEL_SAFE_TYPE}Ptr,\n")
        endif()
      endif()
    endforeach ()
  endif()
endfunction()