HappySeaFox / sail

The missing small and fast image decoding library for humans (not for machines) ⛵ https://sail.software
MIT License
311 stars 25 forks source link

Investigate OpenMP flags correctness #205

Closed HappySeaFox closed 10 months ago

HappySeaFox commented 10 months ago

Upon further testing, openMP wasn't actually getting enabled when compiling the project. Even though the arguments in OpenMP_C_FLAGS are correct (-Xclang -fopenmp), CMake tries to encapsulate both arguments in a single set of quotes which makes it invalid. Using the alternative syntax for passing normal clang arguments to clang-cl works though (/clang:-fopenmp). This seems to function correctly in my testing:

    if (MSVC)
            if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
                 set(SAIL_OPENMP_FLAGS "/clang:-fopenmp" CACHE INTERNAL "")
            else()
                set(SAIL_OPENMP_FLAGS "/openmp:llvm" CACHE INTERNAL "")
            endif()
        else()
            set(SAIL_OPENMP_FLAGS ${OpenMP_C_FLAGS} CACHE INTERNAL "")
        endif()

Originally posted by @Error-mdl in https://github.com/HappySeaFox/sail/issues/203#issuecomment-1856526290

Error-mdl commented 10 months ago

CMakeCache.txt Seems to be an error in Visual Studio's cmake support. Building from directly from CMake works, and there's no quotes around the arguments in the CMake cache. The error only happens when compiling the generated solution file in VS. Building from VS throws this error: clang-cl : warning : unknown argument ignored in clang-cl: '-Xclang -fopenmp' [-Wunknown-argument] VS seems to incorrectly see -Xclang -fopenmp as a single argument and puts both in a single set of quotes which causes the issue (shows up in the Additional Options as %(AdditionalOptions) "-Xclang -fopenmp"). Removing the quotes fixes the error.

HappySeaFox commented 10 months ago

I see. What's your CMake version? Maybe it's a bug in the CMake VS generator.