[Openmp-commits] [openmp] r242298 - Large Refactor of CMake build system

Peyton, Jonathan L jonathan.l.peyton at intel.com
Wed Jul 22 13:01:07 PDT 2015


That was my initial implementation, but one of the linker flags failed when building an executable vs. building a shared library.  Now I'm not positive that flag is still there (I got rid of a lot of redundant flags that were default in recent versions of the major compilers: gcc/clang/MSVC).  It's also a difficult task to accomplish on Windows because you can't include linker flags in the compile phase for MSVC or it will fail.  So I decided to bite the bullet and create a shared library linker flag check which I thought was checking the correct thing (check if a linker flag is supported in the link phase during the build of a shared library).

-- Johnny

-----Original Message-----
From: hwennborg at google.com [mailto:hwennborg at google.com] On Behalf Of Hans Wennborg
Sent: Wednesday, July 22, 2015 12:11 PM
To: Peyton, Jonathan L
Cc: openmp-commits at cs.uiuc.edu
Subject: Re: [Openmp-commits] [openmp] r242298 - Large Refactor of CMake build system

Hi Jonathan,

On Wed, Jul 15, 2015 at 2:29 PM, Peyton, Jonathan L <jonathan.l.peyton at intel.com> wrote:
> -----Original Message-----
> From: openmp-commits-bounces at cs.uiuc.edu 
> [mailto:openmp-commits-bounces at cs.uiuc.edu] On Behalf Of Jonathan 
> Peyton
> Sent: Wednesday, July 15, 2015 11:06 AM
> To: openmp-commits at cs.uiuc.edu
> Subject: [Openmp-commits] [openmp] r242298 - Large Refactor of CMake 
> build system
>
> Author: jlpeyton
> Date: Wed Jul 15 11:05:30 2015
> New Revision: 242298
>
> URL: http://llvm.org/viewvc/llvm-project?rev=242298&view=rev
> Log:
> Large Refactor of CMake build system

[...]

> +function(libomp_check_linker_flag flag boolean)

I had a look in compiler-rt to see how they check for linker flags, and they use this function:
http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?revision=241224&view=markup#l7
If I understand correctly, that's the same approach described here:
http://www.cmake.org/pipermail/cmake/2011-July/045525.html

That approach seems much simpler. Could it be used here as well?

> +  if(NOT DEFINED "${boolean}")
> +    set(retval TRUE)
> +    set(library_source
> +        "int foo(int a) { return a*a; }")
> +    set(cmake_source
> +        "cmake_minimum_required(VERSION 2.8)
> +         project(foo C)
> +         set(CMAKE_SHARED_LINKER_FLAGS \"${flag}\")
> +         add_library(foo SHARED src_to_link.c)")
> +    set(failed_regexes "[Ee]rror;[Uu]nknown;[Ss]kipping;LINK : warning")
> +    set(base_dir ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/link_flag_check)
> +    file(MAKE_DIRECTORY ${base_dir})
> +    file(MAKE_DIRECTORY ${base_dir}/build)
> +    file(WRITE ${base_dir}/src_to_link.c "${library_source}")
> +    file(WRITE ${base_dir}/CMakeLists.txt "${cmake_source}")
> +
> +    message(STATUS "Performing Test ${boolean}")
> +    try_compile(
> +        try_compile_result
> +        ${base_dir}/build
> +        ${base_dir}
> +        foo
> +        OUTPUT_VARIABLE OUTPUT)
> +
> +    if(try_compile_result)
> +        foreach(regex IN LISTS failed_regexes)
> +            if("${OUTPUT}" MATCHES ${regex})
> +                set(retval FALSE)
> +            endif()
> +        endforeach()
> +    else()
> +        set(retval FALSE)
> +    endif()
> +
> +    if(${retval})
> +        set(${boolean} 1 CACHE INTERNAL "Test ${boolean}")
> +        message(STATUS "Performing Test ${boolean} - Success")
> +        file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
> +          "Performing C Linker Flag test ${boolean} succeeded with the following output:\n"
> +          "${OUTPUT}\n"
> +          "Source file was:\n${library_source}\n")
> +    else()
> +        set(${boolean} "" CACHE INTERNAL "Test ${boolean}")
> +        message(STATUS "Performing Test ${boolean} - Failed")
> +        file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
> +          "Performing C Linker Flag test ${boolean} failed with the following output:\n"
> +          "${OUTPUT}\n"
> +          "Source file was:\n${library_source}\n")
> +    endif()
> +
> +    set(${boolean} ${retval} PARENT_SCOPE)
> +  endif()
> +endfunction()




More information about the Openmp-commits mailing list