diff --git a/CMakeLists.txt b/CMakeLists.txt index d9abcfb..4befdf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,16 +14,6 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() -include(GNUInstallDirs) -set(CROSSGUID_INC_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") -set(CROSSGUID_RUNTIME_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") -set(CROSSGUID_LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") -set(CROSSGUID_ARCHIVE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") -set(CROSSGUID_FRAMEWORK_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") - -set(CROSSGUID_CMAKE_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/crossguid/cmake") -set(CROSSGUID_ADDITIONAL_FILES_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/crossguid") - add_library(crossguid ${CMAKE_CURRENT_SOURCE_DIR}/src/guid.cpp) target_include_directories(crossguid PUBLIC $ @@ -65,25 +55,38 @@ set_target_properties(crossguid PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -# Install target -install(TARGETS crossguid EXPORT crossguidTargets - RUNTIME DESTINATION ${CROSSGUID_RUNTIME_INSTALL_DIR} - LIBRARY DESTINATION ${CROSSGUID_LIBRARY_INSTALL_DIR} - ARCHIVE DESTINATION ${CROSSGUID_ARCHIVE_INSTALL_DIR} - FRAMEWORK DESTINATION ${CROSSGUID_FRAMEWORK_INSTALL_DIR}) - -# Install headers -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" - DESTINATION ${CROSSGUID_INC_INSTALL_DIR}) - -# Make cmake config files for all targets -install(EXPORT crossguidTargets - DESTINATION ${CROSSGUID_CMAKE_CONFIG_INSTALL_DIR} - FILE crossguid-config.cmake) - -# Install readme and license -install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" "${CMAKE_CURRENT_SOURCE_DIR}/README.md" - DESTINATION ${CROSSGUID_ADDITIONAL_FILES_INSTALL_DIR}) +if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + include(GNUInstallDirs) + + set(CROSSGUID_INC_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") + set(CROSSGUID_RUNTIME_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") + set(CROSSGUID_LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") + set(CROSSGUID_ARCHIVE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") + set(CROSSGUID_FRAMEWORK_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") + + set(CROSSGUID_CMAKE_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/crossguid/cmake") + set(CROSSGUID_ADDITIONAL_FILES_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/crossguid") + + # Install target + install(TARGETS crossguid EXPORT crossguidTargets + RUNTIME DESTINATION ${CROSSGUID_RUNTIME_INSTALL_DIR} + LIBRARY DESTINATION ${CROSSGUID_LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${CROSSGUID_ARCHIVE_INSTALL_DIR} + FRAMEWORK DESTINATION ${CROSSGUID_FRAMEWORK_INSTALL_DIR}) + + # Install headers + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" + DESTINATION ${CROSSGUID_INC_INSTALL_DIR}) + + # Make cmake config files for all targets + install(EXPORT crossguidTargets + DESTINATION ${CROSSGUID_CMAKE_CONFIG_INSTALL_DIR} + FILE crossguid-config.cmake) + + # Install readme and license + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" "${CMAKE_CURRENT_SOURCE_DIR}/README.md" + DESTINATION ${CROSSGUID_ADDITIONAL_FILES_INSTALL_DIR}) +endif() if (CROSSGUID_TESTS) add_executable(crossguid-test test/TestMain.cpp test/Test.cpp)