# For target_compile_features cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) 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(platform_folders sago/platform_folders.cpp ) # 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(platform_folders PROPERTIES PUBLIC_HEADER "sago/platform_folders.h" ) # cxx_std_11 requires v3.8 if(CMAKE_VERSION VERSION_LESS "3.8.0") # Use old method of forcing C++11 set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED true) else() # Require (minimum) C++11 when using header # PRIVATE means only at compile time target_compile_features(platform_folders PUBLIC cxx_std_11) endif() # cxx_nullptr exists in v3.1 target_compile_features(platform_folders PRIVATE cxx_nullptr) # Apple requires linking to CoreServices # Check sys name instead of "APPLE" for cross-compilation if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # Find the framework # ref: https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemFrameworks/SystemFrameworks.html find_library(_CoreServices_FRAMEWORK NAMES "CoreServices.framework" "CoreServices" PATH_SUFFIXES "CoreServices" PATHS "/System/Library/Frameworks" ) # Make sure it was found if(NOT _CoreServices_FRAMEWORK) message(FATAL_ERROR "Could not find the CoreServices framework!") 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(platform_folders PRIVATE "${_CoreServices_FRAMEWORK}") endif() if(CMAKE_SYSTEM_NAME STREQUAL "Windows") # You can pass these when calling Cmake, so don't override if the user does if(NOT _WIN32_WINNT AND NOT WINVER) target_compile_definitions(platform_folders PRIVATE _WIN32_WINNT=0x0601 WINVER=0x0601 ) endif() endif() # 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 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 "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 platform_folders FILE "platform_folders-exports.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}" ) # 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}/platform_foldersConfigVersion.cmake" # This'll require versioning in the project() call VERSION ${CMAKE_PROJECT_VERSION} # Just assuming Semver is followed COMPATIBILITY SameMajorVersion ) # Install the ConfigVersion file, which is located in the build dir install(FILES "${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfigVersion.cmake" DESTINATION "${_PROJECT_INSTALL_CMAKE_DIR}" ) # A module for testing the library include(CTest) # BUILD_TESTING is defined (default ON) in CTest if(BUILD_TESTING) add_subdirectory(test) add_executable(platform_folders_sample platform_folders.cpp) target_link_libraries(platform_folders_sample PRIVATE platform_folders) endif()