@@ -2,10 +2,17 @@ cmake_minimum_required(VERSION 3.14)
2
2
3
3
project (vcpkg C CXX)
4
4
5
- OPTION (BUILD_TESTING "Option for enabling testing" ON )
6
- OPTION (VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF )
7
5
OPTION (DEFINE_DISABLE_METRICS "Option for disabling metrics" OFF )
8
6
OPTION (VCPKG_ALLOW_APPLE_CLANG "Option for allowing apple clang" OFF )
7
+ OPTION (VCPKG_DEVELOPMENT_WARNINGS "Option for turning on all warnings, and making them errors" ON )
8
+ OPTION (BUILD_TESTING "Option for enabling testing" ON )
9
+ OPTION (VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarking" OFF )
10
+
11
+ # for backwards compatibility with existing code
12
+ if (WERROR)
13
+ set (VCPKG_DEVELOPMENT_WARNINGS On )
14
+ endif ()
15
+
9
16
10
17
if (DEFINE_DISABLE_METRICS)
11
18
set (DISABLE_METRICS_VALUE "1" )
@@ -27,41 +34,18 @@ If you would like to try anyway, pass --allowAppleClang to bootstrap.sh.")
27
34
endif ()
28
35
elseif (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" )
29
36
set (CLANG 1)
30
- elseif (MSVC )
31
- add_compile_options (/FC)
32
- else ()
37
+ elseif (NOT MSVC )
33
38
message (FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID} " )
34
39
endif ()
35
40
36
- if (GCC OR (CLANG AND NOT MSVC ))
37
- if (WERROR)
38
- add_compile_options (-Wall -Wno-unknown-pragmas -Werror)
39
- endif ()
40
- endif ()
41
-
42
- if (DEFINE_DISABLE_METRICS)
43
- set (DISABLE_METRICS_VALUE "1" )
44
- else ()
45
- set (DISABLE_METRICS_VALUE "0" )
46
- endif ()
47
-
48
- file (GLOB_RECURSE VCPKGLIB_SOURCES src/vcpkg/*.cpp)
49
-
50
- add_library (vcpkglib OBJECT ${VCPKGLIB_SOURCES} )
51
- add_executable (vcpkg src/vcpkg.cpp $<TARGET_OBJECTS:vcpkglib>)
52
-
53
- target_compile_features (vcpkg PRIVATE cxx_std_17)
54
- target_compile_definitions (vcpkg PRIVATE -DDISABLE_METRICS=${DISABLE_METRICS_VALUE} )
55
- target_include_directories (vcpkg PRIVATE include )
56
-
57
41
set (THREADS_PREFER_PTHREAD_FLAG ON )
58
42
find_package (Threads REQUIRED)
59
43
60
44
add_definitions (-DDISABLE_METRICS=${DISABLE_METRICS_VALUE} )
61
45
include_directories (include )
62
46
link_libraries (Threads::Threads)
63
47
64
- if (CLANG)
48
+ if (CLANG AND NOT MSVC )
65
49
include (CheckCXXSourceCompiles)
66
50
check_cxx_source_compiles("#include <iostream>
67
51
int main() { return __GLIBCXX__; }" USES_LIBSTDCXX)
@@ -73,31 +57,70 @@ if(CLANG)
73
57
endif ()
74
58
75
59
if (GCC OR (CLANG AND USES_LIBSTDCXX))
76
- target_link_libraries (vcpkg PRIVATE stdc++fs)
60
+ link_libraries ( stdc++fs)
77
61
elseif (CLANG AND NOT MSVC )
78
- target_link_libraries (vcpkg PRIVATE c++fs)
62
+ link_libraries ( c++fs)
79
63
endif ()
80
64
81
- if (GCC OR CLANG)
65
+ if (MSVC )
66
+ # either MSVC, or clang-cl
67
+ add_compile_options (-FC)
68
+
69
+ if (MSVC_VERSION GREATER 1900)
70
+ # Visual Studio 2017 or later
71
+ add_compile_options (-std:c++17 -permissive-)
72
+ else ()
73
+ # Visual Studio 2015
74
+ add_compile_options (-std:c++latest)
75
+ endif ()
76
+
77
+ if (VCPKG_DEVELOPMENT_WARNINGS)
78
+ string (REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
79
+ add_compile_options (-W4 -WX)
80
+
81
+ if (CLANG)
82
+ add_compile_options (-Wmissing-prototypes -Wno-missing-field-initializers)
83
+ endif ()
84
+ endif ()
85
+ elseif (GCC OR CLANG)
82
86
add_compile_options (-std=c++1z)
83
- if (WERROR)
84
- add_compile_options (-Wall -Wno-unknown-pragmas -Werror)
87
+
88
+ if (VCPKG_DEVELOPMENT_WARNINGS)
89
+ add_compile_options (-Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wno-missing-field-initializers -Werror)
90
+
91
+ # GCC and clang have different names for the same warning
92
+ if (GCC)
93
+ add_compile_options (-Wmissing-declarations)
94
+ elseif (CLANG)
95
+ add_compile_options (-Wmissing-prototypes)
96
+ endif ()
85
97
endif ()
86
98
endif ()
87
99
100
+ file (GLOB_RECURSE VCPKGLIB_SOURCES CONFIGURE_DEPENDS src/vcpkg/*.cpp)
101
+
102
+ add_library (vcpkglib OBJECT ${VCPKGLIB_SOURCES} )
103
+ add_executable (vcpkg src/vcpkg.cpp $<TARGET_OBJECTS:vcpkglib>)
104
+
88
105
if (BUILD_TESTING)
89
- file (GLOB_RECURSE VCPKGTEST_SOURCES src/vcpkg-test /*.cpp)
106
+ file (GLOB_RECURSE VCPKGTEST_SOURCES CONFIGURE_DEPENDS src/vcpkg-test /*.cpp)
90
107
91
108
enable_testing ()
92
109
add_executable (vcpkg-test
93
110
${VCPKGTEST_SOURCES}
94
111
$<TARGET_OBJECTS:vcpkglib>)
95
112
96
- add_test (NAME default COMMAND vcpkg-test [ ${TEST_NAME} ] )
113
+ add_test (NAME default COMMAND vcpkg-test )
97
114
98
115
if (VCPKG_BUILD_BENCHMARKING)
99
116
target_compile_options (vcpkg-test PRIVATE -DCATCH_CONFIG_ENABLE_BENCHMARKING)
100
117
endif ()
118
+
119
+ find_program (CLANG_FORMAT clang-format)
120
+ if (CLANG_FORMAT)
121
+ file (GLOB_RECURSE VCPKG_FORMAT_SOURCES CONFIGURE_DEPENDS src/*.cpp include /pch.h include /vcpkg/*.h include /vcpkg-test /*.h)
122
+ add_custom_target (format COMMAND ${CLANG_FORMAT} -i -verbose ${VCPKG_FORMAT_SOURCES} )
123
+ endif ()
101
124
endif ()
102
125
103
126
if (MSVC )
0 commit comments