Fixed two issues with cmake script

- Installing framework on macOS failed because install rules were not executed in correct order
- Cmake files installed to the lib folder contained SFML directories which made it hard to distribute them with the precompiled libs
0.8
Bruno Van de Velde 2018-10-11 19:40:14 +02:00
parent ec029b73db
commit 3f03917cb8
8 changed files with 40 additions and 13 deletions

View File

@ -1,4 +1,3 @@
sudo: false
language: cpp
git:
@ -64,7 +63,7 @@ jobs:
- chmod +x tests/travis_android.sh
- tests/travis_android.sh
- name: maxOS
- name: macOS
os: osx
cache:
directories:

View File

@ -250,6 +250,3 @@ install(DIRECTORY themes DESTINATION "${TGUI_MISC_INSTALL_PREFIX}")
if(TGUI_OS_ANDROID)
install(FILES Android.mk DESTINATION .)
endif()
# Generate the TGUIConfig.cmake file
tgui_export_target(TGUIConfigExport)

View File

@ -91,7 +91,7 @@ function(tgui_export_target export_name)
if (TGUI_BUILD_FRAMEWORK)
set(config_package_location "TGUI.framework/Resources/CMake")
else()
set(config_package_location lib/cmake/TGUI)
set(config_package_location lib${LIB_SUFFIX}/cmake/TGUI)
endif()
configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake/TGUIConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/TGUIConfig.cmake"
INSTALL_DESTINATION "${config_package_location}")

View File

@ -14,7 +14,14 @@ macro(tgui_add_example target)
endif()
add_executable(${target} ${GUI_APP} ${THIS_SOURCES})
target_link_libraries(${target} PRIVATE tgui)
if(DEFINED SFML_LIBRARIES)
# SFML found via FindSFML.cmake
target_include_directories(${target} PRIVATE ${SFML_INCLUDE_DIR})
target_link_libraries(${target} PRIVATE tgui ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
else()
# SFML found via SFMLConfig.cmake
target_link_libraries(${target} PRIVATE tgui sfml-graphics)
endif()
# 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)

View File

@ -16,8 +16,15 @@ if(TGUI_OS_WINDOWS)
endif()
add_executable(gui-builder ${GUI_TYPE} ${GUI_BUILDER_SOURCES})
target_link_libraries(gui-builder PRIVATE tgui)
target_include_directories(gui-builder PRIVATE include)
if(DEFINED SFML_LIBRARIES)
# SFML found via FindSFML.cmake
target_include_directories(gui-builder PRIVATE ${SFML_INCLUDE_DIR})
target_link_libraries(gui-builder PRIVATE tgui ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
else()
# SFML found via SFMLConfig.cmake
target_link_libraries(gui-builder PRIVATE tgui sfml-graphics)
endif()
# 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 AND NOT DEFINED SFML_LIBRARIES)

View File

@ -157,13 +157,16 @@ else()
endif()
# Link to SFML
# Altough we could use PUBLIC here instead of PRIVATE, it causes the files in lib/cmake/TGUI to
# hardcode the SFML directories, making it harder to distribute them with the precompiled libs.
# You will thus have to link to SFML yourself, but you were likely to already do this anyway.
if(DEFINED SFML_LIBRARIES)
# SFML found via FindSFML.cmake
target_include_directories(tgui PUBLIC ${SFML_INCLUDE_DIR})
target_link_libraries(tgui PUBLIC ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
target_include_directories(tgui PRIVATE ${SFML_INCLUDE_DIR})
target_link_libraries(tgui PRIVATE ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
else()
# SFML found via SFMLConfig.cmake
target_link_libraries(tgui PUBLIC sfml-graphics)
target_link_libraries(tgui PRIVATE sfml-graphics)
endif()
# define TGUI_USE_CPP17 if requested
@ -233,3 +236,9 @@ install(TARGETS tgui EXPORT TGUIConfigExport
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
FRAMEWORK DESTINATION . COMPONENT devel
)
# Generate the TGUIConfig.cmake file
# This has to happen here instead of in the root CMakeLists.txt because otherwise
# it might try to write to the macOS framework before the framework is installed.
# This is because the order of install rules is undefined between directories.
tgui_export_target(TGUIConfigExport)

View File

@ -89,8 +89,15 @@ endif()
add_executable(tests ${TEST_SOURCES})
target_include_directories(tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(tests PRIVATE tgui)
target_compile_definitions(tests PRIVATE TGUI_REMOVE_DEPRECATED_CODE)
if(DEFINED SFML_LIBRARIES)
# SFML found via FindSFML.cmake
target_include_directories(tests PRIVATE ${SFML_INCLUDE_DIR})
target_link_libraries(tests PRIVATE tgui ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
else()
# SFML found via SFMLConfig.cmake
target_link_libraries(tests PRIVATE tgui sfml-graphics)
endif()
tgui_set_global_compile_flags(tests)
tgui_set_stdlib(tests)

View File

@ -19,6 +19,7 @@ else
fi
cd build
cmake -DTGUI_BUILD_FRAMEWORK=TRUE -DSFML_INCLUDE_DIR=$SFML_ROOT/lib/SFML.framework -DTGUI_OPTIMIZE_SINGLE_BUILD=TRUE ..
cmake -DCMAKE_INSTALL_PREFIX=$HOME/TGUI_INSTALL -DTGUI_BUILD_FRAMEWORK=TRUE -DSFML_INCLUDE_DIR=$SFML_ROOT/lib/SFML.framework -DTGUI_OPTIMIZE_SINGLE_BUILD=TRUE ..
make -j2
make install
cd ..