Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding CMakeLists.txt #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.3.2)

project(LodePNG)

include(GenerateExportHeader)
find_package(SDL)
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
file(GLOB_RECURSE SOURCES *.cpp)

set(LIBRARIES lodepng lodepng_util)
foreach(LIBRARY ${LIBRARIES})
add_library(${LIBRARY} ${LIBRARY}.cpp)
if (NOT LIBRARY STREQUAL "lodepng")
target_link_libraries(${LIBRARY} lodepng)
else ()
generate_export_header(${LIBRARY})
endif ()
install(TARGETS ${LIBRARY}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endforeach()

string(LENGTH ${CMAKE_SOURCE_DIR} LENGTH_CMAKE_SOURCE_DIR)
set(SDL_DEPENDENT example_opengl example_sdl lodepng_benchmark)
set(UTIL_DEPENDENT lodepng_unittest pngdetail)
enable_testing()

foreach(SOURCE ${SOURCES})
string(SUBSTRING ${SOURCE} ${LENGTH_CMAKE_SOURCE_DIR} -1 EXECUTABLE_NAME)
string(REPLACE ".cpp" "" EXECUTABLE_NAME ${EXECUTABLE_NAME})
string(REPLACE "/examples/" "" EXECUTABLE_NAME ${EXECUTABLE_NAME})
string(REPLACE "/" "" EXECUTABLE_NAME ${EXECUTABLE_NAME})

if (NOT ${EXECUTABLE_NAME} IN_LIST LIBRARIES)
set(LINK_LIBRARIES lodepng)
if (EXECUTABLE_NAME IN_LIST UTIL_DEPENDENT)
list(APPEND LINK_LIBRARIES lodepng_util)
endif()
if (EXECUTABLE_NAME IN_LIST SDL_DEPENDENT)
if (NOT SDL_FOUND)
continue()
endif()
list(APPEND LINK_LIBRARIES ${SDL_LIBRARY})
list(APPEND INCLUDE_DIRS ${SDL_INCLUDE_DIR})
endif()

add_executable(${EXECUTABLE_NAME} ${SOURCE})
if (INCLUDE_DIRS)
target_include_directories(${EXECUTABLE_NAME} PUBLIC ${INCLUDE_DIRS})
endif()
target_link_libraries(${EXECUTABLE_NAME} ${LINK_LIBRARIES})
add_test(NAME ${EXECUTABLE_NAME} COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}>)
install(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION bin)
endif()
endforeach()

install(FILES ${CMAKE_BINARY_DIR}/lodepng_export.h lodepng.h lodepng_util.h DESTINATION include)

include(InstallRequiredSystemLibraries)
include(CPack)
5 changes: 3 additions & 2 deletions lodepng.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ source files with custom allocators.*/
#ifdef LODEPNG_COMPILE_CPP
#include <vector>
#include <string>
#include <lodepng_export.h>
#endif /*LODEPNG_COMPILE_CPP*/

#ifdef LODEPNG_COMPILE_PNG
Expand Down Expand Up @@ -271,7 +272,7 @@ struct LodePNGDecompressSettings
const void* custom_context; /*optional custom settings for custom functions*/
};

extern const LodePNGDecompressSettings lodepng_default_decompress_settings;
extern LODEPNG_EXPORT const LodePNGDecompressSettings lodepng_default_decompress_settings;
void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings);
#endif /*LODEPNG_COMPILE_DECODER*/

Expand Down Expand Up @@ -305,7 +306,7 @@ struct LodePNGCompressSettings /*deflate = compress*/
const void* custom_context; /*optional custom settings for custom functions*/
};

extern const LodePNGCompressSettings lodepng_default_compress_settings;
extern LODEPNG_EXPORT const LodePNGCompressSettings lodepng_default_compress_settings;
void lodepng_compress_settings_init(LodePNGCompressSettings* settings);
#endif /*LODEPNG_COMPILE_ENCODER*/

Expand Down