diff --git a/CMakeLists.txt b/CMakeLists.txt index 6268674..a9217ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,3 +19,31 @@ if(NAMEOF_OPT_BUILD_TESTS) enable_testing() add_subdirectory(test) endif() + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +add_library(${PROJECT_NAME} INTERFACE) +target_include_directories(${PROJECT_NAME} + INTERFACE + $ + $) + +write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + PUBLIC_HEADER DESTINATION include + INCLUDES DESTINATION include) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION lib/cmake/${PROJECT_NAME}) + +install(EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION lib/cmake/${PROJECT_NAME}) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include + DESTINATION include) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index ed9727e..c1829cd 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,7 +1,5 @@ include(CheckCXXCompilerFlag) -include_directories(${CMAKE_SOURCE_DIR}/include) - set(OPTIONS "") if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) @@ -19,5 +17,6 @@ endif() add_executable(example example.cpp - ${CMAKE_SOURCE_DIR}/include/nameof.hpp) + ${CMAKE_SOURCE_DIR}/include/${CMAKE_PROJECT_NAME}.hpp) target_compile_options(example PRIVATE ${OPTIONS}) +target_link_libraries(example PRIVATE ${CMAKE_PROJECT_NAME}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 51840d9..abc92ec 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,5 @@ include(CheckCXXCompilerFlag) -include_directories(3rdparty/Catch2) -include_directories(${CMAKE_SOURCE_DIR}/include) - set(SOURCES test.cpp) set(OPTIONS "") @@ -28,6 +25,8 @@ endif() function(make_target target std) add_executable(${target} ${SOURCES}) target_compile_options(${target} PRIVATE ${OPTIONS}) + target_include_directories(${target} PRIVATE 3rdparty/Catch2) + target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME}) if(std) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(${target} PRIVATE /std:${std})