diff --git a/CMakeLists.txt b/CMakeLists.txt index 6353f66..28f0843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,26 +5,31 @@ project(platform_folders VERSION 3.2.0 LANGUAGES CXX) # Since it's off, the library will be static by default option(BUILD_SHARED_LIBS "Build shared instead of static." OFF) -add_library(${PROJECT_NAME} +add_library(platform_folders sago/platform_folders.cpp ) -# Where to search for the header -# The BUILD/INSTALL interface expressions are for exporting -target_include_directories(${PROJECT_NAME} PRIVATE +# Defines standardized defaults for install paths +include(GNUInstallDirs) +# Where to search for the header while building +target_include_directories(platform_folders PUBLIC $ - $ + # Controls where #include starts to look from + # So /usr/include/ + # or C:\Program Files\platform_folders\include\ + $ ) # Define the header as public for installation -set_target_properties(${PROJECT_NAME} PROPERTIES +set_target_properties(platform_folders PROPERTIES PUBLIC_HEADER "sago/platform_folders.h" ) -# Minimum C++11 for "nullptr" and other stuff -target_compile_features(${PROJECT_NAME} PRIVATE - cxx_std_11 - cxx_nullptr +# Require (minimum) C++11 when using header +# PRIVATE means only at compile time +target_compile_features(platform_folders + PUBLIC cxx_std_11 + PRIVATE cxx_nullptr ) # Apple requires linking to CoreServices @@ -43,55 +48,56 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") endif() # Link to the CoreServices framework. This also sets the correct linking options # "If the library file is in a Mac OSX framework, the Headers directory of the framework will also be processed as a usage requirement." - target_link_libraries(${PROJECT_NAME} PRIVATE "${_CoreServices_FRAMEWORK}") + target_link_libraries(platform_folders PRIVATE "${_CoreServices_FRAMEWORK}") endif() -# Defines standardized defaults for install paths -include(GNUInstallDirs) -# For the config and configversion macros -include(CMakePackageConfigHelpers) - -# Controls what dir to prefix for the lib, so -set(_PROJECT_INSTALL_PREFIX_DIR "sago") -# Controls where the exports, config, and configversion files install to -set(_PROJECT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${_PROJECT_INSTALL_PREFIX_DIR}") +# Cmake's find_package search path is different based on the system +# See https://cmake.org/cmake/help/latest/command/find_package.html for the list +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + # Controls where the exports, config, and configversion files install to + set(_PROJECT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_PREFIX}/cmake") +else() + # When calling find_package() + # it looks for /usr/lib/cmake//Config.cmake + set(_PROJECT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/platform_folders") +endif() # Gives "Make install" esque operations a location to install to... # and creates a .cmake file to be exported -install(TARGETS ${PROJECT_NAME} - EXPORT "${PROJECT_NAME}-targets" - LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/${_PROJECT_INSTALL_PREFIX_DIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/${_PROJECT_INSTALL_PREFIX_DIR}" - # Tells it where to put your headers if any set by set_target_properties - PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${_PROJECT_INSTALL_PREFIX_DIR}" - # Tells export where your includes folder is | Note that the private include path is not needed here - INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${_PROJECT_INSTALL_PREFIX_DIR}" +install(TARGETS platform_folders + EXPORT "platform_folders-targets" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + # Tells it where to put the header files + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sago" ) # "The install(TARGETS) and install(EXPORT) commands work together to install a target and a file to help import it" # Installs a cmake file which external projects can import. -install(EXPORT "${PROJECT_NAME}-targets" +install(EXPORT "platform_folders-targets" + NAMESPACE sago:: DESTINATION "${_PROJECT_INSTALL_CMAKE_DIR}" ) # "The export command is used to generate a file exporting targets from a project build tree" # Creates an import file for external projects which are aware of the build tree. # May be useful for cross-compiling -export(TARGETS ${PROJECT_NAME} - FILE "${PROJECT_NAME}-exports.cmake" +export(TARGETS platform_folders + FILE "platform_folders-exports.cmake" ) -configure_package_config_file("${PROJECT_NAME}Config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" +# For the config and configversion macros +include(CMakePackageConfigHelpers) + +configure_package_config_file("platform_foldersConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfig.cmake" # Tells the config file where it will be installed, so it can be correctly imported INSTALL_DESTINATION "${_PROJECT_INSTALL_CMAKE_DIR}" - # This passes the variables to the cmake.in file, which uses them - PATH_VARS PROJECT_NAME ) # Creates the project's ConfigVersion.cmake file # This allows for find_package() to use a version in the call -write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" +write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfigVersion.cmake" # This'll require versioning in the project() call VERSION ${CMAKE_PROJECT_VERSION} # Just assuming Semver is followed @@ -100,8 +106,8 @@ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Con # Install the ConfigVersion file, which is located in the build dir install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfigVersion.cmake" DESTINATION "${_PROJECT_INSTALL_CMAKE_DIR}" ) diff --git a/README.md b/README.md index 696da84..05479d9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PlatformFolders [![Build Status](https://travis-ci.org/sago007/PlatformFolders.svg?branch=master)](https://travis-ci.org/sago007/PlatformFolders) [![AppVeyor](https://img.shields.io/appveyor/ci/sago007/PlatformFolders.svg?label=Windows)](https://ci.appveyor.com/project/sago007/platformfolders) [![license](https://img.shields.io/github/license/sago007/PlatformFolders.svg)](https://raw.githubusercontent.com/sago007/PlatformFolders/master/LICENSE) [![Join the chat at https://gitter.im/PlatformFolders/Lobby](https://badges.gitter.im/PlatformFolders/Lobby.svg)](https://gitter.im/PlatformFolders/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/729e36adcf5c4523bd136de1b33441cb)](https://www.codacy.com/app/github_43/PlatformFolders?utm_source=github.com&utm_medium=referral&utm_content=sago007/PlatformFolders&utm_campaign=Badge_Grade) +# PlatformFolders [![Build Status](https://travis-ci.org/sago007/PlatformFolders.svg?branch=master)](https://travis-ci.org/sago007/PlatformFolders) [![AppVeyor](https://img.shields.io/appveyor/ci/sago007/PlatformFolders.svg?label=Windows)](https://ci.appveyor.com/project/sago007/platformfolders) [![license](https://img.shields.io/github/license/sago007/PlatformFolders.svg)](https://raw.githubusercontent.com/sago007/PlatformFolders/master/LICENSE) [![Join the chat at https://gitter.im/PlatformFolders/Lobby](https://badges.gitter.im/PlatformFolders/Lobby.svg)](https://gitter.im/PlatformFolders/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/729e36adcf5c4523bd136de1b33441cb)](https://www.codacy.com/app/github_43/PlatformFolders?utm_source=github.com&utm_medium=referral&utm_content=sago007/PlatformFolders&utm_campaign=Badge_Grade) A C++ library to look for directories like `My Documents`, `~/.config`, `%APPDATA%`, etc. so that you do not need to write platform-specific code diff --git a/platform_foldersConfig.cmake.in b/platform_foldersConfig.cmake.in index 6bd5004..f4a7964 100644 --- a/platform_foldersConfig.cmake.in +++ b/platform_foldersConfig.cmake.in @@ -1,3 +1,3 @@ @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/platform_folders-targets.cmake")