build: Set MSVC build settings and make sure MSVC is defined

This commit is contained in:
Ivey
2024-11-19 11:40:03 -05:00
committed by Gabriel Ferreira
parent b3870f04db
commit 528c9f927f
4 changed files with 36 additions and 6 deletions

View File

@@ -233,6 +233,10 @@ function(build_lib)
"${BLIB_LIBNAME}" "${BLIB_IGNORE_PCH}" "${FOLDER}" "${BLIB_TEST_SOURCES}"
)
if(${MSVC})
target_link_options(${lib${BLIB_LIBNAME}} PUBLIC "/OPT:NOREF")
endif()
# Handle package export
install(
TARGETS ${BLIB_LIBNAME}

View File

@@ -50,6 +50,7 @@ if(APPLE)
set(CMAKE_FIND_APPBUNDLE "LAST")
endif()
set(cat_command cat)
if(WIN32)
set(NS3_PRECOMPILE_HEADERS OFF
CACHE BOOL "Precompile module headers to speed up compilation" FORCE
@@ -59,17 +60,24 @@ if(WIN32)
# requires this definition
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=vs-2019
add_definitions(/D_USE_MATH_DEFINES)
set(cat_command type) # required until we move to CMake >= 3.18
endif()
set(cat_command cat)
if(CMAKE_XCODE_BUILD_SYSTEM)
set(XCODE True)
else()
set(XCODE False)
endif()
if(${XCODE})
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}"
MATCHES "MSVC"
)
set(MSVC True)
else()
set(MSVC False)
endif()
if(${MSVC} OR ${XCODE})
# Prevent multi-config generators from placing output files into per
# configuration directory
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
@@ -83,5 +91,23 @@ if(${XCODE})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
)
endforeach()
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
endif()
if(${MSVC})
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Enable exceptions
add_definitions(/EHs)
# Account for lack of valgrind and binary compatibility restrictions on
# Windows https://github.com/microsoft/STL/wiki/Changelog#vs-2022-1710
add_compile_definitions(
__WIN32__ NVALGRIND _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
_CRT_SECURE_NO_WARNINGS NS_MSVC NOMINMAX
)
# Allow unresolved symbols as in most cases they are simply in other ns-3
# libraries
add_link_options("/FORCE:UNRESOLVED")
endif()

View File

@@ -62,7 +62,7 @@ function(setup_vcpkg)
)
endif()
if(DEFINED MSVC)
if(${MSVC})
message(FATAL_ERROR "vcpkg: Visual Studio is unsupported")
else()
# Check if required packages are installed (unzip curl tar)

View File

@@ -212,7 +212,7 @@ macro(process_options)
# Set warning level and warning as errors
if(${NS3_WARNINGS})
if(DEFINED MSVC)
if(${MSVC})
add_compile_options(/W3) # /W4 = -Wall + -Wextra
if(${NS3_WARNINGS_AS_ERRORS})
add_compile_options(/WX)