Skip to content

Commit f00df66

Browse files
committed
Disable warnings when built as subdirectory
Fixes #165.
1 parent 3fb7c24 commit f00df66

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,31 @@
55
cmake_minimum_required(VERSION 3.11)
66
project(cppast VERSION 0.1.0)
77

8+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
9+
set(is_top_level_project TRUE)
10+
else()
11+
set(is_top_level_project FALSE)
12+
endif()
13+
814
# options
915
option(CPPAST_BUILD_TEST "whether or not to build the tests" OFF)
1016
option(CPPAST_BUILD_EXAMPLE "whether or not to build the examples" OFF)
1117
option(CPPAST_BUILD_TOOL "whether or not to build the tool" OFF)
1218

13-
if(${CPPAST_BUILD_TEST} OR (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
19+
if(${CPPAST_BUILD_TEST} OR ${is_top_level_project})
1420
set(build_test ON)
1521
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for the self integration test
1622
else()
1723
set(build_test OFF)
1824
endif()
1925

20-
if(${CPPAST_BUILD_EXAMPLE} OR (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
26+
if(${CPPAST_BUILD_EXAMPLE} OR ${is_top_level_project})
2127
set(build_example ON)
2228
else()
2329
set(build_example OFF)
2430
endif()
2531

26-
if(${CPPAST_BUILD_TOOL} OR (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
32+
if(${CPPAST_BUILD_TOOL} OR ${is_top_level_project})
2733
set(build_tool ON)
2834
else()
2935
set(build_tool OFF)

src/CMakeLists.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,18 @@ target_compile_definitions(cppast PUBLIC
113113
CPPAST_VERSION_MINOR="${cppast_VERSION_MINOR}"
114114
CPPAST_VERSION_MAJOR="${cppast_VERSION_MAJOR}"
115115
CPPAST_VERSION_STRING="${cppast_VERSION}")
116-
target_compile_options(cppast PRIVATE
117-
# clang/GCC warnings
118-
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
119-
-pedantic-errors -Werror -Wall -Wextra -Wconversion -Wsign-conversion>
120-
# disable noexcept type warning on GCC
121-
$<$<CXX_COMPILER_ID:GNU>: -Wno-noexcept-type>
122-
# MSVC warnings
123-
$<$<CXX_COMPILER_ID:MSVC>:
124-
/W3>)
116+
117+
if(${is_top_level_project})
118+
target_compile_options(cppast PRIVATE
119+
# clang/GCC warnings
120+
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
121+
-pedantic-errors -Werror -Wall -Wextra -Wconversion -Wsign-conversion>
122+
# disable noexcept type warning on GCC
123+
$<$<CXX_COMPILER_ID:GNU>: -Wno-noexcept-type>
124+
# MSVC warnings
125+
$<$<CXX_COMPILER_ID:MSVC>:
126+
/W3>)
127+
endif()
125128

126129
install(TARGETS cppast)
127130
install(DIRECTORY ../include/ DESTINATION include)

0 commit comments

Comments
 (0)