From 70ee8a4150810c242884950ba1ce1a2e71e3cebe Mon Sep 17 00:00:00 2001 From: FARBOS Arnaud Date: Fri, 13 May 2016 16:33:24 +0200 Subject: [PATCH] adding CMakeLists.txt --- CMakeLists.txt | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..b0b80ffa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.3.2) + +project(LodePNG) + +find_package(SDL) +include_directories(.) +file(GLOB_RECURSE SOURCES *.cpp) + +set(LIBRARIES lodepng lodepng_util) +foreach(LIBRARY ${LIBRARIES}) + add_library(${LIBRARY} ${LIBRARY}.cpp) + 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}) + + list(FIND LIBRARIES ${EXECUTABLE_NAME} IS_LIB) + if (IS_LIB EQUAL -1) + 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 $) + install(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION bin) + endif() +endforeach() + +include(InstallRequiredSystemLibraries) +include(CPack)