2 # Generate .out from .c with awk (generic), based upon the automake logic.
4 # Copyright (C) 2016 Glenn Randers-Pehrson
5 # Written by Roger Leigh, 2016
7 # This code is released under the libpng license.
8 # For conditions of distribution and use, see the disclaimer
11 # Variables substituted from CMakeLists.txt
12 set(SRCDIR "@CMAKE_CURRENT_SOURCE_DIR@")
13 set(BINDIR "@CMAKE_CURRENT_BINARY_DIR@")
16 set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@")
17 set(CMAKE_C_FLAGS @CMAKE_C_FLAGS@)
18 set(INCDIR "@CMAKE_CURRENT_BINARY_DIR@")
19 set(PNG_PREFIX "@PNG_PREFIX@")
20 set(PNGLIB_MAJOR "@PNGLIB_MAJOR@")
21 set(PNGLIB_MINOR "@PNGLIB_MINOR@")
22 set(PNGLIB_VERSION "@PNGLIB_VERSION@")
23 set(ZLIBINCDIR "@ZLIB_INCLUDE_DIR@")
27 set(CMAKE_OSX_ARCHITECTURES "@CMAKE_OSX_ARCHITECTURES@")
28 set(CMAKE_OSX_SYSROOT "@CMAKE_OSX_SYSROOT@")
29 if(CMAKE_OSX_ARCHITECTURES)
30 set(PLATFORM_C_FLAGS ${PLATFORM_C_FLAGS} -arch ${CMAKE_OSX_ARCHITECTURES})
33 set(PLATFORM_C_FLAGS ${PLATFORM_C_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT})
37 get_filename_component(INPUTEXT "${INPUT}" EXT)
38 get_filename_component(OUTPUTEXT "${OUTPUT}" EXT)
39 get_filename_component(INPUTBASE "${INPUT}" NAME_WE)
40 get_filename_component(OUTPUTBASE "${OUTPUT}" NAME_WE)
41 get_filename_component(INPUTDIR "${INPUT}" PATH)
42 get_filename_component(OUTPUTDIR "${OUTPUT}" PATH)
44 if ("${INPUTEXT}" STREQUAL ".c" AND "${OUTPUTEXT}" STREQUAL ".out")
45 get_filename_component(GENDIR "${OUTPUT}" PATH)
46 file(MAKE_DIRECTORY "${GENDIR}")
48 file(REMOVE "${OUTPUT}.tf1" "${OUTPUT}.tf2")
50 set(INCLUDES "-I${INCDIR}")
52 foreach(dir ${ZLIBINCDIR})
53 list(APPEND INCLUDES "-I${dir}")
58 set(PNG_PREFIX_DEF "-DPNG_PREFIX=${PNG_PREFIX}")
61 execute_process(COMMAND "${CMAKE_C_COMPILER}" "-E"
67 "-DPNGLIB_LIBNAME=PNG${PNGLIB_MAJOR}${PNGLIB_MINOR}_0"
68 "-DPNGLIB_VERSION=${PNGLIB_VERSION}"
69 "-DSYMBOL_PREFIX=${SYMBOL_PREFIX}"
70 "-DPNG_NO_USE_READ_MACROS"
71 "-DPNG_BUILDING_SYMBOL_TABLE"
74 OUTPUT_FILE "${OUTPUT}.tf1"
75 WORKING_DIRECTORY "${BINDIR}"
76 RESULT_VARIABLE CPP_FAIL)
78 message(FATAL_ERROR "Failed to generate ${OUTPUT}.tf1")
81 execute_process(COMMAND "${AWK}" -f "${SRCDIR}/scripts/dfn.awk"
82 "out=${OUTPUT}.tf2" "${OUTPUT}.tf1"
83 WORKING_DIRECTORY "${BINDIR}"
84 RESULT_VARIABLE AWK_FAIL)
86 message(FATAL_ERROR "Failed to generate ${OUTPUT}.tf2")
89 file(REMOVE "${OUTPUT}.tf1")
90 file(RENAME "${OUTPUT}.tf2" "${OUTPUT}")
92 message(FATAL_ERROR "Unsupported conversion: ${INPUTEXT} to ${OUTPUTEXT}")