Updated cmake script to use interface library to set compiler options in targets
parent
bc251ddcca
commit
0f3380c755
|
@ -5,7 +5,7 @@ else()
|
|||
endif()
|
||||
|
||||
# Use new RPATH behavior on macOS
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
|
||||
if(POLICY CMP0068)
|
||||
cmake_policy(SET CMP0068 NEW)
|
||||
endif()
|
||||
|
||||
|
@ -124,6 +124,73 @@ if(TGUI_OS_ANDROID)
|
|||
set(LIB_SUFFIX "/${CMAKE_ANDROID_ARCH_ABI}")
|
||||
endif()
|
||||
|
||||
# Set the c++ library used by all targets (not allowed through interface library apparently)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
if(TGUI_USE_CPP17)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
endif()
|
||||
|
||||
# Create an interface library to pass the warnings to all targets
|
||||
add_library(interface_warnings INTERFACE)
|
||||
if(TGUI_COMPILER_MSVC)
|
||||
target_compile_options(interface_warnings INTERFACE /W4)
|
||||
else()
|
||||
target_compile_options(interface_warnings
|
||||
INTERFACE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wshadow
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wpedantic
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wuseless-cast
|
||||
-Wdouble-promotion
|
||||
-Wformat=2)
|
||||
endif()
|
||||
|
||||
# Create an interface library to pass the standard library to all targets
|
||||
add_library(interface_stdlib INTERFACE)
|
||||
|
||||
if(TGUI_OS_MACOSX)
|
||||
# Use libc++ on macOS
|
||||
if(${CMAKE_GENERATOR} MATCHES "Xcode")
|
||||
set_target_properties(interface_stdlib PROPERTY XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
|
||||
else()
|
||||
target_compile_options(interface_stdlib INTERFACE "-stdlib=libc++")
|
||||
target_link_libraries(interface_stdlib INTERFACE "-stdlib=libc++")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(TGUI_OS_WINDOWS)
|
||||
# Apply the TGUI_USE_STATIC_STD_LIBS option on windows
|
||||
if(TGUI_COMPILER_GCC)
|
||||
if(TGUI_USE_STATIC_STD_LIBS AND NOT TGUI_COMPILER_GCC_TDM)
|
||||
target_link_libraries(interface_stdlib INTERFACE "-static-libgcc" "-static-libstdc++")
|
||||
elseif(NOT TGUI_USE_STATIC_STD_LIBS AND TGUI_COMPILER_GCC_TDM)
|
||||
target_link_libraries(interface_stdlib INTERFACE "-shared-libgcc" "-shared-libstdc++")
|
||||
endif()
|
||||
elseif(TGUI_COMPILER_MSVC AND TGUI_USE_STATIC_STD_LIBS)
|
||||
foreach(flag
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Link SFML in the same way as TGUI, unless SFML_STATIC_LIBRARIES is manually specified
|
||||
if(NOT DEFINED SFML_STATIC_LIBRARIES)
|
||||
if(TGUI_SHARED_LIBS)
|
||||
|
|
|
@ -6,57 +6,6 @@ macro(tgui_set_option var default type docstring)
|
|||
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
|
||||
endmacro()
|
||||
|
||||
# Set the compile options used by all targets
|
||||
function(tgui_set_global_compile_flags target)
|
||||
if(TGUI_COMPILER_GCC OR TGUI_COMPILER_CLANG)
|
||||
target_compile_options(${target} PRIVATE -Wall)
|
||||
target_compile_options(${target} PRIVATE -Wextra)
|
||||
target_compile_options(${target} PRIVATE -Wshadow)
|
||||
target_compile_options(${target} PRIVATE -Wno-long-long)
|
||||
target_compile_options(${target} PRIVATE -pedantic)
|
||||
|
||||
set_target_properties(${target} PROPERTIES CXX_STANDARD_REQUIRED ON)
|
||||
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
|
||||
if(TGUI_USE_CPP17)
|
||||
set_target_properties(${target} PROPERTIES CXX_STANDARD 17)
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES CXX_STANDARD 14)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Set the appropriate standard library on each platform for the given target
|
||||
function(tgui_set_stdlib target)
|
||||
# Use libc++ on macOS
|
||||
if(TGUI_OS_MACOSX)
|
||||
if(${CMAKE_GENERATOR} MATCHES "Xcode")
|
||||
set_property(TARGET ${target} PROPERTY XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
|
||||
else()
|
||||
target_compile_options(${target} PRIVATE "-stdlib=libc++")
|
||||
target_link_libraries(${target} PRIVATE "-stdlib=libc++")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Apply the TGUI_USE_STATIC_STD_LIBS option on windows
|
||||
if(TGUI_OS_WINDOWS)
|
||||
if(TGUI_COMPILER_MSVC AND TGUI_USE_STATIC_STD_LIBS)
|
||||
foreach(flag
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
||||
endif()
|
||||
endforeach()
|
||||
elseif(TGUI_COMPILER_GCC)
|
||||
if(TGUI_USE_STATIC_STD_LIBS AND NOT TGUI_COMPILER_GCC_TDM)
|
||||
target_link_libraries(${target} PRIVATE "-static-libgcc" "-static-libstdc++")
|
||||
elseif(NOT TGUI_USE_STATIC_STD_LIBS AND TGUI_COMPILER_GCC_TDM)
|
||||
target_link_libraries(${target} PRIVATE "-shared-libgcc" "-shared-libstdc++")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Generate a TGUIConfig.cmake file (and associated files)
|
||||
function(tgui_export_target export_name)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
|
|
@ -14,16 +14,13 @@ macro(tgui_add_example target)
|
|||
endif()
|
||||
|
||||
add_executable(${target} ${GUI_APP} ${THIS_SOURCES})
|
||||
target_link_libraries(${target} PRIVATE tgui)
|
||||
target_link_libraries(${target} PRIVATE tgui interface_warnings interface_stdlib)
|
||||
|
||||
# Link to sfml-main (only when SFMLConfig.cmake is used, this is done through the tgui target if FindSFML.cmake is used)
|
||||
if((TGUI_OS_WINDOWS OR TGUI_OS_IOS) AND NOT DEFINED SFML_LIBRARIES)
|
||||
target_link_libraries(${target} PRIVATE sfml-main)
|
||||
endif()
|
||||
|
||||
tgui_set_global_compile_flags(${target})
|
||||
tgui_set_stdlib(${target})
|
||||
|
||||
# Add the install rule for the executable
|
||||
install(TARGETS ${target}
|
||||
RUNTIME DESTINATION ${TGUI_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples
|
||||
|
|
|
@ -16,7 +16,7 @@ if(TGUI_OS_WINDOWS)
|
|||
endif()
|
||||
|
||||
add_executable(gui-builder ${GUI_TYPE} ${GUI_BUILDER_SOURCES})
|
||||
target_link_libraries(gui-builder PRIVATE tgui)
|
||||
target_link_libraries(gui-builder PRIVATE tgui interface_warnings interface_stdlib)
|
||||
target_include_directories(gui-builder PRIVATE include)
|
||||
|
||||
# Link to sfml-main (only when SFMLConfig.cmake is used, this is done through the tgui target if FindSFML.cmake is used)
|
||||
|
@ -24,9 +24,6 @@ if(TGUI_OS_WINDOWS AND NOT DEFINED SFML_LIBRARIES)
|
|||
target_link_libraries(gui-builder PRIVATE sfml-main)
|
||||
endif()
|
||||
|
||||
tgui_set_global_compile_flags(gui-builder)
|
||||
tgui_set_stdlib(gui-builder)
|
||||
|
||||
# Copy the executable to the gui-builder folder
|
||||
add_custom_command(TARGET gui-builder POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:gui-builder> ${PROJECT_SOURCE_DIR}/gui-builder/
|
||||
|
|
|
@ -18,9 +18,8 @@ if (CMAKE_ANDROID_STL_TYPE MATCHES "_shared")
|
|||
target_compile_definitions(tgui-activity PRIVATE STL_LIBRARY=${CMAKE_ANDROID_STL_TYPE})
|
||||
endif()
|
||||
|
||||
tgui_set_global_compile_flags(tgui-activity)
|
||||
target_compile_options(tgui-activity PRIVATE -fpermissive)
|
||||
target_link_libraries(tgui-activity PRIVATE android log)
|
||||
target_link_libraries(tgui-activity PRIVATE android log interface_warnings interface_stdlib)
|
||||
|
||||
install(TARGETS tgui-activity
|
||||
RUNTIME DESTINATION bin COMPONENT bin
|
||||
|
|
|
@ -140,9 +140,6 @@ else()
|
|||
set_target_properties(tgui PROPERTIES RELWITHDEBINFO_POSTFIX -s)
|
||||
endif()
|
||||
|
||||
tgui_set_global_compile_flags(tgui)
|
||||
tgui_set_stdlib(tgui)
|
||||
|
||||
if(TGUI_OPTIMIZE_SINGLE_BUILD AND TGUI_COMPILER_MSVC)
|
||||
target_compile_options(tgui PRIVATE /bigobj)
|
||||
endif()
|
||||
|
@ -155,6 +152,8 @@ else()
|
|||
target_include_directories(tgui INTERFACE $<INSTALL_INTERFACE:include>)
|
||||
endif()
|
||||
|
||||
target_link_libraries(tgui PRIVATE interface_warnings interface_stdlib)
|
||||
|
||||
# Link to SFML
|
||||
if(DEFINED SFML_LIBRARIES)
|
||||
# SFML found via FindSFML.cmake
|
||||
|
|
|
@ -89,10 +89,7 @@ endif()
|
|||
|
||||
add_executable(tests ${TEST_SOURCES})
|
||||
target_include_directories(tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_link_libraries(tests PRIVATE tgui)
|
||||
|
||||
tgui_set_global_compile_flags(tests)
|
||||
tgui_set_stdlib(tests)
|
||||
target_link_libraries(tests PRIVATE tgui interface_warnings interface_stdlib)
|
||||
|
||||
if(TGUI_OPTIMIZE_SINGLE_BUILD AND TGUI_COMPILER_MSVC)
|
||||
target_compile_options(tests PRIVATE /bigobj)
|
||||
|
|
Loading…
Reference in New Issue