From 8699e96609d4449fa1c7704a292a76bbbb5d6bb8 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 23 Oct 2021 12:09:44 +0200 Subject: [PATCH] build_system: * ENTT_USE_LIBCPP default is OFF * added ENTT_INCLUDE_HEADERS to make adding headers to the EnTT target optional * slightly better message handling --- CMakeLists.txt | 180 ++++++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a78c9b9a9..113794f90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,37 +42,41 @@ message(VERBOSE "* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})") message(VERBOSE "* Copyright (c) 2017-2021 Michele Caini ") message(VERBOSE "*") -option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if availbale." ON) +option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if availbale." OFF) option(ENTT_USE_SANITIZER "Enable sanitizers by adding -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined flags if availbale." OFF) # # Compiler stuff # -if(NOT WIN32 AND ENTT_USE_LIBCPP) - include(CheckCXXSourceCompiles) - include(CMakePushCheckState) +if(ENTT_USE_LIBCPP) + if(NOT WIN32) + include(CheckCXXSourceCompiles) + include(CMakePushCheckState) - cmake_push_check_state() + cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++") - check_cxx_source_compiles(" - #include - int main() { return std::is_same_v; } - " ENTT_HAS_LIBCPP) + check_cxx_source_compiles(" + #include + int main() { return std::is_same_v; } + " ENTT_HAS_LIBCPP) + + cmake_pop_check_state() + endif() if(NOT ENTT_HAS_LIBCPP) message(VERBOSE "The option ENTT_USE_LIBCPP is set but libc++ is not available. The flag will not be added to the target.") endif() - - cmake_pop_check_state() endif() if(ENTT_USE_SANITIZER) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(ENTT_HAS_SANITIZER TRUE CACHE INTERNAL "") - else() + endif() + + if(NOT ENTT_HAS_SANITIZER) message(VERBOSE "The option ENTT_USE_SANITIZER is set but sanitizer support is not available. The flags will not be added to the target.") endif() endif() @@ -81,82 +85,13 @@ endif() # Add EnTT target # +option(ENTT_INCLUDE_HEADERS "Add all EnTT headers to the EnTT target." OFF) + include(GNUInstallDirs) add_library(EnTT INTERFACE) add_library(EnTT::EnTT ALIAS EnTT) -target_sources( - EnTT - INTERFACE - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ -) - target_include_directories( EnTT INTERFACE @@ -164,6 +99,81 @@ target_include_directories( $ ) +target_compile_features(EnTT INTERFACE cxx_std_17) + +if(ENTT_INCLUDE_HEADERS) + target_sources( + EnTT + INTERFACE + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + ) +endif() + if(ENTT_HAS_SANITIZER) target_compile_options(EnTT INTERFACE $<$:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>) target_link_libraries(EnTT INTERFACE $<$:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>) @@ -173,8 +183,6 @@ if(ENTT_HAS_LIBCPP) target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++) endif() -target_compile_features(EnTT INTERFACE cxx_std_17) - # # Install pkg-config file #