CMake: improve setting C++ standard and configuration summary
CMake/fl_add_library.cmake: set target_compile_features(.. cxx_std_NN)
which is inherited by consumers of the library.
This prevents CMake user projects from failing if they would
otherwise compile with an older C++ standard.
CMake/fl_debug_var.cmake: add INTERFACE_COMPILE_FEATURES to fl_debug_target()
CMake/fl_summary.cmake: update summary format for longer variable names
CMakeLists.txt:
- check CMAKE_CXX_STANDARD given by the user (commandline)
and set C++ standard related CMake variables in the CMake cache.
The latter is experimental: setting in the cache may be reverted.
- add C++ standard related info to configure summary.
This commit is contained in:
parent
2d9cf4d83e
commit
c18c39071a
@ -2,7 +2,7 @@
|
||||
# Macro used by the CMake build system for the Fast Light Tool Kit (FLTK).
|
||||
# Originally written by Michael Surette
|
||||
#
|
||||
# Copyright 1998-2024 by Bill Spitzak and others.
|
||||
# Copyright 1998-2025 by Bill Spitzak and others.
|
||||
#
|
||||
# This library is free software. Distribution and use rights are outlined in
|
||||
# the file "COPYING" which should have been included with this file. If this
|
||||
@ -98,7 +98,10 @@ function(fl_add_library LIBNAME LIBTYPE SOURCES)
|
||||
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE "FL_LIBRARY")
|
||||
|
||||
# Set PUBLIC include and linker directories
|
||||
# Set PUBLIC properties, e.g. C++ standard and include and linker directories.
|
||||
# These properties are inherited by consumers of the libraries
|
||||
|
||||
target_compile_features(${TARGET_NAME} PUBLIC "cxx_std_${CMAKE_CXX_STANDARD}")
|
||||
|
||||
if(0) # DEBUG
|
||||
message(STATUS "fl_add_library and alias : fltk::${alias_name} ALIAS ${TARGET_NAME}")
|
||||
|
||||
@ -123,6 +123,7 @@ function(fl_debug_target name)
|
||||
LINK_LIBRARIES
|
||||
COMPILE_DEFINITIONS
|
||||
INTERFACE_COMPILE_DEFINITIONS
|
||||
INTERFACE_COMPILE_FEATURES
|
||||
INTERFACE_INCLUDE_DIRECTORIES
|
||||
INTERFACE_LINK_DIRECTORIES
|
||||
INTERFACE_LINK_LIBRARIES)
|
||||
|
||||
@ -30,7 +30,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/fl_debug_var.cmake)
|
||||
########################################################################
|
||||
|
||||
macro(fl_summary title value)
|
||||
fl_expand_name(label "${title}" 24)
|
||||
fl_expand_name(label "${title}" 30)
|
||||
message(STATUS "${label} ${value}")
|
||||
endmacro(fl_summary title value)
|
||||
|
||||
|
||||
@ -46,16 +46,20 @@ project(FLTK VERSION 1.5.0)
|
||||
# Note 3: This code is experimental and intentionally undocumented.
|
||||
# It may be removed or changed w/o notice.
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
if(DEFINED CMAKE_CXX_STANDARD)
|
||||
if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS 11)
|
||||
message(FATAL_ERROR "The FLTK project requires at least C++11")
|
||||
endif()
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 11 CACHE STRING "Minimal C++ Standard")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Minimal C++ Standard Required?")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Use Compiler Specific C++ Extensions")
|
||||
endif()
|
||||
|
||||
#######################################################################
|
||||
@ -69,12 +73,24 @@ include(CMake/fl_add_library.cmake)
|
||||
# right now we don't use compatibility functions
|
||||
# include(CMake/compatibility.cmake)
|
||||
|
||||
if(0)
|
||||
if(0) # debug most important CMake variables and features
|
||||
# FLTK version
|
||||
fl_debug_var(FLTK_VERSION_MAJOR)
|
||||
fl_debug_var(FLTK_VERSION_MINOR)
|
||||
fl_debug_var(FLTK_VERSION_PATCH)
|
||||
fl_debug_var(FLTK_VERSION)
|
||||
# CMake version and C++ standard
|
||||
fl_debug_var(CMAKE_VERSION)
|
||||
fl_debug_var(CMAKE_CXX_STANDARD)
|
||||
fl_debug_var(CMAKE_CXX_STANDARD_REQUIRED)
|
||||
fl_debug_var(CMAKE_CXX_EXTENSIONS)
|
||||
# Build platform
|
||||
fl_debug_var(MSVC)
|
||||
fl_debug_var(MINGW)
|
||||
fl_debug_var(MSYS)
|
||||
fl_debug_var(UNIX)
|
||||
fl_debug_var(APPLE)
|
||||
fl_debug_var(CMAKE_CROSSCOMPILING)
|
||||
endif()
|
||||
|
||||
# Set FLTK_VERSION in the cache so user projects can access it,
|
||||
@ -345,7 +361,17 @@ else()
|
||||
fl_summary("${title}" "No")
|
||||
endif()
|
||||
|
||||
fl_summary_yn("Use std::" FLTK_USE_STD)
|
||||
message("")
|
||||
|
||||
if(FLTK_USE_STD)
|
||||
fl_summary("Use std::" "Yes - obsolete: always enabled since FLTK 1.5.0")
|
||||
else()
|
||||
fl_summary("Use std::" "No - *should* always be enabled since FLTK 1.5.0 !!")
|
||||
endif()
|
||||
|
||||
fl_summary( "CMAKE_CXX_STANDARD" "${CMAKE_CXX_STANDARD}")
|
||||
fl_summary_yn("CMAKE_CXX_STANDARD_REQUIRED" CMAKE_CXX_STANDARD_REQUIRED)
|
||||
fl_summary_yn("CMAKE_CXX_EXTENSIONS" CMAKE_CXX_EXTENSIONS)
|
||||
|
||||
message("")
|
||||
message(STATUS "End of Configuration Summary --\n")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user