Code · 1 file

Sample CMake File

A CMakeLists.txt that builds a library, an executable and tests. Every language sample implements the same small program so you can compare them side by side.

CMake · 692 B

Sample CMake file

An idiomatic CMake example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.

CC0 · free for any use · Verified by an independent tool · Report a problem

CMakeLists.txt — first linesCMake
# Sample CMakeLists.txt — samplefiles.com
cmake_minimum_required(VERSION 3.20)
project(Sample VERSION 1.0.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(SAMPLE_BUILD_TESTS "Build unit tests" ON)

add_library(customers src/customers.cpp)
target_include_directories(customers PUBLIC include)

add_executable(sample src/main.cpp)
target_link_libraries(sample PRIVATE customers)

if(SAMPLE_BUILD_TESTS)
  enable_testing()
  add_executable(customers_test tests/customers_test.cpp)
  target_link_libraries(customers_test PRIVATE customers)
  add_test(NAME customers_test COMMAND customers_test)
endif()

install(TARGETS sample RUNTIME DESTINATION bin)

File details

Size
692 B (692 bytes)
MIME type
text/plain
SHA-256
85bc020d0027b273c43d23d004c64b545ff5bd07824081fd1bfcfe5d95348a2d
MD5
c98f7f2a94cfac55cc6cf714007fc202

Download from the command line

curl -L -o CMakeLists.txt https://files.samplefiles.com/code/cmake/CMakeLists.txt

Or check the download in your browser with the checksum calculator.