diff options
33 files changed, 513 insertions, 166 deletions
diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst index 310ad11..f50fcb6 100644 --- a/Help/command/try_compile.rst +++ b/Help/command/try_compile.rst @@ -33,6 +33,7 @@ Try Compiling Source Files try_compile(RESULT_VAR <bindir> <srcfile|SOURCES srcfile...> [CMAKE_FLAGS <flags>...] [COMPILE_DEFINITIONS <defs>...] + [LINK_OPTIONS <options>...] [LINK_LIBRARIES <libs>...] [OUTPUT_VARIABLE <var>] [COPY_FILE <fileName> [COPY_FILE_ERROR <var>]] @@ -55,6 +56,7 @@ the source(s) as an executable that looks something like this: include_directories(${INCLUDE_DIRECTORIES}) link_directories(${LINK_DIRECTORIES}) add_executable(cmTryCompileExec <srcfile>...) + target_link_options(cmTryCompileExec PRIVATE <LINK_OPTIONS from caller>) target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES}) The options are: @@ -67,7 +69,7 @@ The options are: are used. ``COMPILE_DEFINITIONS <defs>...`` - Specify ``-Ddefinition`` arguments to pass to ``add_definitions`` + Specify ``-Ddefinition`` arguments to pass to :command:`add_definitions` in the generated test project. ``COPY_FILE <fileName>`` @@ -85,6 +87,11 @@ The options are: If this option is specified, any ``-DLINK_LIBRARIES=...`` value given to the ``CMAKE_FLAGS`` option will be ignored. +``LINK_OPTIONS <options>...`` + Specify link step options to pass to :command:`target_link_options` or + to :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property in the generated + project, depending of the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable. + ``OUTPUT_VARIABLE <var>`` Store the output from the build process the given variable. diff --git a/Help/command/try_run.rst b/Help/command/try_run.rst index dfa0bf9..137402f 100644 --- a/Help/command/try_run.rst +++ b/Help/command/try_run.rst @@ -15,6 +15,7 @@ Try Compiling and Running Source Files try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR bindir srcfile [CMAKE_FLAGS <flags>...] [COMPILE_DEFINITIONS <defs>...] + [LINK_OPTIONS <options>...] [LINK_LIBRARIES <libs>...] [COMPILE_OUTPUT_VARIABLE <var>] [RUN_OUTPUT_VARIABLE <var>] @@ -38,7 +39,7 @@ The options are: are used. ``COMPILE_DEFINITIONS <defs>...`` - Specify ``-Ddefinition`` arguments to pass to ``add_definitions`` + Specify ``-Ddefinition`` arguments to pass to :command:`add_definitions` in the generated test project. ``COMPILE_OUTPUT_VARIABLE <var>`` @@ -52,6 +53,10 @@ The options are: If this option is specified, any ``-DLINK_LIBRARIES=...`` value given to the ``CMAKE_FLAGS`` option will be ignored. +``LINK_OPTIONS <options>...`` + Specify link step options to pass to :command:`target_link_options` in the + generated project. + ``OUTPUT_VARIABLE <var>`` Report the compile build output and the output from running the executable in the given variable. This option exists for legacy reasons. Prefer diff --git a/Help/release/dev/check-functions-LINK_OPTIONS.rst b/Help/release/dev/check-functions-LINK_OPTIONS.rst new file mode 100644 index 0000000..a6bfed2 --- /dev/null +++ b/Help/release/dev/check-functions-LINK_OPTIONS.rst @@ -0,0 +1,5 @@ +check-functions-LINK_OPTIONS +---------------------------- + +* The family of modules to check capabilities (like + :module:`CheckCSourceCompiles`) gain capability to manage ``LINK_OPTIONS``. diff --git a/Help/release/dev/try_compile-LINK_OPTIONS.rst b/Help/release/dev/try_compile-LINK_OPTIONS.rst new file mode 100644 index 0000000..1db485b --- /dev/null +++ b/Help/release/dev/try_compile-LINK_OPTIONS.rst @@ -0,0 +1,5 @@ +try_compile-LINK_OPTIONS +------------------------ + +* The commands :command:`try_compile` and :command:`try_run` gain new + option ``LINK_OPTIONS``. diff --git a/Modules/CMakePushCheckState.cmake b/Modules/CMakePushCheckState.cmake index 7628d1a..f6bfc12 100644 --- a/Modules/CMakePushCheckState.cmake +++ b/Modules/CMakePushCheckState.cmake @@ -7,26 +7,27 @@ CMakePushCheckState -This module defines three macros: CMAKE_PUSH_CHECK_STATE() -CMAKE_POP_CHECK_STATE() and CMAKE_RESET_CHECK_STATE() These macros can +This module defines three macros: ``CMAKE_PUSH_CHECK_STATE()`` +``CMAKE_POP_CHECK_STATE()`` and ``CMAKE_RESET_CHECK_STATE()`` These macros can be used to save, restore and reset (i.e., clear contents) the state of -the variables CMAKE_REQUIRED_FLAGS, CMAKE_REQUIRED_DEFINITIONS, -CMAKE_REQUIRED_LIBRARIES, CMAKE_REQUIRED_INCLUDES and CMAKE_EXTRA_INCLUDE_FILES -used by the various Check-files coming with CMake, like e.g. -check_function_exists() etc. The variable contents are pushed on a -stack, pushing multiple times is supported. This is useful e.g. when -executing such tests in a Find-module, where they have to be set, but -after the Find-module has been executed they should have the same -value as they had before. - -CMAKE_PUSH_CHECK_STATE() macro receives optional argument RESET. -Whether it's specified, CMAKE_PUSH_CHECK_STATE() will set all -CMAKE_REQUIRED_* variables to empty values, same as -CMAKE_RESET_CHECK_STATE() call will do. +the variables ``CMAKE_REQUIRED_FLAGS``, ``CMAKE_REQUIRED_DEFINITIONS``, +``CMAKE_REQUIRED_LINK_OPTIONS``, ``CMAKE_REQUIRED_LIBRARIES``, +``CMAKE_REQUIRED_INCLUDES`` and ``CMAKE_EXTRA_INCLUDE_FILES`` used by the +various Check-files coming with CMake, like e.g. ``check_function_exists()`` +etc. +The variable contents are pushed on a stack, pushing multiple times is +supported. This is useful e.g. when executing such tests in a Find-module, +where they have to be set, but after the Find-module has been executed they +should have the same value as they had before. + +``CMAKE_PUSH_CHECK_STATE()`` macro receives optional argument ``RESET``. +Whether it's specified, ``CMAKE_PUSH_CHECK_STATE()`` will set all +``CMAKE_REQUIRED_*`` variables to empty values, same as +``CMAKE_RESET_CHECK_STATE()`` call will do. Usage: -:: +.. code-block:: cmake cmake_push_check_state(RESET) set(CMAKE_REQUIRED_DEFINITIONS -DSOME_MORE_DEF) @@ -42,6 +43,7 @@ macro(CMAKE_RESET_CHECK_STATE) set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_REQUIRED_INCLUDES) set(CMAKE_REQUIRED_DEFINITIONS) + set(CMAKE_REQUIRED_LINK_OPTIONS) set(CMAKE_REQUIRED_LIBRARIES) set(CMAKE_REQUIRED_FLAGS) set(CMAKE_REQUIRED_QUIET) @@ -56,12 +58,13 @@ macro(CMAKE_PUSH_CHECK_STATE) math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}+1") - set(_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_EXTRA_INCLUDE_FILES}) - set(_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_INCLUDES}) - set(_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_DEFINITIONS}) - set(_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LIBRARIES}) - set(_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_FLAGS}) - set(_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_QUIET}) + set(_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_EXTRA_INCLUDE_FILES}) + set(_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_INCLUDES}) + set(_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_DEFINITIONS}) + set(_CMAKE_REQUIRED_LINK_OPTIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LINK_OPTIONS}) + set(_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LIBRARIES}) + set(_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_FLAGS}) + set(_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_QUIET}) if (${ARGC} GREATER 0 AND "${ARGV0}" STREQUAL "RESET") cmake_reset_check_state() @@ -74,12 +77,13 @@ macro(CMAKE_POP_CHECK_STATE) # don't pop more than we pushed if("${_CMAKE_PUSH_CHECK_STATE_COUNTER}" GREATER "0") - set(CMAKE_EXTRA_INCLUDE_FILES ${_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_INCLUDES ${_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_DEFINITIONS ${_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_FLAGS ${_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_QUIET ${_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) + set(CMAKE_EXTRA_INCLUDE_FILES ${_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) + set(CMAKE_REQUIRED_INCLUDES ${_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) + set(CMAKE_REQUIRED_DEFINITIONS ${_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) + set(CMAKE_REQUIRED_LINK_OPTIONS ${_CMAKE_REQUIRED_LINK_OPTIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) + set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) + set(CMAKE_REQUIRED_FLAGS ${_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) + set(CMAKE_REQUIRED_QUIET ${_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}-1") endif() diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake index 5b0b70e..77ba0cc 100644 --- a/Modules/CheckCSourceCompiles.cmake +++ b/Modules/CheckCSourceCompiles.cmake @@ -43,6 +43,10 @@ Check if given C source compiles and links into an executable. ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` directory property will be ignored. + ``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_compile` for further details). + ``CMAKE_REQUIRED_LIBRARIES`` A :ref:`;-list <CMake Language Lists>` of libraries to add to the link command. These can be the name of system libraries or they can be @@ -78,6 +82,12 @@ macro(CHECK_C_SOURCE_COMPILES SOURCE VAR) endforeach() set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -100,6 +110,7 @@ macro(CHECK_C_SOURCE_COMPILES SOURCE VAR) ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS} ${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}" diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake index e682b29..eba70f2 100644 --- a/Modules/CheckCSourceRuns.cmake +++ b/Modules/CheckCSourceRuns.cmake @@ -42,6 +42,10 @@ subsequently be run. ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` directory property will be ignored. + ``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_run` for further details). + ``CMAKE_REQUIRED_LIBRARIES`` A :ref:`;-list <CMake Language Lists>` of libraries to add to the link command. These can be the name of system libraries or they can be @@ -66,6 +70,12 @@ macro(CHECK_C_SOURCE_RUNS SOURCE VAR) if(NOT DEFINED "${VAR}") set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -88,6 +98,7 @@ macro(CHECK_C_SOURCE_RUNS SOURCE VAR) ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS} ${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake index f7ec8eb..cc457a5 100644 --- a/Modules/CheckCXXSourceCompiles.cmake +++ b/Modules/CheckCXXSourceCompiles.cmake @@ -43,6 +43,10 @@ Check if given C++ source compiles and links into an executable. ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` directory property will be ignored. + ``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_compile` for further details). + ``CMAKE_REQUIRED_LIBRARIES`` A :ref:`;-list <CMake Language Lists>` of libraries to add to the link command. These can be the name of system libraries or they can be @@ -79,6 +83,12 @@ macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR) set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -101,6 +111,7 @@ macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR) ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS} ${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}" diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake index bdc2291..7db976b 100644 --- a/Modules/CheckCXXSourceRuns.cmake +++ b/Modules/CheckCXXSourceRuns.cmake @@ -42,6 +42,10 @@ subsequently be run. ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` directory property will be ignored. + ``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_run` for further details). + ``CMAKE_REQUIRED_LIBRARIES`` A :ref:`;-list <CMake Language Lists>` of libraries to add to the link command. These can be the name of system libraries or they can be @@ -66,6 +70,12 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR) if(NOT DEFINED "${VAR}") set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -88,6 +98,7 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR) ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS} ${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} diff --git a/Modules/CheckCXXSymbolExists.cmake b/Modules/CheckCXXSymbolExists.cmake index d067001..970e301 100644 --- a/Modules/CheckCXXSymbolExists.cmake +++ b/Modules/CheckCXXSymbolExists.cmake @@ -7,35 +7,42 @@ CheckCXXSymbolExists Check if a symbol exists as a function, variable, or macro in C++ -.. code-block:: cmake +.. command:: CHECK_CXX_SYMBOL_EXISTS - CHECK_CXX_SYMBOL_EXISTS(<symbol> <files> <variable>) + .. code-block:: cmake -Check that the ``<symbol>`` is available after including given header -``<files>`` and store the result in a ``<variable>``. Specify the list of -files in one argument as a semicolon-separated list. -CHECK_CXX_SYMBOL_EXISTS() can be used to check in C++ files, as -opposed to CHECK_SYMBOL_EXISTS(), which works only for C. + CHECK_CXX_SYMBOL_EXISTS(<symbol> <files> <variable>) -If the header files define the symbol as a macro it is considered -available and assumed to work. If the header files declare the symbol -as a function or variable then the symbol must also be available for -linking. If the symbol is a type or enum value it will not be -recognized (consider using CheckTypeSize or CheckCSourceCompiles). + Check that the ``<symbol>`` is available after including given header + ``<files>`` and store the result in a ``<variable>``. Specify the list of + files in one argument as a semicolon-separated list. + ``CHECK_CXX_SYMBOL_EXISTS()`` can be used to check in C++ files, as + opposed to ``CHECK_SYMBOL_EXISTS()``, which works only for ``C``. + + If the header files define the symbol as a macro it is considered + available and assumed to work. If the header files declare the symbol + as a function or variable then the symbol must also be available for + linking. If the symbol is a type or enum value it will not be + recognized (consider using :module:`CheckTypeSize` + or :module:`CheckCSourceCompiles`). The following variables may be set before calling this macro to modify the way the check is run: ``CMAKE_REQUIRED_FLAGS`` - string of compile command line flags + string of compile command line flags. ``CMAKE_REQUIRED_DEFINITIONS`` - list of macros to define (-DFOO=bar) + a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar). ``CMAKE_REQUIRED_INCLUDES`` - list of include directories + a :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. +``CMAKE_REQUIRED_LINK_OPTIONS`` + a :ref:`;-list <CMake Language Lists>` of options to add to the link command. ``CMAKE_REQUIRED_LIBRARIES`` - list of libraries to link + a :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. See policy :policy:`CMP0075`. ``CMAKE_REQUIRED_QUIET`` - execute quietly without messages + execute quietly without messages. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckFortranFunctionExists.cmake b/Modules/CheckFortranFunctionExists.cmake index dc371aa..7ca205a 100644 --- a/Modules/CheckFortranFunctionExists.cmake +++ b/Modules/CheckFortranFunctionExists.cmake @@ -5,24 +5,33 @@ CheckFortranFunctionExists -------------------------- -:command:`Macro <macro>` which checks if a Fortran function exists. +Check if a Fortran function exists. -.. code-block:: cmake +.. command:: CHECK_FORTRAN_FUNCTION_EXISTS - CHECK_FORTRAN_FUNCTION_EXISTS(<function> <result>) + .. code-block:: cmake -where + CHECK_FORTRAN_FUNCTION_EXISTS(<function> <result>) -``<function>`` - the name of the Fortran function -``<result>`` - variable to store the result; will be created as an internal cache variable. + where + + ``<function>`` + the name of the Fortran function + ``<result>`` + variable to store the result; will be created as an internal cache variable. The following variables may be set before calling this macro to modify the way the check is run: +``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_compile` for further details). + ``CMAKE_REQUIRED_LIBRARIES`` - list of libraries to link + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for + further details). #]=======================================================================] include_guard(GLOBAL) @@ -30,6 +39,12 @@ include_guard(GLOBAL) macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE) if(NOT DEFINED ${VARIABLE}) message(STATUS "Looking for Fortran ${FUNCTION}") + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -48,6 +63,7 @@ macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE) try_compile(${VARIABLE} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f + ${CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS} ${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES} OUTPUT_VARIABLE OUTPUT ) diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake index 977b7b4..b3e83dd 100644 --- a/Modules/CheckFortranSourceCompiles.cmake +++ b/Modules/CheckFortranSourceCompiles.cmake @@ -49,6 +49,10 @@ Check if given Fortran source compiles and links into an executable. ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` directory property will be ignored. + ``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_compile` for further details). + ``CMAKE_REQUIRED_LIBRARIES`` A :ref:`;-list <CMake Language Lists>` of libraries to add to the link command. These can be the name of system libraries or they can be @@ -88,6 +92,12 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) endif() set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -110,6 +120,7 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS} ${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}" diff --git a/Modules/CheckFunctionExists.cmake b/Modules/CheckFunctionExists.cmake index cbec739..c39144f 100644 --- a/Modules/CheckFunctionExists.cmake +++ b/Modules/CheckFunctionExists.cmake @@ -7,27 +7,33 @@ CheckFunctionExists Check if a C function can be linked -.. code-block:: cmake +.. command:: check_function_exists - check_function_exists(<function> <variable>) + .. code-block:: cmake -Checks that the ``<function>`` is provided by libraries on the system and store -the result in a ``<variable>``, which will be created as an internal -cache variable. + check_function_exists(<function> <variable>) + + Checks that the ``<function>`` is provided by libraries on the system and store + the result in a ``<variable>``, which will be created as an internal + cache variable. The following variables may be set before calling this macro to modify the way the check is run: ``CMAKE_REQUIRED_FLAGS`` - string of compile command line flags + string of compile command line flags. ``CMAKE_REQUIRED_DEFINITIONS`` - list of macros to define (-DFOO=bar) + a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar). ``CMAKE_REQUIRED_INCLUDES`` - list of include directories + a :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. +``CMAKE_REQUIRED_LINK_OPTIONS`` + a :ref:`;-list <CMake Language Lists>` of options to add to the link command. ``CMAKE_REQUIRED_LIBRARIES`` - list of libraries to link + a :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. See policy :policy:`CMP0075`. ``CMAKE_REQUIRED_QUIET`` - execute quietly without messages + execute quietly without messages. .. note:: @@ -53,6 +59,12 @@ macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE) if(NOT CMAKE_REQUIRED_QUIET) message(STATUS "Looking for ${FUNCTION}") endif() + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -79,6 +91,7 @@ macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE) ${CMAKE_BINARY_DIR} ${_cfe_source} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS} ${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} "${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}" diff --git a/Modules/CheckIncludeFile.cmake b/Modules/CheckIncludeFile.cmake index 87dac4f..d7b9481 100644 --- a/Modules/CheckIncludeFile.cmake +++ b/Modules/CheckIncludeFile.cmake @@ -9,7 +9,7 @@ Provides a macro to check if a header file can be included in ``C``. .. command:: CHECK_INCLUDE_FILE - :: + .. code-block:: cmake CHECK_INCLUDE_FILE(<include> <variable> [<flags>]) @@ -22,15 +22,19 @@ The following variables may be set before calling this macro to modify the way the check is run: ``CMAKE_REQUIRED_FLAGS`` - string of compile command line flags + string of compile command line flags. ``CMAKE_REQUIRED_DEFINITIONS`` - list of macros to define (-DFOO=bar) + a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar). ``CMAKE_REQUIRED_INCLUDES`` - list of include directories + a :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. +``CMAKE_REQUIRED_LINK_OPTIONS`` + a :ref:`;-list <CMake Language Lists>` of options to add to the link command. ``CMAKE_REQUIRED_LIBRARIES`` - A list of libraries to link. See policy :policy:`CMP0075`. + a :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. See policy :policy:`CMP0075`. ``CMAKE_REQUIRED_QUIET`` - execute quietly without messages + execute quietly without messages. See the :module:`CheckIncludeFiles` module to check for multiple headers at once. See the :module:`CheckIncludeFileCXX` module to check for headers @@ -58,6 +62,11 @@ macro(CHECK_INCLUDE_FILE INCLUDE VARIABLE) string(APPEND CMAKE_C_FLAGS " ${ARGV2}") endif() + set(_CIF_LINK_OPTIONS) + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(_CIF_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + endif() + set(_CIF_LINK_LIBRARIES "") if(CMAKE_REQUIRED_LIBRARIES) cmake_policy(GET CMP0075 _CIF_CMP0075 @@ -85,11 +94,13 @@ macro(CHECK_INCLUDE_FILE INCLUDE VARIABLE) ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${_CIF_LINK_OPTIONS} ${_CIF_LINK_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}" OUTPUT_VARIABLE OUTPUT) + unset(_CIF_LINK_OPTIONS) unset(_CIF_LINK_LIBRARIES) if(${ARGC} EQUAL 3) diff --git a/Modules/CheckIncludeFileCXX.cmake b/Modules/CheckIncludeFileCXX.cmake index 42b5eaf..de5a83b 100644 --- a/Modules/CheckIncludeFileCXX.cmake +++ b/Modules/CheckIncludeFileCXX.cmake @@ -9,7 +9,7 @@ Provides a macro to check if a header file can be included in ``CXX``. .. command:: CHECK_INCLUDE_FILE_CXX - :: + .. code-block:: cmake CHECK_INCLUDE_FILE_CXX(<include> <variable> [<flags>]) @@ -22,15 +22,19 @@ The following variables may be set before calling this macro to modify the way the check is run: ``CMAKE_REQUIRED_FLAGS`` - string of compile command line flags + string of compile command line flags. ``CMAKE_REQUIRED_DEFINITIONS`` - list of macros to define (-DFOO=bar) + a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar). ``CMAKE_REQUIRED_INCLUDES`` - list of include directories + a :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. +``CMAKE_REQUIRED_LINK_OPTIONS`` + a :ref:`;-list <CMake Language Lists>` of options to add to the link command. ``CMAKE_REQUIRED_LIBRARIES`` - A list of libraries to link. See policy :policy:`CMP0075`. + a :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. See policy :policy:`CMP0075`. ``CMAKE_REQUIRED_QUIET`` - execute quietly without messages + execute quietly without messages. See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFiles` to check for one or more ``C`` headers. @@ -57,6 +61,11 @@ macro(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE) string(APPEND CMAKE_CXX_FLAGS " ${ARGV2}") endif() + set(_CIF_LINK_OPTIONS) + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(_CIF_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + endif() + set(_CIF_LINK_LIBRARIES "") if(CMAKE_REQUIRED_LIBRARIES) cmake_policy(GET CMP0075 _CIF_CMP0075 @@ -84,11 +93,13 @@ macro(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE) ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${_CIF_LINK_OPTIONS} ${_CIF_LINK_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} "${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}" OUTPUT_VARIABLE OUTPUT) + unset(_CIF_LINK_OPTIONS) unset(_CIF_LINK_LIBRARIES) if(${ARGC} EQUAL 3) diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake index b303260..f52ab55 100644 --- a/Modules/CheckIncludeFiles.cmake +++ b/Modules/CheckIncludeFiles.cmake @@ -10,7 +10,7 @@ be included together. .. command:: CHECK_INCLUDE_FILES - :: + .. code-block:: cmake CHECK_INCLUDE_FILES("<includes>" <variable> [LANGUAGE <language>]) @@ -19,24 +19,28 @@ be included together. entry named ``<variable>``. Specify the ``<includes>`` argument as a :ref:`;-list <CMake Language Lists>` of header file names. -If LANGUAGE is set, the specified compiler will be used to perform the -check. Acceptable values are ``C`` and ``CXX``. If not set, the C compiler -will be used if enabled. If the C compiler is not enabled, the C++ -compiler will be used if enabled. + If ``LANGUAGE`` is set, the specified compiler will be used to perform the + check. Acceptable values are ``C`` and ``CXX``. If not set, the C compiler + will be used if enabled. If the C compiler is not enabled, the C++ + compiler will be used if enabled. The following variables may be set before calling this macro to modify the way the check is run: ``CMAKE_REQUIRED_FLAGS`` - string of compile command line flags + string of compile command line flags. ``CMAKE_REQUIRED_DEFINITIONS`` - list of macros to define (-DFOO=bar) + a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar). ``CMAKE_REQUIRED_INCLUDES`` - list of include directories + a :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. +``CMAKE_REQUIRED_LINK_OPTIONS`` + a :ref:`;-list <CMake Language Lists>` of options to add to the link command. ``CMAKE_REQUIRED_LIBRARIES`` - A list of libraries to link. See policy :policy:`CMP0075`. + a :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. See policy :policy:`CMP0075`. ``CMAKE_REQUIRED_QUIET`` - execute quietly without messages + execute quietly without messages. See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFileCXX` to check for a single header file in ``C`` or ``CXX`` languages. @@ -98,6 +102,11 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE) set(_description "include file ${_INCLUDE}") endif() + set(_CIF_LINK_OPTIONS) + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(_CIF_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + endif() + set(_CIF_LINK_LIBRARIES "") if(CMAKE_REQUIRED_LIBRARIES) cmake_policy(GET CMP0075 _CIF_CMP0075 @@ -128,11 +137,13 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE) ${CMAKE_BINARY_DIR} ${src} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${_CIF_LINK_OPTIONS} ${_CIF_LINK_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS} "${CHECK_INCLUDE_FILES_INCLUDE_DIRS}" OUTPUT_VARIABLE OUTPUT) + unset(_CIF_LINK_OPTIONS) unset(_CIF_LINK_LIBRARIES) if(${VARIABLE}) if(NOT CMAKE_REQUIRED_QUIET) diff --git a/Modules/CheckLibraryExists.cmake b/Modules/CheckLibraryExists.cmake index 428a6b0..6504df5 100644 --- a/Modules/CheckLibraryExists.cmake +++ b/Modules/CheckLibraryExists.cmake @@ -7,15 +7,19 @@ CheckLibraryExists Check if the function exists. -CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE) +.. command:: CHECK_LIBRARY_EXISTS -:: + .. code-block:: cmake + + CHECK_LIBRARY_EXISTS(LIBRARY FUNCTION LOCATION VARIABLE) - LIBRARY - the name of the library you are looking for - FUNCTION - the name of the function - LOCATION - location where the library should be found - VARIABLE - variable to store the result - Will be created as an internal cache variable. + :: + + LIBRARY - the name of the library you are looking for + FUNCTION - the name of the function + LOCATION - location where the library should be found + VARIABLE - variable to store the result + Will be created as an internal cache variable. @@ -26,6 +30,7 @@ the way the check is run: CMAKE_REQUIRED_FLAGS = string of compile command line flags CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) + CMAKE_REQUIRED_LINK_OPTIONS = list of options to pass to link command CMAKE_REQUIRED_LIBRARIES = list of libraries to link CMAKE_REQUIRED_QUIET = execute quietly without messages #]=======================================================================] @@ -39,6 +44,11 @@ macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) if(NOT CMAKE_REQUIRED_QUIET) message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}") endif() + set(CHECK_LIBRARY_EXISTS_LINK_OPTIONS) + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_LIBRARY_EXISTS_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + endif() set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY}) if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_LIBRARY_EXISTS_LIBRARIES @@ -58,6 +68,7 @@ macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) ${CMAKE_BINARY_DIR} ${_cle_source} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_LIBRARY_EXISTS_LINK_OPTIONS} LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION} diff --git a/Modules/CheckPrototypeDefinition.cmake b/Modules/CheckPrototypeDefinition.cmake index c90b766..a7b020c 100644 --- a/Modules/CheckPrototypeDefinition.cmake +++ b/Modules/CheckPrototypeDefinition.cmake @@ -7,26 +7,30 @@ CheckPrototypeDefinition Check if the prototype we expect is correct. -check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE) +.. command:: check_prototype_definition -:: + .. code-block:: cmake - FUNCTION - The name of the function (used to check if prototype exists) - PROTOTYPE- The prototype to check. - RETURN - The return value of the function. - HEADER - The header files required. - VARIABLE - The variable to store the result. - Will be created as an internal cache variable. + check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE) -Example: + :: -:: + FUNCTION - The name of the function (used to check if prototype exists) + PROTOTYPE- The prototype to check. + RETURN - The return value of the function. + HEADER - The header files required. + VARIABLE - The variable to store the result. + Will be created as an internal cache variable. + + Example: - check_prototype_definition(getpwent_r - "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)" - "NULL" - "unistd.h;pwd.h" - SOLARIS_GETPWENT_R) + .. code-block:: cmake + + check_prototype_definition(getpwent_r + "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)" + "NULL" + "unistd.h;pwd.h" + SOLARIS_GETPWENT_R) The following variables may be set before calling this function to modify the way the check is run: @@ -36,6 +40,7 @@ the way the check is run: CMAKE_REQUIRED_FLAGS = string of compile command line flags CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) CMAKE_REQUIRED_INCLUDES = list of include directories + CMAKE_REQUIRED_LINK_OPTIONS = list of options to pass to link command CMAKE_REQUIRED_LIBRARIES = list of libraries to link CMAKE_REQUIRED_QUIET = execute quietly without messages #]=======================================================================] @@ -52,6 +57,12 @@ function(check_prototype_definition _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIAB set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n") set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS}) + if (CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_PROTOTYPE_DEFINITION_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_PROTOTYPE_DEFINITION_LINK_OPTIONS) + endif() if (CMAKE_REQUIRED_LIBRARIES) set(CHECK_PROTOTYPE_DEFINITION_LIBS LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -83,6 +94,7 @@ function(check_prototype_definition _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIAB ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_PROTOTYPE_DEFINITION_LINK_OPTIONS} ${CHECK_PROTOTYPE_DEFINITION_LIBS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS} "${CMAKE_SYMBOL_EXISTS_INCLUDES}" diff --git a/Modules/CheckStructHasMember.cmake b/Modules/CheckStructHasMember.cmake index e7c337c..7fef857 100644 --- a/Modules/CheckStructHasMember.cmake +++ b/Modules/CheckStructHasMember.cmake @@ -7,18 +7,20 @@ CheckStructHasMember Check if the given struct or class has the specified member variable -:: +.. command:: CHECK_STRUCT_HAS_MEMBER - CHECK_STRUCT_HAS_MEMBER(<struct> <member> <header> <variable> - [LANGUAGE <language>]) + .. code-block:: cmake -:: + CHECK_STRUCT_HAS_MEMBER(<struct> <member> <header> <variable> + [LANGUAGE <language>]) - <struct> - the name of the struct or class you are interested in - <member> - the member which existence you want to check - <header> - the header(s) where the prototype should be declared - <variable> - variable to store the result - <language> - the compiler to use (C or CXX) + :: + + <struct> - the name of the struct or class you are interested in + <member> - the member which existence you want to check + <header> - the header(s) where the prototype should be declared + <variable> - variable to store the result + <language> - the compiler to use (C or CXX) @@ -30,13 +32,17 @@ the way the check is run: CMAKE_REQUIRED_FLAGS = string of compile command line flags CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) CMAKE_REQUIRED_INCLUDES = list of include directories + CMAKE_REQUIRED_LINK_OPTIONS = list of options to pass to link command CMAKE_REQUIRED_LIBRARIES = list of libraries to link CMAKE_REQUIRED_QUIET = execute quietly without messages +Example: + +.. code-block:: cmake -Example: CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h -HAVE_TIMEVAL_TV_SEC LANGUAGE C) + CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h + HAVE_TIMEVAL_TV_SEC LANGUAGE C) #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake index 3483121..b9ef808 100644 --- a/Modules/CheckSymbolExists.cmake +++ b/Modules/CheckSymbolExists.cmake @@ -10,7 +10,7 @@ or macro in ``C``. .. command:: check_symbol_exists - :: + .. code-block:: cmake check_symbol_exists(<symbol> <files> <variable>) @@ -32,15 +32,19 @@ The following variables may be set before calling this macro to modify the way the check is run: ``CMAKE_REQUIRED_FLAGS`` - string of compile command line flags + string of compile command line flags. ``CMAKE_REQUIRED_DEFINITIONS`` - list of macros to define (-DFOO=bar) + a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar). ``CMAKE_REQUIRED_INCLUDES`` - list of include directories + a :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. +``CMAKE_REQUIRED_LINK_OPTIONS`` + a :ref:`;-list <CMake Language Lists>` of options to add to the link command. ``CMAKE_REQUIRED_LIBRARIES`` - list of libraries to link + a :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. See policy :policy:`CMP0075`. ``CMAKE_REQUIRED_QUIET`` - execute quietly without messages + execute quietly without messages. #]=======================================================================] include_guard(GLOBAL) @@ -62,6 +66,12 @@ macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE) if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}") set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n") set(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS}) + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_SYMBOL_EXISTS_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_SYMBOL_EXISTS_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_SYMBOL_EXISTS_LIBS LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -91,6 +101,7 @@ macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE) ${CMAKE_BINARY_DIR} "${SOURCEFILE}" COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_SYMBOL_EXISTS_LINK_OPTIONS} ${CHECK_SYMBOL_EXISTS_LIBS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS} diff --git a/Modules/CheckTypeSize.cmake b/Modules/CheckTypeSize.cmake index 2c53df9..3727373 100644 --- a/Modules/CheckTypeSize.cmake +++ b/Modules/CheckTypeSize.cmake @@ -7,50 +7,52 @@ CheckTypeSize Check sizeof a type -:: +.. command:: CHECK_TYPE_SIZE - CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY] - [LANGUAGE <language>]) + .. code-block:: cmake -Check if the type exists and determine its size. On return, -"HAVE_${VARIABLE}" holds the existence of the type, and "${VARIABLE}" -holds one of the following: + CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY] + [LANGUAGE <language>]) -:: + Check if the type exists and determine its size. On return, + ``HAVE_${VARIABLE}`` holds the existence of the type, and ``${VARIABLE}`` + holds one of the following: - <size> = type has non-zero size <size> - "0" = type has arch-dependent size (see below) - "" = type does not exist + :: -Both ``HAVE_${VARIABLE}`` and ``${VARIABLE}`` will be created as internal -cache variables. + <size> = type has non-zero size <size> + "0" = type has arch-dependent size (see below) + "" = type does not exist -Furthermore, the variable "${VARIABLE}_CODE" holds C preprocessor code -to define the macro "${VARIABLE}" to the size of the type, or leave -the macro undefined if the type does not exist. + Both ``HAVE_${VARIABLE}`` and ``${VARIABLE}`` will be created as internal + cache variables. -The variable "${VARIABLE}" may be "0" when CMAKE_OSX_ARCHITECTURES has -multiple architectures for building OS X universal binaries. This -indicates that the type size varies across architectures. In this -case "${VARIABLE}_CODE" contains C preprocessor tests mapping from -each architecture macro to the corresponding type size. The list of -architecture macros is stored in "${VARIABLE}_KEYS", and the value for -each key is stored in "${VARIABLE}-${KEY}". + Furthermore, the variable ``${VARIABLE}_CODE`` holds C preprocessor code + to define the macro ``${VARIABLE}`` to the size of the type, or leave + the macro undefined if the type does not exist. -If the BUILTIN_TYPES_ONLY option is not given, the macro checks for -headers <sys/types.h>, <stdint.h>, and <stddef.h>, and saves results -in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H. The type size -check automatically includes the available headers, thus supporting -checks of types defined in the headers. + The variable ``${VARIABLE}`` may be ``0`` when + :variable:`CMAKE_OSX_ARCHITECTURES` has multiple architectures for building + OS X universal binaries. This indicates that the type size varies across + architectures. In this case ``${VARIABLE}_CODE`` contains C preprocessor + tests mapping from each architecture macro to the corresponding type size. + The list of architecture macros is stored in ``${VARIABLE}_KEYS``, and the + value for each key is stored in ``${VARIABLE}-${KEY}``. -If LANGUAGE is set, the specified compiler will be used to perform the -check. Acceptable values are C and CXX + If the ``BUILTIN_TYPES_ONLY`` option is not given, the macro checks for + headers ``<sys/types.h>``, ``<stdint.h>``, and ``<stddef.h>``, and saves + results in ``HAVE_SYS_TYPES_H``, ``HAVE_STDINT_H``, and ``HAVE_STDDEF_H``. + The type size check automatically includes the available headers, thus + supporting checks of types defined in the headers. + + If ``LANGUAGE`` is set, the specified compiler will be used to perform the + check. Acceptable values are ``C`` and ``CXX``. Despite the name of the macro you may use it to check the size of more complex expressions, too. To check e.g. for the size of a struct member you can do something like this: -:: +.. code-block:: cmake check_type_size("((struct something*)0)->member" SIZEOF_MEMBER) @@ -64,6 +66,7 @@ the way the check is run: CMAKE_REQUIRED_FLAGS = string of compile command line flags CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) CMAKE_REQUIRED_INCLUDES = list of include directories + CMAKE_REQUIRED_LINK_OPTIONS = list of options to pass to link command CMAKE_REQUIRED_LIBRARIES = list of libraries to link CMAKE_REQUIRED_QUIET = execute quietly without messages CMAKE_EXTRA_INCLUDE_FILES = list of extra headers to include @@ -116,6 +119,7 @@ function(__check_type_size_impl type var map builtin language) configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY) try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}" diff --git a/Modules/CheckVariableExists.cmake b/Modules/CheckVariableExists.cmake index f30165e..f4953a3 100644 --- a/Modules/CheckVariableExists.cmake +++ b/Modules/CheckVariableExists.cmake @@ -7,20 +7,21 @@ CheckVariableExists Check if the variable exists. -:: +.. command:: CHECK_VARIABLE_EXISTS - CHECK_VARIABLE_EXISTS(VAR VARIABLE) + .. code-block:: cmake + CHECK_VARIABLE_EXISTS(VAR VARIABLE) -:: + :: - VAR - the name of the variable - VARIABLE - variable to store the result - Will be created as an internal cache variable. + VAR - the name of the variable + VARIABLE - variable to store the result + Will be created as an internal cache variable. -This macro is only for C variables. + This macro is only for ``C`` variables. The following variables may be set before calling this macro to modify the way the check is run: @@ -29,6 +30,7 @@ the way the check is run: CMAKE_REQUIRED_FLAGS = string of compile command line flags CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) + CMAKE_REQUIRED_LINK_OPTIONS = list of options to pass to link command CMAKE_REQUIRED_LIBRARIES = list of libraries to link CMAKE_REQUIRED_QUIET = execute quietly without messages #]=======================================================================] @@ -42,6 +44,12 @@ macro(CHECK_VARIABLE_EXISTS VAR VARIABLE) if(NOT CMAKE_REQUIRED_QUIET) message(STATUS "Looking for ${VAR}") endif() + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_VARIABLE_EXISTS_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_VARIABLE_EXISTS_ADD_LINK_OPTIONS) + endif() if(CMAKE_REQUIRED_LIBRARIES) set(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) @@ -52,6 +60,7 @@ macro(CHECK_VARIABLE_EXISTS VAR VARIABLE) ${CMAKE_BINARY_DIR} ${CMAKE_ROOT}/Modules/CheckVariableExists.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_VARIABLE_EXISTS_ADD_LINK_OPTIONS} ${CHECK_VARIABLE_EXISTS_ADD_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_VARIABLE_DEFINITIONS} OUTPUT_VARIABLE OUTPUT) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index f6ec606..541ae76 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -121,6 +121,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, std::string cxxExtensions; std::string cudaExtensions; std::vector<std::string> targets; + std::vector<std::string> linkOptions; std::string libsToLink = " "; bool useOldLinkLibs = true; char targetNameBuf[64]; @@ -144,6 +145,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, DoingNone, DoingCMakeFlags, DoingCompileDefinitions, + DoingLinkOptions, DoingLinkLibraries, DoingOutputVariable, DoingCopyFile, @@ -165,6 +167,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, doing = DoingCMakeFlags; } else if (argv[i] == "COMPILE_DEFINITIONS") { doing = DoingCompileDefinitions; + } else if (argv[i] == "LINK_OPTIONS") { + doing = DoingLinkOptions; } else if (argv[i] == "LINK_LIBRARIES") { doing = DoingLinkLibraries; useOldLinkLibs = false; @@ -208,6 +212,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, cmakeFlags.push_back(argv[i]); } else if (doing == DoingCompileDefinitions) { compileDefs.push_back(argv[i]); + } else if (doing == DoingLinkOptions) { + linkOptions.push_back(argv[i]); } else if (doing == DoingLinkLibraries) { libsToLink += "\"" + cmSystemTools::TrimWhitespace(argv[i]) + "\" "; if (cmTarget* tgt = this->Makefile->FindTargetToUse(argv[i])) { @@ -814,6 +820,23 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, } } + if (!linkOptions.empty()) { + std::vector<std::string> options; + options.reserve(linkOptions.size()); + for (const auto& option : linkOptions) { + options.emplace_back(cmOutputConverter::EscapeForCMake(option)); + } + + if (targetType == cmStateEnums::STATIC_LIBRARY) { + fprintf(fout, + "set_property(TARGET %s PROPERTY STATIC_LIBRARY_OPTIONS %s)\n", + targetName.c_str(), cmJoin(options, " ").c_str()); + } else { + fprintf(fout, "target_link_options(%s PRIVATE %s)\n", + targetName.c_str(), cmJoin(options, " ").c_str()); + } + } + if (useOldLinkLibs) { fprintf(fout, "target_link_libraries(%s ${LINK_LIBRARIES})\n", targetName.c_str()); diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 9396138..fafbd24 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -45,7 +45,8 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, if (argv[i] == "ARGS") { ++i; while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" && - argv[i] != "CMAKE_FLAGS" && argv[i] != "LINK_LIBRARIES") { + argv[i] != "CMAKE_FLAGS" && argv[i] != "LINK_OPTIONS" && + argv[i] != "LINK_LIBRARIES") { runArgs += " "; runArgs += argv[i]; ++i; diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index a4d829b..b044757 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -275,6 +275,7 @@ function(add_RunCMake_test_try_compile) endif() endif() foreach(var + CMAKE_SYSTEM_NAME CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION CMAKE_C_STANDARD_DEFAULT @@ -291,7 +292,8 @@ function(add_RunCMake_test_try_compile) endfunction() add_RunCMake_test_try_compile() -add_RunCMake_test(try_run) +add_RunCMake_test(try_run -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} + -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}) add_RunCMake_test(set) add_RunCMake_test(variable_watch) add_RunCMake_test(while) diff --git a/Tests/RunCMake/try_compile/LinkOptions.cmake b/Tests/RunCMake/try_compile/LinkOptions.cmake new file mode 100644 index 0000000..9b246c4 --- /dev/null +++ b/Tests/RunCMake/try_compile/LinkOptions.cmake @@ -0,0 +1,38 @@ + +enable_language(C) + +cmake_policy(SET CMP0054 NEW) + +set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}") +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if (RunCMake_C_COMPILER_ID STREQUAL "MSVC") + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (undef_flag /INCLUDE:_func) + else() + set (undef_flag /INCLUDE:func) + endif() + else() + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (undef_flag -u _func) + else() + set (undef_flag -u func) + endif() + endif() +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set (undef_flag -u _func) +else() + set (undef_flag -u func) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib.c + COPY_FILE "${lib_name}") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/main.c + OUTPUT_VARIABLE out + LINK_OPTIONS ${undef_flag} "${lib_name}") + +if(NOT result) + message(FATAL_ERROR "try_compile(... LINK_OPTIONS ...) failed:\n${out}") +endif() diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index 6a1bc64..77fb7a0 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -25,6 +25,13 @@ run_cmake(TargetTypeExe) run_cmake(TargetTypeInvalid) run_cmake(TargetTypeStatic) +if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND + CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|Clang|AppleClang)$") + set (RunCMake_TEST_OPTIONS -DRunCMake_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}) + run_cmake(LinkOptions) + unset (RunCMake_TEST_OPTIONS) +endif() + if(CMAKE_C_STANDARD_DEFAULT) run_cmake(CStandard) elseif(DEFINED CMAKE_C_STANDARD_DEFAULT) diff --git a/Tests/RunCMake/try_compile/lib.c b/Tests/RunCMake/try_compile/lib.c new file mode 100644 index 0000000..b00c576 --- /dev/null +++ b/Tests/RunCMake/try_compile/lib.c @@ -0,0 +1,4 @@ + +void func() +{ +} diff --git a/Tests/RunCMake/try_compile/main.c b/Tests/RunCMake/try_compile/main.c new file mode 100644 index 0000000..2128ead --- /dev/null +++ b/Tests/RunCMake/try_compile/main.c @@ -0,0 +1,8 @@ +extern void func(); + +int main(void) +{ + func(); + + return 0; +} diff --git a/Tests/RunCMake/try_run/LinkOptions.cmake b/Tests/RunCMake/try_run/LinkOptions.cmake new file mode 100644 index 0000000..17af2f7 --- /dev/null +++ b/Tests/RunCMake/try_run/LinkOptions.cmake @@ -0,0 +1,42 @@ + +enable_language(C) + +cmake_policy(SET CMP0054 NEW) + +set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}") +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if (RunCMake_C_COMPILER_ID STREQUAL "MSVC") + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (undef_flag /INCLUDE:_func) + else() + set (undef_flag /INCLUDE:func) + endif() + else() + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (undef_flag -u _func) + else() + set (undef_flag -u func) + endif() + endif() +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set (undef_flag -u _func) +else() + set (undef_flag -u func) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib.c + COPY_FILE "${lib_name}") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) +try_run(run_result compile_result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/main.c + COMPILE_OUTPUT_VARIABLE compile_out + RUN_OUTPUT_VARIABLE run_out + LINK_OPTIONS ${undef_flag} "${lib_name}") + +if(NOT compile_result) + message(FATAL_ERROR "try_run(... LINK_OPTIONS ...) compilation failed:\n${compile_out}") +endif() +if(run_result STREQUAL "FAILED_TO_RUN") + message(FATAL_ERROR "try_run(... LINK_OPTIONS ...) execution failed:\n${run_out}") +endif() diff --git a/Tests/RunCMake/try_run/RunCMakeTest.cmake b/Tests/RunCMake/try_run/RunCMakeTest.cmake index 1ec9a55..3689562 100644 --- a/Tests/RunCMake/try_run/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_run/RunCMakeTest.cmake @@ -1,3 +1,10 @@ include(RunCMake) run_cmake(BadLinkLibraries) + +if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND + CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|Clang|AppleClang)$") + set (RunCMake_TEST_OPTIONS -DRunCMake_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}) + run_cmake(LinkOptions) + unset (RunCMake_TEST_OPTIONS) +endif() diff --git a/Tests/RunCMake/try_run/lib.c b/Tests/RunCMake/try_run/lib.c new file mode 100644 index 0000000..b00c576 --- /dev/null +++ b/Tests/RunCMake/try_run/lib.c @@ -0,0 +1,4 @@ + +void func() +{ +} diff --git a/Tests/RunCMake/try_run/main.c b/Tests/RunCMake/try_run/main.c new file mode 100644 index 0000000..2128ead --- /dev/null +++ b/Tests/RunCMake/try_run/main.c @@ -0,0 +1,8 @@ +extern void func(); + +int main(void) +{ + func(); + + return 0; +} |