From e82e51fd94fb6290df6d2aba4e3777662ed9403d Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 24 Apr 2021 13:59:47 +0200 Subject: [PATCH 1/5] cmake: use GNUInstallDirs --- CMakeLists.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7173c9..d60b219 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") project(aptdec) +include(GNUInstallDirs) + # libpng find_package(PNG) @@ -18,7 +20,7 @@ add_library(aptstatic STATIC ${LIB_C_SOURCE_FILES}) # Create shared library for 3rd party apps add_library(apt SHARED ${LIB_C_SOURCE_FILES}) -add_compile_definitions(PALETTE_DIR="../palettes") +add_compile_definitions(PALETTE_DIR="${CMAKE_INSTALL_PREFIX}/palettes") if (PNG_FOUND AND LIBSNDFILE_FOUND) add_executable(aptdec ${EXE_C_SOURCE_FILES}) @@ -76,24 +78,24 @@ IF(NOT WIN32) set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}") if (TARGET aptdec) - install(TARGETS aptdec DESTINATION "bin/") + install(TARGETS aptdec) install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes/" DESTINATION "palettes/") endif() - install(TARGETS apt LIBRARY DESTINATION lib) - install(FILES ${LIB_C_HEADER_FILES} DESTINATION include/apt ) + install(TARGETS apt) + install(FILES ${LIB_C_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) else() #set(CPACK_GENERATOR "ZIP;NSIS") set(CPACK_GENERATOR "ZIP") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") if (TARGET aptdec) - install(TARGETS aptdec DESTINATION "bin/") + install(TARGETS aptdec) file(GLOB_RECURSE DLLS *.dll) - install(FILES ${DLLS} DESTINATION "bin/") + install(FILES ${DLLS} DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - install(TARGETS apt DESTINATION "bin/") - install(FILES ${LIB_C_HEADER_FILES} DESTINATION include/apt ) + install(TARGETS apt) + install(FILES ${LIB_C_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes/" DESTINATION "palettes/") endif() From 63efb4344490e200b5622ac8cf4a2ee465bde80b Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 24 Apr 2021 14:04:04 +0200 Subject: [PATCH 2/5] cmake: deduplicate install directives --- CMakeLists.txt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d60b219..9a64dd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,27 +76,23 @@ set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) IF(NOT WIN32) set(CPACK_GENERATOR "DEB;TGZ") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}") - - if (TARGET aptdec) - install(TARGETS aptdec) - install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes/" DESTINATION "palettes/") - endif() - - install(TARGETS apt) - install(FILES ${LIB_C_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) else() #set(CPACK_GENERATOR "ZIP;NSIS") set(CPACK_GENERATOR "ZIP") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") if (TARGET aptdec) - install(TARGETS aptdec) file(GLOB_RECURSE DLLS *.dll) install(FILES ${DLLS} DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - install(TARGETS apt) - install(FILES ${LIB_C_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) +endif() + +if (TARGET aptdec) + install(TARGETS aptdec) install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes/" DESTINATION "palettes/") endif() +install(TARGETS apt) +install(FILES ${LIB_C_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) + include(CPack) From 0a888e6bafde3e382cd4162d56e0647a4c11a23c Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 24 Apr 2021 14:06:40 +0200 Subject: [PATCH 3/5] cmake: install headers as part of shared library --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a64dd4..92a0d06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,10 @@ set(LIB_C_HEADER_FILES src/apt.h) # Link with static library for aptdec executable, so we don't need to set the path add_library(aptstatic STATIC ${LIB_C_SOURCE_FILES}) + # Create shared library for 3rd party apps add_library(apt SHARED ${LIB_C_SOURCE_FILES}) +set_target_properties(apt PROPERTIES PUBLIC_HEADER ${LIB_C_HEADER_FILES}) add_compile_definitions(PALETTE_DIR="${CMAKE_INSTALL_PREFIX}/palettes") @@ -92,7 +94,6 @@ if (TARGET aptdec) install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes/" DESTINATION "palettes/") endif() -install(TARGETS apt) -install(FILES ${LIB_C_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) +install(TARGETS apt PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) include(CPack) From 73488dce962256989db68e83426a21b655309504 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 24 Apr 2021 14:07:56 +0200 Subject: [PATCH 4/5] cmake: install palettes to DATADIR --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92a0d06..07d91b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ add_library(aptstatic STATIC ${LIB_C_SOURCE_FILES}) add_library(apt SHARED ${LIB_C_SOURCE_FILES}) set_target_properties(apt PROPERTIES PUBLIC_HEADER ${LIB_C_HEADER_FILES}) -add_compile_definitions(PALETTE_DIR="${CMAKE_INSTALL_PREFIX}/palettes") +add_compile_definitions(PALETTE_DIR="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/palettes") if (PNG_FOUND AND LIBSNDFILE_FOUND) add_executable(aptdec ${EXE_C_SOURCE_FILES}) @@ -91,7 +91,7 @@ endif() if (TARGET aptdec) install(TARGETS aptdec) - install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes/" DESTINATION "palettes/") + install(DIRECTORY "${PROJECT_SOURCE_DIR}/palettes" DESTINATION ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}) endif() install(TARGETS apt PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt) From 5a257ae0ceaa1ccd97a66f092dc7fce272802390 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 24 Apr 2021 14:31:14 +0200 Subject: [PATCH 5/5] cmake: use message(WARNING) when dependencies are missing --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07d91b5..3b67be4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ if (PNG_FOUND AND LIBSNDFILE_FOUND) endif() endif() else() - MESSAGE(STATUS "WARNING: Only building apt library, as not all of the required libraries were found for aptdec.") + MESSAGE(WARNING "Only building apt library, as not all of the required libraries were found for aptdec.") endif() if (MSVC)