Skip to content

Commit 53cc43a

Browse files
committed
#1: refactor sample project options
1 parent 675b415 commit 53cc43a

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
2-
project(foo VERSION 0.0.1)
2+
3+
file(READ "VERSION" _foo_version_str)
4+
string(STRIP "${_vt_version_str}" _foo_version_str)
5+
project(foo VERSION ${_foo_version_str})
6+
7+
# To generate output file with compilation errors and warnings
8+
# CMake generator needs to be known
9+
set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE)
10+
11+
# Prevent mixing install policies from add_subdirectory;
12+
# This suppresses a warning as the old behavior is deprecated-by-definition.
13+
cmake_policy(SET CMP0082 NEW)
314

415
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 2.24:
516
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
@@ -36,9 +47,7 @@ if(NOT CMAKE_CXX_STANDARD)
3647
endif()
3748
message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
3849

39-
option(FOO_WERROR_ENABLED "Build foo with warnings as errors" OFF)
40-
option(FOO_TESTS_ENABLED "Build foo with unit tests" ON)
41-
option(FOO_COVERAGE_ENABLED "Build foo with coverage" OFF)
50+
4251

4352
if(APPLE AND NOT CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
4453
add_compile_options(-ffat-lto-objects)
@@ -54,6 +63,8 @@ set(PROJECT_EXAMPLE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/examples)
5463
set(PROJECT_APP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/apps)
5564
set(PROJECT_BINDINGS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bindings)
5665

66+
include(cmake/configure_options.cmake)
67+
5768
add_subdirectory(src)
5869

5970
message(STATUS "FOO_COVERAGE_ENABLED: ${FOO_COVERAGE_ENABLED}")

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

cmake/configure_options.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
option(FOO_WERROR_ENABLED "Build foo with warnings as errors" OFF)
2+
option(FOO_TESTS_ENABLED "Build foo with unit tests" ON)
3+
option(FOO_COVERAGE_ENABLED "Build foo with coverage" OFF)

0 commit comments

Comments
 (0)