# Generate a static library target named "bitmaps"
# (with filename libbitmaps.a on Linux)

# Copy the *.xpm files to ${XPM_CPP_PATH}/*.cpp, on change only.
# Compile those *.cpp files and put them into the library, then done.

# NAKed by Dick:
# builds a set of all the .xpm files
# file(GLOB BITMAP_SRCS *.xpm)  NO, does not build proper dependency
# generation or allow renaming of bitmap files, NAKed by Dick.
# this is twice now I've had to change this.

# Dick: use this one instead:
set(BITMAP_SRCS
    3d.xpm
    Add_Arc.xpm
    Add_Bus2Bus.xpm
    add_bus.xpm
    Add_Circle.xpm
    Add_Component.xpm
    Add_Corner.xpm
    Add_Dashed_Line.xpm
    add_dimension.xpm
    Add_Entry.xpm
    Add_GLabel.xpm
    add_hierarchical_label.xpm
    add_hierar_pin.xpm
    add_hierar_subsheet.xpm
    Add_Junction.xpm
    Add_Line2Bus.xpm
    Add_Line_Label.xpm
    Add_Line.xpm
    Add_Mires.xpm
    Add_Polygon.xpm
    Add_Power.xpm
    Add_Rectangle.xpm
    Add_Text.xpm
    Add_Tracks.xpm
    Add_Zone_Cutout.xpm
    Add_Zone.xpm
    anchor.xpm
    annotate_down_right.xpm
    annotate_right_down.xpm
    annotate.xpm
    Apply.xpm
    auto_associe.xpm
    Auto_track_width.xpm
    axis3d_back.xpm
    axis3d_bottom.xpm
    axis3d_front.xpm
    axis3d_left.xpm
    axis3d_right.xpm
    axis3d_top.xpm
    axis3d.xpm
    backanno.xpm
    book.xpm
    Break_Bus.xpm
    Break_Line.xpm
    Browse_Files.xpm
    cancel_tool.xpm
    Cancel.xpm
    checked_ok.xpm
    component_select_unit.xpm
    component_select_alternate_shape.xpm
    config.xpm
    CopyBlock.xpm
    copy.xpm
    copper_layers_setup.cpp
    Cursor_Shape.xpm
    cursor.xpm
    cut.xpm
    cvpcb.xpm
    dashline.xpm
    Datasheet.xpm
    del_body.xpm
    Delete_Arc.xpm
    delete_association.xpm
    Delete_Bus.xpm
    Delete_Circle.xpm
    Delete_Connection.xpm
    Delete_Cotation.xpm
    Delete_Field.xpm
    Delete_GLabel.xpm
    Delete_Line.xpm
    Delete_Module.xpm
    Delete_Net.xpm
    Delete_Node.xpm
    Delete_Pad.xpm
    Delete_Pinsheet.xpm
    Delete_Pin.xpm
    Delete_Polygon.xpm
    Delete_Rectangle.xpm
    Delete_Segment.xpm
    Delete_Sheet.xpm
    Delete_Text.xpm
    Delete_Track.xpm
    delete.xpm
    del_track.xpm
    directory.xpm
    Display_Options.xpm
    down.xpm
    Drag_Module.xpm
    Drag_Outline_Segment.xpm
    Drag_Pad.xpm
    Drag_Segment_WithSlope.xpm
    Drag_Track_Segment.xpm
    drc_off.xpm
    drc.xpm
    Edges_Sketch.xpm
    Edit_Comp_Footprint.xpm
    Edit_Component.xpm
    Edit_Comp_Ref.xpm
    Edit_Comp_Value.xpm
    Edit_Module.xpm
    Editor.xpm
    Edit_Part.xpm
    Edit_Sheet.xpm
    Edit_Text.xpm
    Edit.xpm
    eeschema.xpm
    Enter_Sheet.xpm
    ercerr.xpm
    ercgreen.xpm
    ercwarn.xpm
    erc.xpm
    Exit.xpm
    Export_Module.xpm
    Export_Options_Pad.xpm
    export.xpm
    fabrication.xpm
    File_FootPrint.xpm
    fill_zone.xpm
    find_xpm.xpm
    Flag.xpm
    Fonts.xpm
    Footprint_Text.xpm
    general_deletions.xpm
    general_ratsnet.xpm
    GLabel2Label.xpm
    GLabel2Text.xpm
    GL_Change.xpm
    Global_Options_Pad.xpm
    green.xpm
    grid_select.xpm
    grid_select_axis.xpm
    grid.xpm
    hammer.xpm
    help.xpm
    Hidden_Pin.xpm
    Hierarchy_cursor.xpm
    Hierarchy_Nav.xpm
    hotkeys.xpm
    icon_3d.xpm
    icon_cvpcb_small.xpm
    icon_cvpcb.xpm
    icon_eeschema.xpm
    icon_gerbview_small.xpm
    icon_gerbview.xpm
    icon_kicad.xpm
    icon_modedit.xpm
    icon_pcbnew.xpm
    icon_txt.xpm
    import3d.xpm
    import_hierarchical_label.xpm
    Import_Module.xpm
    import.xpm
    Info.xpm
    Insert_Module_Board.xpm
    Invert_Module.xpm
    invisible_text.xpm
    jigsaw.xpm
    kicad_icon_small.xpm
    Label2GLabel.xpm
    Label2Text.xpm
    label.xpm
    Lang_Catalan.xpm
    Lang_chinese.xpm
    Lang_Cs.xpm
    Lang_Default.xpm
    Lang_De.xpm
    Lang_En.xpm
    Lang_Es.xpm
    Lang_Fr.xpm
    Lang_Fi.xpm
    Lang_Hu.xpm
    Lang_It.xpm
    Lang_Ko.xpm
    Lang_Nl.xpm
    Lang_Pl.xpm
    Lang_Pt.xpm
    Lang_Ru.xpm
    Lang_Sl.xpm
    Language.xpm
    layers_manager.xpm
    Leave_Sheet.xpm
    left.xpm
    libedit_icon.xpm
    libedit.xpm
    libedprt.xpm
    Lib_next.xpm
    Lib_previous.xpm
    library_browse.xpm
    library_update.xpm
    library.xpm
    libsavem.xpm
    libview.xpm
    Lines90.xpm
    Load_Module_Board.xpm
    Load_Module_Lib.xpm
    local_ratsnet.xpm
    Locked.xpm
    mirepcb.xpm
    Mirror_H.xpm
    Mirror_V.xpm
    modedit.xpm
    Mode_Module.xpm
    Mode_Track.xpm
    modratsnest.xpm
    Module_Check.xpm
    Modul_Edit.xpm
    module_filtered_list.xpm
    module_full_list.xpm
    module_options.xpm
    Module_Ratsnet.xpm
    module.xpm
    Morgan1.xpm
    Morgan2.xpm
    Move_Arc.xpm
    Move_Circle.xpm
    Move_Field.xpm
    Move_GLabel.xpm
    Move_Line.xpm
    Move_Module.xpm
    Move_Pad.xpm
    Move_Pinsheet.xpm
    Move_Pin.xpm
    Move_Polygon.xpm
    Move_Rectangle.xpm
    Move_Sheet.xpm
    Move_Text.xpm
    Move_Track_Segment.xpm
    Move_Track.xpm
    Move.xpm
    mw_Add_Gap.xpm
    mw_Add_Line.xpm
    mw_Add_Shape.xpm
    mw_Add_stub_arc.xpm
    mw_Add_Stub.xpm
    mw_toolbar.xpm
    Net_HighLight.xpm
    netlist.xpm
    Net_Locked.xpm
    Net_UnLocked.xpm
    new_component.xpm
    new_cvpcb.xpm
    New_FootPrint.xpm
    New_Library.xpm
    New_Module.xpm
    new_pcb.xpm
    New_Project.xpm
    new_sch.xpm
    new_txt.xpm
    new.xpm
    noconn.xpm
    Normal.xpm
    online_help.xpm
    Open_Library.xpm
    Open_Project.xpm
    open.xpm
    options_all_tracks_and_vias.xpm
    Options_All_Tracks.xpm
    Options_All_Vias.xpm
    Options_Arc.xpm
    Options_Circle.xpm
    Options_Module.xpm
    Options_New_Pad.xpm
    Options_Pad.xpm
    Options_Pinsheet.xpm
    Options_Pin.xpm
    Options_Rectangle.xpm
    Options_Segment.xpm
    Options_Text.xpm
    Options_Tracks.xpm
    Options_Track.xpm
    Options_Vias.xpm
    opt_show_polygon.xpm
    Orient.xpm
    ortho.xpm
    Pad_Sketch.xpm
    pad.xpm
    pads_mask_layers.xpm
    palette.xpm
    part_properties.xpm
    paste.xpm
    pcbnew.xpm
    PcbOffset.xpm
    pin2pin.xpm
    Pin_Name_to.xpm
    Pin_Number_to.xpm
    Pin_Size_to.xpm
    pinorient_right.xpm
    pinorient_left.xpm
    pinorient_up.xpm
    pinorient_down.xpm
    pinshape_normal.xpm
    pinshape_invert.xpm
    pinshape_clock_normal.xpm
    pinshape_clock_invert.xpm
    pinshape_active_low_input.xpm
    pinshape_clock_active_low.xpm
    pinshape_active_low_output.xpm
    pinshape_clock_fall.xpm
    pinshape_nonlogic.xpm
    pintype_input.xpm
    pintype_output.xpm
    pintype_bidi.xpm
    pintype_3states.xpm
    pintype_passive.xpm
    pintype_notspecif.xpm
    pintype_powerinput.xpm
    pintype_poweroutput.xpm
    pintype_opencoll.xpm
    pintype_openemit.xpm
    pintype_noconnect.xpm
    Pin_to.xpm
    pin.xpm
    plot_HPG.xpm
    plot_PS.xpm
    plot_xpm.xpm
    polar.xpm
    Post_Compo.xpm
    Post_Drill.xpm
    Post_Module.xpm
    preference.xpm
    print.xpm
    ratsnest.xpm
    Read_SetUp.xpm
    redo.xpm
    red.xpm
    reload2.xpm
    reload.xpm
    Resize_Sheet.xpm
    right.xpm
    Rotate_Field.xpm
    Rotate_GLabel.xpm
    Rotate_Module-.xpm
    Rotate_Module+.xpm
    Rotate_Pin.xpm
    Rotate-.xpm
    Rotate+.xpm
    rotate-x.xpm
    rotate+x.xpm
    rotate-y.xpm
    rotate+y.xpm
    rotate-z.xpm
    rotate+z.xpm
    save_as.xpm
    Save_CmpStuff.xpm
    Save_Library.xpm
    Save_NetList.xpm
    Save_Project.xpm
    Save_SetUp.xpm
    save.xpm
    schematic.xpm
    select_grid.xpm
    Select_Layer_Pair.xpm
    Select_W_Layer.xpm
    shape_3d.xpm
    sheetset.xpm
    showdcode.xpm
    showmodedge.xpm
    showtrack.xpm
    Show_Zone.xpm
    Show_Zone_Disable.xpm
    Show_Zone_Outline_Only.xpm
    Swap_Layer.xpm
    Text_Sketch.xpm
    tool_ratsnet.xpm
    tools.xpm
    Track_Locked.xpm
    Track_Sketch.xpm
    Track_UnLocked.xpm
    transistor.xpm
    treensel.xpm
    treesel.xpm
    undelete.xpm
    undo.xpm
    unit_inch.xpm
    unit_mm.xpm
    unknown.xpm
    Unlocked.xpm
    unzip.xpm
    Update_Module_Board.xpm
    up.xpm
    Via_Sketch.xpm
    viewlibs_icon.xpm
    Web_support.xpm
    Width_Net.xpm
    Width_Segment.xpm
    Width_Track_Via.xpm
    Width_Track.xpm
    Width_Vias.xpm
    zip_tool.xpm
    zip.xpm
    Zoom_1.xpm
    zoom_auto.xpm
    Zoom_Center.xpm
    zoom_in.xpm
    zoomoins3d.xpm
    zoom_out.xpm
    zoompage3d.xpm
    Zoom_Page.xpm
    zoomplus3d.xpm
    zoom_redraw.xpm
    zoomrefr3d.xpm
    Zoom_Selected.xpm
    Zoom_Select.xpm
    zoom.xpm
)


# Get the path of the *.xpm files into "PATH"
set(PATH ${CMAKE_CURRENT_SOURCE_DIR})
#message("PATH = ${PATH}")

# The name of the directory to put the copied and renamed *.xpm files into.
# As files are copied they are renamed to *.cpp.
set(XPM_CPP_PATH "${CMAKE_BINARY_DIR}/bitmaps/auto_renamed_to_cpp"
    CACHE PATH "path to store renamed .xpm files for compilation")

foreach(LOOP_VAR ${BITMAP_SRCS})
    get_filename_component(BASENAME ${LOOP_VAR} NAME_WE)
    set(CPP_BITMAP "${XPM_CPP_PATH}/${BASENAME}.cpp")
    add_custom_command(
        OUTPUT ${CPP_BITMAP}
        COMMAND "${CMAKE_COMMAND}" -E copy "${PATH}/${BASENAME}.xpm" "${CPP_BITMAP}"
        DEPENDS ${BASENAME}.xpm)
    list(APPEND CPP_BITMAPS ${CPP_BITMAP})
    set_source_files_properties(${CPP_BITMAP} PROPERTIES COMPILE_FLAGS -DXPMMAIN)
endforeach(LOOP_VAR)

add_library(bitmaps ${CPP_BITMAPS})
