aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/PaludisGeneratorUtils.cmake
blob: 147f0c6edb2d86bbac55c6240e8c3f9e9bf1dee8 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
include(CMakeParseArguments)

find_program(M4_EXECUTABLE NAMES m4 gm4 DOC "m4 macro processor")
if(NOT M4_EXECUTABLE)
  message(FATAL_ERROR "m4 not found")
endif()

function(paludis_m4process input_file target)
  set(options)
  set(single_value_args OUTPUT)
  set(multiple_value_args)

  cmake_parse_arguments(PM4P "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})

  get_filename_component(input_file_basename "${input_file}" NAME)
  if(PM4P_OUTPUT)
    set(output_file "${PM4P_OUTPUT}")
  else()
    set(output_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename}")
    string(REGEX REPLACE "\\.[^.]*$" "" output_file "${output_file}")
  endif()

  string(MD5 md5 "paludis-m4process-${output_file}")
  set(target_name paludis-m4process-${md5}-${input_file_basename})

  add_custom_command(OUTPUT
                       ${output_file}
                     COMMAND
                       ${M4_EXECUTABLE} -I ${PROJECT_SOURCE_DIR} -E ${input_file} > ${output_file}
                     DEPENDS
                       ${input_file})
  add_custom_target(${target_name} DEPENDS ${output_file} COMMENT ${output_file})

  set(${target} ${target_name} PARENT_SCOPE)
endfunction()

# TODO(compnerd) convert misc/make_se.bash into a cmake script
function(paludis_seprocess input_file)
  set(single_value_args HEADER_FILE HEADER_TARGET SOURCE_FILE SOURCE_TARGET)
  set(multiple_value_args)

  cmake_parse_arguments(PSEP "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})

  if(NOT PSEP_HEADER_TARGET)
    message(SEND_ERROR "paludis_seprocess(${input_file}) invoked without HEADER_TARGET option")
  endif()
  if(NOT PSEP_SOURCE_TARGET)
    message(SEND_ERROR "paludis_seprocess(${input_file}) invoked without SOURCE_TARGET option")
  endif()

  get_filename_component(input_file_basename "${input_file}" NAME)
  get_filename_component(input_file_basename_we "${input_file}" NAME_WE)

  set(output_header_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-se.hh")
  string(MD5 md5 "paludis-seprocess-${output_header_file}")
  set(header_target_name paludis-seprocess-${md5}-${input_file_basename_we}-se.hh)
  set(${PSEP_HEADER_TARGET} ${header_target_name} PARENT_SCOPE)

  add_custom_command(OUTPUT
                       ${output_header_file}
                     COMMAND
                       "${PROJECT_SOURCE_DIR}/misc/make_se.bash" --header ${input_file} > ${output_header_file}
                     DEPENDS
                       "${PROJECT_SOURCE_DIR}/misc/make_se.bash"
                       ${input_file})
  add_custom_target(${header_target_name} DEPENDS ${output_header_file} COMMENT ${output_header_file})


  set(output_source_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-se.cc")
  string(MD5 md5 "paludis-seprocess-${output_source_file}")
  set(source_target_name paludis-seprocess-${md5}-${input_file_basename_we}-se.cc)
  set(${PSEP_SOURCE_TARGET} ${source_target_name} PARENT_SCOPE)

  add_custom_command(OUTPUT
                       ${output_source_file}
                     COMMAND
                       "${PROJECT_SOURCE_DIR}/misc/make_se.bash" --source ${input_file} > ${output_source_file}
                     DEPENDS
                       "${PROJECT_SOURCE_DIR}/misc/make_se.bash"
                       ${input_file})
  add_custom_target(${source_target_name} DEPENDS ${output_source_file} COMMENT ${output_source_file})

  if(PSEP_HEADER_FILE)
    set(${PSEP_HEADER_FILE} ${output_header_file} PARENT_SCOPE)
  endif()

  if(PSEP_SOURCE_FILE)
    set(${PSEP_SOURCE_FILE} ${output_source_file} PARENT_SCOPE)
  endif()
endfunction()

# TODO(compnerd) convert make_nn.bash into a cmake script
function(paludis_nnprocess input_file)
  set(options)
  set(single_value_args HEADER_TARGET HEADER_FILE SOURCE_TARGET SOURCE_FILE)
  set(multiple_value_args)

  cmake_parse_arguments(PNNP "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})

  if(NOT PNNP_HEADER_TARGET)
    message(SEND_ERROR "paludis_nnprocess(${input_file}) invoked without HEADER_TARGET option")
  endif()
  if(NOT PNNP_SOURCE_TARGET)
    message(SEND_ERROR "paludis_nnprocess(${input_file}) invoked without SOURCE_TARGET option")
  endif()

  get_filename_component(input_file_basename "${input_file}" NAME)
  get_filename_component(input_file_basename_we "${input_file}" NAME_WE)

  set(output_header_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-nn.hh")
  string(MD5 md5 "paludis-nnprocess-${output_header_file}")
  set(header_target_name paludis-nnprocess-${md5}-${input_file_basename_we}-nn.hh)

  add_custom_command(OUTPUT
                       ${output_header_file}
                     COMMAND
                       "${PROJECT_SOURCE_DIR}/misc/make_nn.bash" --header ${input_file} > ${output_header_file}
                     DEPENDS
                       "${PROJECT_SOURCE_DIR}/misc/make_nn.bash"
                       ${input_file})
  add_custom_target(${header_target_name} DEPENDS ${output_header_file} COMMENT ${output_header_file})


  set(output_source_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-nn.cc")
  string(MD5 md5 "paludis-nnprocess-${output_source_file}")
  set(source_target_name paludis-nnprocess-${md5}-${input_file_basename_we}-nn.cc)

  add_custom_command(OUTPUT
                       ${output_source_file}
                     COMMAND
                       "${PROJECT_SOURCE_DIR}/misc/make_nn.bash" --source ${input_file} > ${output_source_file}
                     DEPENDS
                       "${PROJECT_SOURCE_DIR}/misc/make_nn.bash"
                       ${input_file})
  add_custom_target(${source_target_name} DEPENDS ${output_source_file} COMMENT ${output_source_file})

  set(${PNNP_HEADER_TARGET} ${header_target_name} PARENT_SCOPE)
  if(PNNP_HEADER_FILE)
    set(${PNNP_HEADER_FILE} ${output_header_file} PARENT_SCOPE)
  endif()

  set(${PNNP_SOURCE_TARGET} ${source_target_name} PARENT_SCOPE)
  if(PNNP_SOURCE_FILE)
    set(${PNNP_SOURCE_FILE} ${output_source_file} PARENT_SCOPE)
  endif()
endfunction()