How to set linker flags for OpenMP in CMake's try_compile function

后端 未结 4 1122
面向向阳花
面向向阳花 2020-11-29 01:25

I would like to verify that the current compiler can build with openmp support. The application has do deploy across a wide variety of unix systems, some of which might hav

4条回答
  •  生来不讨喜
    2020-11-29 01:26

    OpenMP support has been improved in CMake 3.9+

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.9)
    project(openmp_test) # you can change the project name
    
    find_package(OpenMP)
    
    add_executable(openmp_para_test main.cpp) # you can change the excutable name
    
    if(OpenMP_CXX_FOUND)
        target_link_libraries(openmp_para_test PUBLIC OpenMP::OpenMP_CXX)
    endif()
    

    This way will correctly set the library link line differently from the compile line if needed.

    Source.

提交回复
热议问题