Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Deprecated auto_ptr in AudioDevice and CMake configuration  (Read 5813 times)

0 Members and 1 Guest are viewing this topic.

JinLisek

  • Newbie
  • *
  • Posts: 8
    • View Profile
Deprecated auto_ptr in AudioDevice and CMake configuration
« on: August 01, 2018, 09:05:25 am »
Hello,

I'm new to the forum (and using forums in general), so be gentle, please. ;) And nice to meet you!

I've just started using SFML today. What I want to do is to compile SFML, along my game, within CMake project.

I think, I've correctly compiled and linked SFML, because below code works as expected:
sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)

Before I begin to describe the issue, I'll just say that I've tried to search for an answer, but to no avail. I've found this https://en.sfml-dev.org/forums/index.php?topic=21110.0, but I haven't found my answer there. I've also read CMake Tutorial for compiling SFML, but it doesn't work for me, as I don't want to compile just SFML, but whole project (and SFML is a part of it). SFML I use is taken directly from github (at tag 2.5.0) and added to my project as git submodule.

My problem is that I get a warning while compiling AudioDevice.cpp:
../deps/sfml/src/SFML/Audio/AudioDevice.cpp:110:10: warning: &#8216;template<class> class std::auto_ptr&#8217; is deprecated [-Wdeprecated-declarations]
     std::auto_ptr<AudioDevice> device;
 

From the knowledge I've gathered so far, it seems the issue is with my project using different compiler than compiler used to compile SFML. However, I don't think that's possible, as my project compiles SFML (so the compiler should be the same).

Below are my CMake files, but only those that I think matter. I also removed lines which include different libraries etc.

My sfml.cmake:
set(SFML_DIR "deps/sfml/"
    CACHE PATH "The path to the SFML framework.")

add_subdirectory(${SFML_DIR} ${CMAKE_BINARY_DIR}/sfml)
include_directories(SYSTEM ${SFML_DIR}/sfml/include
                           ${SFML_DIR}/sfml/include)
 

My main CMakeLists.txt:
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

project("Snake With A Twist")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)

include(sfml)

add_subdirectory(app)
 

My app CMakeLists.txt:
add_executable(SnakeWithATwist main.cpp)

target_link_libraries(SnakeWithATwist
    PRIVATE sfml-window
)

target_compile_options(SnakeWithATwist PRIVATE -Wall -Wextra -Werror)

target_compile_features(SnakeWithATwist PRIVATE cxx_std_14)
 

If you want a deeper look, here is my project: https://github.com/JinLisek/SimpleSnakeGame

The correction is probably easy, but since my CMake experience is not that big, I just can't wrap my head around it. Any help is welcome and I'll be very grateful for all answers!
« Last Edit: August 01, 2018, 09:09:50 am by JinLisek »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #1 on: August 01, 2018, 09:56:32 am »
That's just a warning, it shouldn't stop your project from compiling. You use -Werror but that's just for your own sources, not for SFML, right?
Laurent Gomila - SFML developer

JinLisek

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #2 on: August 01, 2018, 08:01:46 pm »
You're right about it compiling. However, as I always try to do something better, if it's possible, I'd like to keep the project clean of warnings.

I'm not sure how CMake configures SFML. I've added -Werror to my main target, SnakeWithATwist, like this:
target_compile_options(SnakeWithATwist PRIVATE -Wall -Wextra -Werror)
 

But target SnakeWithATwist depends on SFML:
target_link_libraries(SnakeWithATwist PRIVATE sfml-window)
 

Shouldn't CMake also apply -Werror to sfml-window then?

And is it possible to somehow get rid of the warning? Well, I could locally just change auto_ptr to unique_ptr, if it doesn't take too much effort. Or is there some other way?

EDIT: After all, it was trivial to change auto_ptr to unique_ptr. Is it possible to apply the change to SFML repo? I know it's called pull request, but I don't know how to do that and if it's possible with SFML.

EDIT 2: I've created a pull request here: https://github.com/SFML/SFML/pull/1463
I think the topic can be closed. :)
« Last Edit: August 01, 2018, 08:51:37 pm by JinLisek »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #3 on: August 01, 2018, 11:51:27 pm »
If you ask me we should just add
Code: [Select]
set_target_properties(sfml-<module> PROPERTIES CXX_STANDARD 98 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)to all the module target definitions as long as SFML is still a C++98 library. If the compiler knows we are compiling using the C++98 standard it is smart enough to ignore std::auto_ptr usage and anything else that might be/get deprecated.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

JinLisek

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #4 on: August 02, 2018, 04:21:01 pm »
Thank you! That worked for me. :)

I didn't know that SFML uses C++ 98, but my pull request was canceled, so now I know. ;D

I'll just put set_target_properties for sfml-audio, because other modules compile just fine in C++ 11. :)

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #5 on: August 16, 2018, 12:03:28 am »
It's a bit trickier for latest versions of MSVC. If you compile everything as C++17 now, you'll have auto_ptr disabled by default. To enable it, you need to define _HAS_AUTO_PTR_ETC.

By the way, won't using pre-C++11 .so with >=C++11 code cause some problems? As far as I know, ABI has changed for pre and post C++11 libstdc++. Won't this cause some troubles if we always build SFML as C++03?
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

JinLisek

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #6 on: August 29, 2018, 07:17:52 pm »
Refresh, since nobody answered and the question asked by Elias Daler above is quite interesting, at least for me.

Now, that you mention it, I guess I'll try compiling my project with C++17.

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #7 on: March 08, 2021, 01:18:31 pm »
Yes >>

« Last Edit: March 08, 2021, 09:46:28 pm by Redee »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #8 on: March 08, 2021, 02:17:44 pm »
std::auto_ptr has since been removed anyways. Check out the master branch.  :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Deprecated auto_ptr in AudioDevice and CMake configuration
« Reply #9 on: March 08, 2021, 09:48:52 pm »
std::auto_ptr has since been removed anyways. Check out the master branch.  :)
Cool  ;) :)