-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
37 lines (32 loc) · 1.26 KB
/
CMakeLists.txt
File metadata and controls
37 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Lesson 16: Make vs CMake — the CMake version
#
# Compare this with the Makefile in the same directory.
# CMake handles automatically:
# - Compiler detection (g++, clang++, MSVC)
# - Header dependency tracking
# - Out-of-source builds (always)
# - Platform differences (library extensions, flags)
# - Parallel builds
# - Test registration
#
# What took ~70 lines in the Makefile is ~25 lines here.
# The tradeoff: CMake is a build system generator (it
# produces Makefiles/Ninja files), adding a layer of
# indirection. Understanding Make first makes CMake's
# output and behavior much less mysterious.
cmake_minimum_required(VERSION 3.20)
project(matrix_demo LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Static library — replaces: ar rcs, LIB_SRCS, pattern rules
add_library(matrix STATIC src/matrix.cpp)
target_include_directories(matrix PUBLIC include)
# Executable — replaces: APP_TARGET, linking, RPATH
add_executable(app src/main.cpp)
target_link_libraries(app PRIVATE matrix)
# Tests — replaces: TEST_TARGET, test phony target
enable_testing()
add_executable(test_matrix tests/test_matrix.cpp)
target_link_libraries(test_matrix PRIVATE matrix)
add_test(NAME matrix_tests COMMAND test_matrix)