Skip to content

Commit 4bb9c57

Browse files
committed
Fix library installation
1 parent 7a6f6e0 commit 4bb9c57

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
2-
project(modern_cpp_project LANGUAGES CXX)
2+
project(modern_cpp_project LANGUAGES CXX VERSION 0.1.0)
33

44
# Enable C++20 with strict enforcement
55
set(CMAKE_CXX_STANDARD 20)
@@ -28,7 +28,7 @@ include(Sanitizers)
2828
# === Libraries ===
2929
add_subdirectory(src)
3030

31-
# === Application target ===
31+
# === Application ===
3232
add_executable(${PROJECT_NAME}
3333
src/main.cpp
3434
)
@@ -52,7 +52,7 @@ include(GNUInstallDirs)
5252
include(CMakePackageConfigHelpers)
5353

5454
install(TARGETS math
55-
EXPORT mathTargets
55+
EXPORT ${PROJECT_NAME}Targets
5656
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
5757
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
5858
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
@@ -61,20 +61,20 @@ install(TARGETS math
6161

6262
install(
6363
DIRECTORY ${CMAKE_SOURCE_DIR}/include/
64-
DESTINATION include
64+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
6565
)
6666

6767
# Export the targets to a file
68-
install(EXPORT mathTargets
69-
FILE mathTargets.cmake
68+
install(
69+
EXPORT ${PROJECT_NAME}Targets
7070
NAMESPACE ${PROJECT_NAME}::
7171
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
7272
)
7373

7474
# Configure a version file
7575
write_basic_package_version_file(
7676
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
77-
VERSION 1.0.0
77+
VERSION ${PROJECT_VERSION}
7878
COMPATIBILITY SameMajorVersion
7979
)
8080

cmake/Config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@PACKAGE_INIT@
22

3-
include("${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake")
3+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ add_library(math STATIC
22
arithmetic.cpp
33
)
44

5+
add_library(${PROJECT_NAME}::math ALIAS math)
6+
57
target_include_directories(math
68
PUBLIC
79
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>

0 commit comments

Comments
 (0)