--- FLIF-0.3/src/CMakeLists.txt.orig	2017-04-28 11:46:54.000000000 -0400
+++ FLIF-0.3/src/CMakeLists.txt	2018-02-26 05:37:44.705656000 -0500
@@ -66,7 +66,7 @@ endif()
 if(CMAKE_COMPILER_IS_GNUCXX)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
     set(CMAKE_CXX_FLAGS_DEBUG "-ggdb3")
-    set(CMAKE_CXX_FLAGS_RELEASE "-O3")
+    set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ftree-vectorize")
 endif()
 
 if(USE_ASAN)
@@ -89,36 +89,78 @@ endif()
 add_executable(flif_exe ${COMMON_SOURCES} ${WINDOWS_EXE_SOURCE} ${FLIF_SRC_DIR}/flif-enc.cpp ${FLIF_SRC_DIR}/flif.cpp)
 target_link_libraries(flif_exe ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
 set_target_properties(flif_exe PROPERTIES OUTPUT_NAME flif)
+add_executable(dflif_exe ${COMMON_SOURCES} ${WINDOWS_EXE_SOURCE} ${FLIF_SRC_DIR}/flif-enc.cpp ${FLIF_SRC_DIR}/flif.cpp)
+target_compile_definitions(dflif_exe PRIVATE -DDECODER_ONLY)
+target_link_libraries(dflif_exe ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
+set_target_properties(dflif_exe PROPERTIES OUTPUT_NAME dflif)
 
 if(WIN32)
     target_include_directories(flif_exe PRIVATE ${FLIF_SRC_DIR}/../build/MSVC/getopt)
     target_compile_definitions(flif_exe PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} STATIC_GETOPT ) # prevents dllexporting symbols for getopt
+    target_include_directories(dflif_exe PRIVATE ${FLIF_SRC_DIR}/../build/MSVC/getopt)
+    target_compile_definitions(dflif_exe PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} STATIC_GETOPT ) # prevents dllexporting symbols for getopt
 endif()
 
 # library
+if(BUILD_SHARED_LIBS)
+    add_library(flif_lib SHARED ${COMMON_SOURCES} ${FLIF_SRC_DIR}/flif-enc.cpp ${FLIF_SRC_DIR}/library/flif-interface.cpp)
+    add_library(flif_lib_dec SHARED ${COMMON_SOURCES} ${FLIF_SRC_DIR}/library/flif-interface_dec.cpp)
 
-add_library(flif_lib SHARED ${COMMON_SOURCES} ${FLIF_SRC_DIR}/flif-enc.cpp ${FLIF_SRC_DIR}/library/flif-interface.cpp)
-add_library(flif_lib_dec SHARED ${COMMON_SOURCES} ${FLIF_SRC_DIR}/library/flif-interface_dec.cpp)
+    target_link_libraries(flif_lib ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
+    target_link_libraries(flif_lib_dec ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
 
-target_link_libraries(flif_lib ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
-target_link_libraries(flif_lib_dec ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
+    set_target_properties(flif_lib PROPERTIES OUTPUT_NAME flif)
+    set_target_properties(flif_lib_dec PROPERTIES OUTPUT_NAME flif_dec)
 
-set_target_properties(flif_lib PROPERTIES OUTPUT_NAME flif)
-set_target_properties(flif_lib_dec PROPERTIES OUTPUT_NAME flif_dec)
+    target_compile_definitions(flif_lib PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} FLIF_BUILD_DLL )
+    target_compile_definitions(flif_lib_dec PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} FLIF_BUILD_DLL DECODER_ONLY )
 
-target_compile_definitions(flif_lib PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} FLIF_BUILD_DLL )
-target_compile_definitions(flif_lib_dec PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} FLIF_BUILD_DLL DECODER_ONLY )
+    target_include_directories(flif_lib PRIVATE ${FLIF_SRC_DIR}/../extern)
+    target_include_directories(flif_lib_dec PRIVATE ${FLIF_SRC_DIR}/../extern)
+
+    target_link_libraries(flif_exe flif_lib)
+    target_link_libraries(dflif_exe flif_lib_dec)
+endif(BUILD_SHARED_LIBS)
 
 target_include_directories(flif_exe PRIVATE ${FLIF_SRC_DIR}/../extern)
-target_include_directories(flif_lib PRIVATE ${FLIF_SRC_DIR}/../extern)
-target_include_directories(flif_lib_dec PRIVATE ${FLIF_SRC_DIR}/../extern)
+target_include_directories(dflif_exe PRIVATE ${FLIF_SRC_DIR}/../extern)
+
+if(BUILD_STATIC_LIBS)
+    add_library(flif_lib_static STATIC ${COMMON_SOURCES} ${FLIF_SRC_DIR}/flif-enc.cpp ${FLIF_SRC_DIR}/library/flif-interface.cpp)
+    add_library(flif_lib_dec_static STATIC ${COMMON_SOURCES} ${FLIF_SRC_DIR}/library/flif-interface_dec.cpp)
+
+    target_link_libraries(flif_lib_static ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
+    target_link_libraries(flif_lib_dec_static ${PNG_LIBRARY} ${STATIC_LINKED_LIBS})
+
+    set_target_properties(flif_lib_static PROPERTIES OUTPUT_NAME flif)
+    set_target_properties(flif_lib_dec_static PROPERTIES OUTPUT_NAME flif_dec)
+
+    target_compile_definitions(flif_lib_static PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} FLIF_BUILD_DLL )
+    target_compile_definitions(flif_lib_dec_static PRIVATE ${DEFINITIONS_FOR_ALL_TARGETS} FLIF_BUILD_DLL DECODER_ONLY )
+
+    target_include_directories(flif_lib_static PRIVATE ${FLIF_SRC_DIR}/../extern)
+    target_include_directories(flif_lib_dec_static PRIVATE ${FLIF_SRC_DIR}/../extern)
+
+    if (NOT(BUILD_SHARED_LIBS))
+       target_link_libraries(flif_exe flif_lib_static)
+       target_link_libraries(dflif_exe flif_lib_dec_static)
+    endif(NOT(BUILD_SHARED_LIBS))
+endif(BUILD_STATIC_LIBS)
 
 # viewflif
 
 if(${SDL2_FOUND})
-    add_executable(viewflif ${FLIF_SRC_DIR}/viewflif.c)
+    if(WIN32)
+      add_executable(viewflif WIN32 ${FLIF_SRC_DIR}/viewflif.c)
+    else(WIN32)
+      add_executable(viewflif ${FLIF_SRC_DIR}/viewflif.c)
+    endif(WIN32)
     set_source_files_properties(${FLIF_SRC_DIR}/viewflif.c PROPERTIES LANGUAGE CXX)
-    target_link_libraries(viewflif flif_lib_dec ${SDL2_LIBRARY} ${SDL2MAIN_LIBRARY})
+    if ("${PKG_SDL2_STATIC_LIBRARIES}" STREQUAL "")
+      target_link_libraries(viewflif flif_lib_dec ${SDL2_LIBRARY} ${SDL2MAIN_LIBRARY})
+    else("${PKG_SDL2_STATIC_LIBRARIES}" STREQUAL "")
+      target_link_libraries(viewflif flif_lib_dec ${PKG_SDL2_STATIC_LIBRARIES})
+    endif("${PKG_SDL2_STATIC_LIBRARIES}" STREQUAL "")
     target_include_directories(viewflif PRIVATE ${FLIF_SRC_DIR}/library ${SDL2_INCLUDE_DIR})
     target_compile_definitions(viewflif PRIVATE FLIF_USE_DLL)
 endif()
