Skip to content

Commit

Permalink
[CMake] CLEAN/FIX deprecated things (MSVC mainly) (#2217)
Browse files Browse the repository at this point in the history
* msvc: re-enable deprecated warnings for Sofa modules

* msvc: disable deprecated warnings for external projects

* msvc: use Sleep instead of deprecated _sleep

* unique() for shared_ptr is deprecated (https://en.cppreference.com/w/cpp/memory/shared_ptr/unique)

* Update CMakeLists.txt

Co-authored-by: Guillaume Paran <guillaume.paran@sofa-framework.org>
  • Loading branch information
fredroy and guparan committed Jul 1, 2021
1 parent 9067170 commit f4b409d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions SofaKernel/extlibs/newmat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ else()
target_compile_definitions(${PROJECT_NAME} PUBLIC "USING_DOUBLE")
endif()

if(WIN32)
# remove warnings about deprecation (CRT,etc)
target_compile_options(${PROJECT_NAME} PRIVATE "/wd4996")
endif()

# The code must be relocatable if we want to link a shared library against it
if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xGNU" OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
target_compile_options(${PROJECT_NAME} PRIVATE "-fPIC")
Expand Down
5 changes: 4 additions & 1 deletion SofaKernel/modules/Sofa.Config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ endif()
## Windows-specific
if(WIN32)
list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_USE_MATH_DEFINES")
list(APPEND SOFACONFIG_COMPILE_OPTIONS "/MP;/wd4250;/wd4251;/wd4275;/wd4675;/wd4996;/wd4661")
list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_CRT_SECURE_NO_WARNINGS")
list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_CRT_NONSTDC_NO_DEPRECATE")

list(APPEND SOFACONFIG_COMPILE_OPTIONS "/MP;/wd4250;/wd4251;/wd4275;/wd4675;/wd4661")
# 4661: no suitable definition provided for explicit template instantiation request
# it happens because we put explicit instantiation in a separate translation unit
# it is by design, so this warning is irrelevant in our project
Expand Down
2 changes: 1 addition & 1 deletion SofaKernel/modules/SofaCore/src/sofa/core/MultiVecId.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class TMultiVecId
{
if (!idMap_ptr)
idMap_ptr.reset(new IdMap());
else if(!idMap_ptr.unique())
else if(!(idMap_ptr.use_count() == 1))
idMap_ptr.reset(new IdMap(*idMap_ptr));
return *idMap_ptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DataContentValue<T, true>

T* beginEdit()
{
if(!ptr.unique())
if(!(ptr.use_count() == 1))
{
ptr.reset(new T(*ptr)); // a priori the Data will be modified -> copy
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ctime_t CTime::getRefTicksPerSec()

void CTime::sleep(double a)
{
_sleep((long)(a*1000.0));
Sleep((long)(a*1000.0));
}

#else /* WIN32 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xGNU" OR "x${CMAKE_CXX_COMPILER_ID}" ST
target_compile_options(${PROJECT_NAME} PRIVATE "-fPIC")
endif()

if(WIN32)
# remove warnings about deprecation (CRT,etc)
target_compile_options(${PROJECT_NAME} PRIVATE "/wd4996")
endif()

include(SofaMacros)
sofa_create_package_with_targets(
PACKAGE_NAME MiniFlowVR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<INSTALL_INTERFACE:in

if(WIN32)
target_compile_options(${PROJECT_NAME} PRIVATE "-DCREATE_QGLVIEWER_DLL")
target_compile_options(${PROJECT_NAME} PRIVATE "/wd4996") # remove warnings about deprecation (CRT,etc)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_d")
Expand Down
5 changes: 5 additions & 0 deletions modules/SofaSparseSolver/extlibs/csparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<INSTALL_INTERFACE:include/extlibs/CSparse>")

if(WIN32)
# remove warnings about deprecation (CRT,etc)
target_compile_options(${PROJECT_NAME} PRIVATE "/wd4996")
endif()

sofa_create_package_with_targets(
PACKAGE_NAME CSparse
PACKAGE_VERSION ${PROJECT_VERSION}
Expand Down
5 changes: 5 additions & 0 deletions modules/SofaSparseSolver/extlibs/metis-5.1.0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if(UNIX)
target_link_libraries(${PROJECT_NAME} m)
endif()

if(WIN32)
# remove warnings about deprecation (CRT,etc)
target_compile_options(${PROJECT_NAME} PRIVATE "/wd4996")
endif()

sofa_create_package_with_targets(
PACKAGE_NAME Metis
PACKAGE_VERSION 5.1.0
Expand Down

0 comments on commit f4b409d

Please sign in to comment.