From c1479e57690e1b9f8150c936a54e3cd9046cc6cc Mon Sep 17 00:00:00 2001 From: brofield Date: Mon, 2 Dec 2024 09:30:31 +1000 Subject: [PATCH] Clean up CMakeLists a little --- .gitignore | 2 ++ CMakeLists.txt | 24 ++++++------------------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 83ba081..8bda967 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ bld/ [Oo]bj/ [Ll]og/ [Ll]ogs/ +build/ +build-system-gtest/ # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b360ad..3b96f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -70,7 +57,8 @@ target_include_directories(${PROJECT_NAME} INTERFACE $ ) -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)