2018-12-31 20:04:05 +01:00
cmake_minimum_required ( VERSION 3.0.2 FATAL_ERROR )
# Generates files for MIME type <-> extension conversions
# DEPENDS ON: gperf grep bash/powershell
2020-06-24 13:47:36 +02:00
if ( NOT TDUTILS_MIME_TYPE )
return ( )
endif ( )
2018-12-31 20:04:05 +01:00
file ( MAKE_DIRECTORY auto )
set ( TDMIME_SOURCE
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . c p p
)
set ( TDMIME_AUTO
$ { T D M I M E _ S O U R C E }
P A R E N T _ S C O P E
)
add_custom_target ( tdmime_auto DEPENDS ${ TDMIME_SOURCE } )
if ( NOT CMAKE_CROSSCOMPILING )
2018-02-04 12:16:09 +01:00
find_program ( GPERF_EXECUTABLE gperf )
2018-02-11 16:58:18 +01:00
if ( NOT GPERF_EXECUTABLE )
2018-07-08 02:18:46 +02:00
message ( FATAL_ERROR "Could NOT find gperf. Add path to gperf executable to PATH environment variable or specify it manually using GPERF_EXECUTABLE option, i. e. 'cmake -DGPERF_EXECUTABLE:FILEPATH=\" <path to gperf executable>\ "'." )
2018-02-04 12:16:09 +01:00
endif ( )
2018-12-31 20:04:05 +01:00
set ( GPERF_FILES
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . g p e r f
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . g p e r f
)
set ( GPERF_GEN_SOURCE generate_mime_types_gperf.cpp )
add_executable ( generate_mime_types_gperf ${ GPERF_GEN_SOURCE } )
add_custom_command (
O U T P U T $ { G P E R F _ F I L E S }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M A N D g e n e r a t e _ m i m e _ t y p e s _ g p e r f m i m e _ t y p e s . t x t $ { G P E R F _ F I L E S }
D E P E N D S g e n e r a t e _ m i m e _ t y p e s _ g p e r f m i m e _ t y p e s . t x t
)
2020-07-26 14:55:33 +02:00
if ( CMAKE_HOST_WIN32 )
2018-02-04 12:16:09 +01:00
set ( MIME_TYPE_TO_EXTENSION_CMD ${ GPERF_EXECUTABLE } -m100 --output-file=auto/mime_type_to_extension.cpp auto/mime_type_to_extension.gperf )
2018-12-31 20:04:05 +01:00
else ( )
2018-02-04 12:16:09 +01:00
set ( MIME_TYPE_TO_EXTENSION_CMD ${ GPERF_EXECUTABLE } -m100 auto/mime_type_to_extension.gperf | grep -v __gnu_inline__ > auto/mime_type_to_extension.cpp )
2018-12-31 20:04:05 +01:00
endif ( )
add_custom_command (
O U T P U T $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . c p p
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M A N D $ { M I M E _ T Y P E _ T O _ E X T E N S I O N _ C M D }
D E P E N D S a u t o / m i m e _ t y p e _ t o _ e x t e n s i o n . g p e r f
)
2020-07-26 14:55:33 +02:00
if ( CMAKE_HOST_WIN32 )
2018-02-04 12:16:09 +01:00
set ( EXTENSION_TO_MIME_TYPE_CMD ${ GPERF_EXECUTABLE } -m100 --output-file=auto/extension_to_mime_type.cpp auto/extension_to_mime_type.gperf )
2018-12-31 20:04:05 +01:00
else ( )
2018-02-04 12:16:09 +01:00
set ( EXTENSION_TO_MIME_TYPE_CMD ${ GPERF_EXECUTABLE } -m100 auto/extension_to_mime_type.gperf | grep -v __gnu_inline__ > auto/extension_to_mime_type.cpp )
2018-12-31 20:04:05 +01:00
endif ( )
add_custom_command (
O U T P U T $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . c p p
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M A N D $ { E X T E N S I O N _ T O _ M I M E _ T Y P E _ C M D }
D E P E N D S a u t o / e x t e n s i o n _ t o _ m i m e _ t y p e . g p e r f
)
endif ( )