Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
104 lines (84 loc) · 3.88 KB
/
Copy pathCMakeLists.txt
File metadata and controls
104 lines (84 loc) · 3.88 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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Function for grouping files. Used for filters in Visual Studio.
function(createSourceGroups files rootPath)
foreach(_source IN ITEMS ${files} )
get_filename_component(_source_path "${_source}" PATH)
file(RELATIVE_PATH _source_path_rel "${rootPath}" "${_source_path}")
string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
endfunction(createSourceGroups)
project (mini-yaml)
cmake_minimum_required(VERSION 2.8)
# Options.
option(CODE_COVERAGE "Enables coverage reporting" OFF)
# Require C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Threads)
# Force warnings as errors
if(MSVC)
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic -fno-elide-constructors")
endif()
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Find files
set(mini_yaml_dir "${CMAKE_SOURCE_DIR}/yaml")
set(mini_yaml_test_dir "${CMAKE_SOURCE_DIR}/test")
set(mini_yaml_examples_dir "${CMAKE_SOURCE_DIR}/examples")
file(GLOB_RECURSE mini_yaml_inc "${mini_yaml_dir}/*.h" "${mini_yaml_dir}/*.hpp")
file(GLOB_RECURSE mini_yaml_src "${mini_yaml_dir}/*.c" "${mini_yaml_dir}/*.cpp")
set(mini_yaml_files "${mini_yaml_inc}" "${mini_yaml_src}")
file(GLOB_RECURSE test_files "${mini_yaml_test_dir}/*.cpp" "${mini_yaml_test_dir}/*.hpp")
file(GLOB_RECURSE first_example_src "${mini_yaml_examples_dir}/first_example.cpp")
# ==============================================================================================================
#
# First example
#
# ==============================================================================================================
include_directories ("${mini_yaml_dir}")
link_directories("${CMAKE_SOURCE_DIR}/lib")
add_executable(first_example ${first_example_src} ${mini_yaml_files})
set_target_properties( first_example
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/bin"
)
# ==============================================================================================================
#
# Test
#
# ==============================================================================================================
SET(gtest_force_shared_crt on CACHE BOOL
"Use shared (DLL) run-time lib even when Google Test is built as static lib.")
add_subdirectory(${CMAKE_SOURCE_DIR}/vendor/googletest/googletest
${CMAKE_SOURCE_DIR}/vendor/googletest/googletest
EXCLUDE_FROM_ALL) # Add googletest directly to our build.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
include_directories ("${mini_yaml_dir}")
add_executable(mini_yaml_test ${test_files} ${mini_yaml_files})
set_target_properties( mini_yaml_test
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/bin"
)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") ## Code coverage
set_target_properties(mini_yaml_test PROPERTIES COMPILE_FLAGS "--coverage")
target_link_libraries(mini_yaml_test "gcov")
endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_link_libraries(mini_yaml_test gtest_main)