-1

so I've been trying to migrate my Qt/C++ project over from MSVC 2017 to MSVC 2019, and it's been a rough time. I'm getting the following error when trying to build in Visual Studio 2019:

2>cl : command line warning D9002: ignoring unknown option '/mp'

I was not getting this error before when using Visual Studio 2017, so that's odd. I desperately need this flag, since my compilation times are >10x slower without it. On a slightly different note, I also can't quite figure out how to get the build to be 32 bit, but one thing at a time. My cmake file looks like this:

# CMake build

# Project-level setup ====================================================
project( engine ) # TODO: Set version
cmake_minimum_required( VERSION 3.16 )
set(TARGET_NAME "engine")
set(TEST_TARGET_NAME "engine_tests")

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON) # Saves having to use QT5_WRAP_CPP
set(CMAKE_AUTORCC ON) # Saves having to use QT5_ADD_RESOURCES
set(CMAKE_AUTOUIC ON) # Saves having to use QT5_WRAP_UI

# Set compiler flags =====================================================
# Use C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# TODO: 64 bit
if (MSVC)
    add_compile_options(/mp /bigobj /wd4577 /wd4467 /wd26812 /wd26812)
else()
endif()

# Set paths to find Qt ===================================================
# Find Qt itself
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    # set(QT_MSVC_2017 "C:\\Qt\\5.12\\5.12.2\\msvc2017")
    set(QT_MSVC_2019 "C:\\Qt\\5.15\\5.15.2\\msvc2019")
    
    set(CMAKE_PREFIX_PATH ${QT_MSVC_2019})
else()
    message (WARNING "-------- System not supported ---------")
endif()

# Find UI files
set(CMAKE_AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/ui")

# Find Required Qt Libraries =============================================
find_package(Qt5 COMPONENTS Core REQUIRED)# Core stuff
find_package(Qt5 COMPONENTS Concurrent REQUIRED) # For threading
find_package(Qt5 COMPONENTS Gamepad REQUIRED) # Controller support
find_package(Qt5 COMPONENTS Gui REQUIRED) # For OpenGL integration
find_package(Qt5 COMPONENTS OpenGLExtensions REQUIRED)
find_package(Qt5 COMPONENTS Multimedia REQUIRED) # Multimedia capabilities
find_package(Qt5 COMPONENTS MultimediaWidgets REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED) # For widgets

# OpenGL libraries
# See: https://stackoverflow.com/questions/65100749/converting-from-qmake-to-cmake-how-do-i-find-libraries-in-the-same-way/65106458#65106458
find_package(OpenGL REQUIRED) # enforces as a requirement

# Set build mode directory options ========================================
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/release)

# Set directories to find libraries, need to do this before add_executable for desired target
file(TO_CMAKE_PATH "$ENV{PYTHON_LIB}" ENV_PYTHON_LIB)
message(STATUS "Setting link directory ${ENV_PYTHON_LIB}")
link_directories(${ENV_PYTHON_LIB})

# Build EXE ===============================================================
message (STATUS "-------- Finding source, header, resource, UI files relative to  ${CMAKE_SOURCE_DIR} ---------")
file(GLOB_RECURSE MY_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp"  "src/*.h"
"resources/*.qrc" "ui/*.ui")

# Get all the source files to build the test suite
file(GLOB_RECURSE MY_TEST_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp" "src/*.h" "resources/*.qrc" "ui/*.ui" "tests/*.cpp" "tests/*.h")
list(FILTER MY_TEST_SOURCES EXCLUDE REGEX "src/main.cpp")


# Generate release PDB
# https://stackoverflow.com/questions/28178978/how-to-generate-pdb-files-for-release-build-with-cmake-flags/31264946
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:/Zi>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/DEBUG>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:ICF>")

# Add an executable to be built from sources variable
# add_executable(${TARGET_NAME} ${MY_SOURCES})
add_executable(${TARGET_NAME} WIN32 ${MY_SOURCES}) # Makes sure that this is a windows application, not a console app
add_executable(${TEST_TARGET_NAME} ${MY_TEST_SOURCES})

# Pre-processor Defines ===================================================
add_definitions(-D_UNICODE -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DQT_DLL -DQT_OPENGL_LIB)
add_definitions(-DDEVELOP_MODE)
add_definitions(-DLINALG_USE_EIGEN)

# Disable warnings about deprecated things, like using strcpy (sorry, not sorry)
if(MSVC)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()

# Command-line configuration ===================================================
set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS "${CMAKE_SOURCE_DIR}")

# Add additional include directories for including using src as root =======================================
target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/src")
target_include_directories(${TEST_TARGET_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/src")

########### Iterate over all targets to link libraries #################
foreach(current_target ${TARGET_NAME} ${TEST_TARGET_NAME})

# Set linker properties ===================================================
set(DEBUG_DEFINITIONS "DEBUG_MODE")
set(RELEASE_DEFINITIONS "QT_NO_DEBUG_OUTPUT")
target_compile_definitions(${current_target} PUBLIC
    $<$<CONFIG:DEBUG>:${DEBUG_DEFINITIONS}>
    $<$<CONFIG:RELEASE>:${RELEASE_DEFINITIONS}>
)

# Link Required Qt modules to main target =================================
target_link_libraries(${current_target} OpenGL::GL OpenGL::GLU)
target_link_libraries(${current_target} Qt5::Core)
target_link_libraries(${current_target} Qt5::Concurrent) 
target_link_libraries(${current_target} Qt5::Gamepad)
target_link_libraries(${current_target} Qt5::Gui)
target_link_libraries(${current_target} Qt5::OpenGLExtensions) # TODO: Probably unnecessary, remove
target_link_libraries(${current_target} Qt5::Multimedia)
target_link_libraries(${current_target} Qt5::MultimediaWidgets)
target_link_libraries(${current_target} Qt5::Widgets)

# Add additional libraries ================================================
# stuff here
    

endforeach()

Hopefully it's pretty straightforward, I'm building a main project as well as a test project. I am aware that the file GLOB is highly discouraged by cmake folks, but I will eventually hand enter my file paths. Otherwise, this was working for me just fine with MSVC 2017. Before (when I only had Visual Studio 2017 installed), it was enough to call cmake using:

cmake -B"./app" -S"./my_project"

But now I'm doing the following:

cmake -B"./app" -S"./my_project" -G "Visual Studio 16 2019" -A Win32

To the best of my understanding this SHOULD give me what I want, which is a 32 bit build. However, When I go to my project's configuration properties, the Preferred Build Tool Architecture is still 64-bit. Is this related to the build of the project itself? If this is a non-issue, then that's great! However, I still don't understand why the /MP flag is no longer recognized.

Danny
  • 354
  • 3
  • 13
  • 4
    `cl` compiler options are [case-sensitive](https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-160), so `/mp` is not [`/MP`](https://learn.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes?view=msvc-160). – dxiv Feb 28 '21 at 05:49
  • I'm guessing "preferred build tool architecture" is referring to the bitness of the _compiler itself_, rather than the code it is generating. – Alex Reinking Feb 28 '21 at 10:27
  • @dxiv Duh, that did it! – Danny Feb 28 '21 at 19:37
  • @AlexReinking Yup, you're correct! – Danny Feb 28 '21 at 19:38

1 Answers1

0

try /MP10

The processMax argument must range from 1 through 65536. Otherwise, the compiler issues warning message D9014, ignores the processMax argument, and assumes the maximum number of processes is 1.

https://learn.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes?view=msvc-160