Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent adding /MP flag for MSVC in case any other language than C/CXX will be used (e.g. CUDA) #2862

Merged
merged 1 commit into from
Feb 15, 2019

Conversation

SunBlack
Copy link
Contributor

In our project we had currently sometimes issues with equivalent CMake code for the flag /MP. Reason add_compile_options("/MP") will add /MP flag to all compilers - even CUDA. Currently this isn't an issue in PCL, because PCL is using CUDA via find_package(CUDA) and not via modern variant (project(pcl CXX CUDA)), see here.

So currently we have 3 options:

  1. Do not change anything, because currently no issue with it in PCL (just upcoming)
  2. Use old variant (adjust CMAKE_CXX_FLAGS) and add a comment how it looks like if minimum required CMake version will be increased:
    set(MSVC_MP ${CPUCores} CACHE STRING "Number of simultaneously running compilers (0 = automatic detection by MSVC). See documentation of /MP flag.")
    # Replace CMAKE_C_FLAGS/CMAKE_CXX_FLAGS by add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/MP${MSVC_MP}>) after miniumum required CMake version is raised to 3.11, see https://gitlab.kitware.com/cmake/cmake/issues/17535
    if(MSVC_MP EQUAL 0)
      # MSVC_MP is 0 in case the information cannot be determined by ProcessorCount => fallback
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
    elseif(MSVC_MP GREATER 1)
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${MSVC_MP}")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP${MSVC_MP}")
    endif()
  1. Use old variant before CMake 3.11 and new after (see PR)

I don't like option 1, but I have no preference if we use variant 2 or 3. Variant 2 is shorter, but variant 3 is using more modern CMake code.

@jasjuang
Copy link
Contributor

I like variant 3, but if it isn't a lot of work I think we should try to switch add_compile_options over to target_compile_options because the compile flags will actually be propagated to the downstream and won't be lost in the middle. Also having a per target compile option is better than a global compile option because it is more modular.

Copy link
Member

@taketwo taketwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since variant 3 is already implemented, no reason to not merge it I think. In future target_compile_options should certainly be our goal.

CMakeLists.txt Show resolved Hide resolved
@SergioRAgostinho SergioRAgostinho merged commit 78c795c into PointCloudLibrary:master Feb 15, 2019
@SunBlack SunBlack deleted the fix_mp_flag branch February 15, 2019 15:58
@taketwo taketwo changed the title Prevent adding /MP flag for MSVC in case any other language than C/CXX will be used (e.g. CUDA) Prevent adding /MP flag for MSVC in case any other language than C/CXX will be used (e.g. CUDA) Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants