-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
64 lines (51 loc) · 1.86 KB
/
CMakeLists.txt
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # enable PIC
set(CMAKE_DEBUG_POSTFIX "-d")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) # ensure CMAKE_BUILD_TYPE is not empty
endif()
# project parameters
set(project_name repl)
set(project_version "0.1.0")
set(project_version_name repl_version) # name of variable in generated header
set(cxx_standard cxx_std_20)
project(${project_name} VERSION "${project_version}")
set(is_root_project OFF) # indicate if this is the top-level project
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(is_root_project ON)
message(STATUS "${PROJECT_NAME} is top level")
endif()
# header text
if(is_root_project)
set(build_config ${CMAKE_BUILD_TYPE})
if(CMAKE_CONFIGURATION_TYPES)
set(build_config "Multi-config")
endif()
message(STATUS "[${CMAKE_SYSTEM_PROCESSOR}] [${CMAKE_SYSTEM_NAME}] [${CMAKE_GENERATOR}] [${CMAKE_CXX_COMPILER_ID}] [${build_config}]")
endif()
# version
function(configure_version)
set(in "${CMAKE_CURRENT_SOURCE_DIR}/src/${project_version_name}.hpp.in")
if(EXISTS "${in}")
set(out "${CMAKE_CURRENT_BINARY_DIR}/${project_version_name}.hpp.in")
message(STATUS "Configuring ${out}")
configure_file("${in}" "${out}")
endif()
endfunction()
configure_version()
# exe
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE
src/main.cpp
)
target_include_directories(${PROJECT_NAME} PRIVATE src "${CMAKE_CURRENT_BINARY_DIR}")
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
get_target_property(sources ${PROJECT_NAME} SOURCES)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${sources})
if(GNU)
target_compile_options(${PROJECT_NAME} INTERFACE -Wall -Wextra -Wpedantic -Werror=return-type)
endif()