[CMake] CHECK_FUNCTION_EXISTS() issue
Crni Gorac
cgorac at gmail.com
Thu Aug 3 05:16:10 EDT 2006
Back to my OpenMP based project, I was able to build following cmake
test regarding is given compiler supporting OpenMP or not. Basic idea
is like in corresponding macro from autoconf macros archive: try to
check is one of OpenMP functions (omp_set_num_threads() here)
available when various flags passed to compiler (OpenMP support is
turned on with a single flag on each compiler supporting OpenMP, it's
only that flags are different for different compilers). So cmake test
would look as follows:
#####
INCLUDE(CheckFunctionExists)
MESSAGE(STATUS "Check for compiler OpenMP support...")
SET(OPENMP_FLAG)
SET(OPENMP_FLAG_FOUND FALSE)
SET(
OPENMP_FLAGS
"-fopenmp" # gcc
"-openmp" # icc
"-mp" # SGI & PGI
"-xopenmp" # Sun
"-omp" # Tru64
"-qsmp=omp" # AIX
)
SET(OPENMP_FUNCTION omp_set_num_threads)
FOREACH(FLAG ${OPENMP_FLAGS})
IF(NOT OPENMP_FLAG_FOUND)
MESSAGE(STATUS "Check if \"${FLAG}\" OpenMP flag working...")
SET(CMAKE_REQUIRED_FLAGS ${FLAG})
CHECK_FUNCTION_EXISTS(${OPENMP_FUNCTION} OPENMP_FUNCTION_FOUND)
IF(OPENMP_FUNCTION_FOUND)
SET(OPENMP_FLAG ${FLAG})
SET(OPENMP_FLAG_FOUND TRUE)
ENDIF(OPENMP_FUNCTION_FOUND)
ENDIF(NOT OPENMP_FLAG_FOUND)
ENDFOREACH(FLAG ${OPENMP_FLAGS})
IF(NOT OPENMP_FLAG_FOUND)
MESSAGE(FATAL_ERROR "Given compiler does not support OpenMP.")
ENDIF(NOT OPENMP_FLAG_FOUND)
MESSAGE(STATUS "Check for compiler OpenMP support: yes")
SET_TARGET_PROPERTIES(
my-executable PROPERTIES
COMPILE_FLAGS ${OPENMP_FLAG}
LINK_FLAGS ${OPENMP_FLAG}
)
#####
However, there is a problem with CHECK_FUNCTION_EXIST() macro, namely
after calling it first time, looks like the result is cached and macro
body is not executed when macro later called again within FOREACH
loop. So my question is - is there a way to employ this macro to
check if given function exists in kind of loop?
Thanks.
More information about the CMake
mailing list