Skip to content

Commit

Permalink
Clean up CMakeLists a little
Browse files Browse the repository at this point in the history
  • Loading branch information
brofield committed Dec 1, 2024
1 parent d9c1b13 commit c1479e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ bld/
[Oo]bj/
[Ll]og/
[Ll]ogs/
build/
build-system-gtest/

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down
24 changes: 6 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,14 @@ project(
LANGUAGES CXX
)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(IS_TOPLEVEL_PROJECT TRUE)
else()
set(IS_TOPLEVEL_PROJECT FALSE)
endif()

option(SIMPLEINI_USE_SYSTEM_GTEST "Use system GoogleTest dependency" OFF)

# Disable in-source builds:
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)

if("${srcdir}" STREQUAL "${bindir}")
message("")
message("ERROR:: in-source builds are disabled!")
message("Run cmake in a separate build directory:")
message("$ cmake -S . -B build")
message("")
message(FATAL_ERROR "Aborting...")
# disable in-source builds
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed, use cmake -S . -B build.")
endif()


# Define library paths and include directories
set(EXPORT_NAMESPACE "${PROJECT_NAME}::")
set(HEADERS SimpleIni.h)
Expand Down Expand Up @@ -70,7 +57,8 @@ target_include_directories(${PROJECT_NAME} INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

if(IS_TOPLEVEL_PROJECT)
# only build tests when top level and testing enabled
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
Expand Down

0 comments on commit c1479e5

Please sign in to comment.