Skip to content

Commit c1479e5

Browse files
committed
Clean up CMakeLists a little
1 parent d9c1b13 commit c1479e5

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ bld/
3131
[Oo]bj/
3232
[Ll]og/
3333
[Ll]ogs/
34+
build/
35+
build-system-gtest/
3436

3537
# Visual Studio 2015/2017 cache/options directory
3638
.vs/

CMakeLists.txt

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,14 @@ project(
77
LANGUAGES CXX
88
)
99

10-
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
11-
set(IS_TOPLEVEL_PROJECT TRUE)
12-
else()
13-
set(IS_TOPLEVEL_PROJECT FALSE)
14-
endif()
15-
1610
option(SIMPLEINI_USE_SYSTEM_GTEST "Use system GoogleTest dependency" OFF)
1711

18-
# Disable in-source builds:
19-
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
20-
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
21-
22-
if("${srcdir}" STREQUAL "${bindir}")
23-
message("")
24-
message("ERROR:: in-source builds are disabled!")
25-
message("Run cmake in a separate build directory:")
26-
message("$ cmake -S . -B build")
27-
message("")
28-
message(FATAL_ERROR "Aborting...")
12+
# disable in-source builds
13+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
14+
message(FATAL_ERROR "In-source builds are not allowed, use cmake -S . -B build.")
2915
endif()
3016

17+
3118
# Define library paths and include directories
3219
set(EXPORT_NAMESPACE "${PROJECT_NAME}::")
3320
set(HEADERS SimpleIni.h)
@@ -70,7 +57,8 @@ target_include_directories(${PROJECT_NAME} INTERFACE
7057
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
7158
)
7259

73-
if(IS_TOPLEVEL_PROJECT)
60+
# only build tests when top level and testing enabled
61+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
7462
include(CTest)
7563
if(BUILD_TESTING)
7664
add_subdirectory(tests)

0 commit comments

Comments
 (0)