From 0281dee877dfbcebcfd31959bf2463c6bba9ae61 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 7 Mar 2013 11:17:17 -0600 Subject: [PATCH] [libpng16] Fixed CMakelists.txt to allow building a single variant of the library (Claudio Bley): Introduced a PNG_LIB_TARGETS variable that lists all activated library targets. It is an error if this variable ends up empty, ie. you have to build at least one library variant. Made the *_COPY targets only depend on library targets actually being build. Use PNG_LIB_TARGETS to unify a code path. Changed the CREATE_SYMLINK macro to expact the full path to a file as the first argument. When symlinking the filename component of that path is determined and used as the link target. Use copy_if_different in the CREATE_SYMLINK macro. --- ANNOUNCE | 11 +++++++++++ CHANGES | 11 +++++++++++ CMakeLists.txt | 46 +++++++++++++++++++++++++--------------------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index a7a025331..6a5f5c172 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -94,6 +94,17 @@ Version 1.6.1beta07 [March 7, 2013] Fixed bugs in the pngpixel and makepng test programs. Version 1.6.1beta08 [March 7, 2013] + Fixed CMakelists.txt to allow building a single variant of the library + (Claudio Bley): + Introduced a PNG_LIB_TARGETS variable that lists all activated library + targets. It is an error if this variable ends up empty, ie. you have + to build at least one library variant. + Made the *_COPY targets only depend on library targets actually being build. + Use PNG_LIB_TARGETS to unify a code path. + Changed the CREATE_SYMLINK macro to expact the full path to a file as the + first argument. When symlinking the filename component of that path is + determined and used as the link target. + Use copy_if_different in the CREATE_SYMLINK macro. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index d6786dd1c..b6f982dca 100644 --- a/CHANGES +++ b/CHANGES @@ -4450,6 +4450,17 @@ Version 1.6.1beta07 [March 7, 2013] Fixed bugs in the pngpixel and makepng test programs. Version 1.6.1beta08 [March 7, 2013] + Fixed CMakelists.txt to allow building a single variant of the library + (Claudio Bley): + Introduced a PNG_LIB_TARGETS variable that lists all activated library + targets. It is an error if this variable ends up empty, ie. you have + to build at least one library variant. + Made the *_COPY targets only depend on library targets actually being build. + Use PNG_LIB_TARGETS to unify a code path. + Changed the CREATE_SYMLINK macro to expact the full path to a file as the + first argument. When symlinking the filename component of that path is + determined and used as the link target. + Use copy_if_different in the CREATE_SYMLINK macro. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CMakeLists.txt b/CMakeLists.txt index 728067d02..b5ae626cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,8 +139,11 @@ endif() # NOW BUILD OUR TARGET include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR}) +unset(PNG_LIB_TARGETS) + if(PNG_SHARED) add_library(${PNG_LIB_NAME} SHARED ${libpng_sources}) + set(PNG_LIB_TARGETS ${PNG_LIB_NAME}) if(MSVC) # msvc does not append 'lib' - do it here to have consistent name set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib") @@ -153,6 +156,7 @@ if(PNG_STATIC) # does not work without changing name set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static) add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources}) + list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_STATIC}) if(MSVC) # msvc does not append 'lib' - do it here to have consistent name set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib") @@ -160,6 +164,12 @@ if(PNG_STATIC) target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY}) endif() +if(NOT PNG_LIB_TARGETS) + message(SEND_ERROR + "No library variant selected to build. " + "Please enable at least one of the following options: PNG_STATIC, PNG_SHARED") +endif() + if(PNG_SHARED AND WIN32) set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL) endif() @@ -222,14 +232,15 @@ macro(CREATE_SYMLINK SRC_FILE DEST_FILE) if(WIN32 AND NOT CYGWIN AND NOT MSYS) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE} - DEPENDS ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC} + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE} + DEPENDS ${PNG_LIB_TARGETS} ) ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}) else(WIN32 AND NOT CYGWIN AND NOT MSYS) - execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + get_filename_component(LINK_TARGET "${SRC_FILE}" NAME) + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif(WIN32 AND NOT CYGWIN AND NOT MSYS) endmacro() @@ -287,40 +298,33 @@ endif() # INSTALL if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) - if(PNG_SHARED) - install(TARGETS ${PNG_LIB_NAME} - ${PNG_EXPORT_RULE} - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(TARGETS ${PNG_LIB_TARGETS} + ${PNG_EXPORT_RULE} + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(PNG_SHARED) # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin if(CYGWIN OR MINGW) get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE}) - get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME) - CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}) + CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif(CYGWIN OR MINGW) if(NOT WIN32) get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE}) - get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME) - CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_SHARED_LIBRARY_SUFFIX}) + CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif(NOT WIN32) endif(PNG_SHARED) if(PNG_STATIC) - install(TARGETS ${PNG_LIB_NAME_STATIC} - ${PNG_EXPORT_RULE} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(NOT WIN32 OR CYGWIN OR MINGW) get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE}) - get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME) - CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_STATIC_LIBRARY_SUFFIX}) + CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif(NOT WIN32 OR CYGWIN OR MINGW)