原创 从autotool迁移到cmake:编写FindLTDL.cmake FindMath.cmake

参考
https://gitlab.com/graphviz/graphviz/blob/master/cmake/FindLTDL.cmake
https://cmake.org/pipermail/cmake/2010-June/037579.html
https://github.com/nest/nest-simulator/blob/master/cmake/FindLTDL.cmake
https://github.com/fzi-forschungszentrum-informatik/schunk_svh_driver/blob/master/icmaker/CMakeModules/FindLtdl.cmake

Usage


find_package(Math REQUIRED)
find_package(LTDL REQUIRED)
target_link_libraries(guile  Math::Math LTDL::LTDL)

code:
https://github.com/PikachuHy/guile/blob/1.8-cmake/cmake/FindLTDL.cmake
https://github.com/PikachuHy/guile/blob/1.8-cmake/cmake/FindMath.cmake

#[=======================================================================[.rst:
FindLTDL
-----------

Find the LTDL libraries

IMPORTED targets
^^^^^^^^^^^^^^^^

This module defines the following :prop_tgt:`IMPORTED` target:

``LTDL::LTDL``

Result variables
^^^^^^^^^^^^^^^^

This module will set the following variables if found:

``LTDL_INCLUDE_DIRS``
  where to find ltdl.h, etc.
``LTDL_LIBRARIES``
  the libraries to link against to use ltdl.
``LTDL_VERSION``
  version of the ltdl library found
``LTDL_FOUND``
  TRUE if found

#]=======================================================================]

# Look for the necessary header
find_path(LTDL_INCLUDE_DIR NAMES ltdl.h)
mark_as_advanced(LTDL_INCLUDE_DIR)

# Look for the necessary library
find_library(LTDL_LIBRARY NAMES ltdl)
mark_as_advanced(LTDL_LIBRARY)

find_program(LIBTOOL_EXECUTABLE
        NAMES glibtool libtool libtoolize
        )
if ( NOT LIBTOOL_EXECUTABLE STREQUAL "LIBTOOL_EXECUTABLE-NOTFOUND" )
    execute_process(
            COMMAND ${LIBTOOL_EXECUTABLE} --version
            RESULT_VARIABLE RESULT
            OUTPUT_VARIABLE LTDL_VAR_OUTPUT
            OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    if ( RESULT EQUAL 0 )
        string( REGEX REPLACE ".* ([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
                LTDL_VERSION ${LTDL_VAR_OUTPUT} )
    endif ()
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LTDL
        REQUIRED_VARS LTDL_INCLUDE_DIR LTDL_LIBRARY
        VERSION_VAR LTDL_VERSION)

# Create the imported target
if(LTDL_FOUND)
    set(LTDL_INCLUDE_DIRS ${LTDL_INCLUDE_DIR})
    set(LTDL_LIBRARIES ${LTDL_LIBRARY})
    if(NOT TARGET LTDL::LTDL)
        add_library(LTDL::LTDL UNKNOWN IMPORTED)
        set_target_properties(LTDL::LTDL PROPERTIES
                IMPORTED_LOCATION             "${LTDL_LIBRARY}"
                INTERFACE_INCLUDE_DIRECTORIES "${LTDL_INCLUDE_DIR}")
    endif()
endif()
# https://android.googlesource.com/platform/external/eigen/+/master/cmake/FindStandardMathLibrary.cmake
# Look for the necessary library
# Look for the necessary header
find_path(MATH_INCLUDE_DIR NAMES math.h)
mark_as_advanced(MATH_INCLUDE_DIR)

# Look for the necessary library
find_library(MATH_LIBRARY NAMES m libm)
mark_as_advanced(MATH_LIBRARY)
include(CheckCSourceCompiles)
set(find_math_library_test_program
        "#include
int main() { sin(0.0); log(0.0f); }")
set(CMAKE_REQUIRED_FLAGS "")
set(CMAKE_REQUIRED_LIBRARIES "m")
check_c_source_compiles(
        "${find_math_library_test_program}"
        math_library_linked_to_as_m)
if(math_library_linked_to_as_m)
    include(FindPackageHandleStandardArgs)
    find_package_handle_standard_args(Math REQUIRED_VARS MATH_LIBRARY)
endif()

# Create the imported target
if(Math_FOUND)
    set(MATH_LIBRARIES ${MATH_LIBRARY})
    if(NOT TARGET Math::Math)
        add_library(Math::Math UNKNOWN IMPORTED)
        set_target_properties(Math::Math PROPERTIES
                IMPORTED_LOCATION             "${MATH_LIBRARY}")
    endif()
endif()

你可能感兴趣的:(原创 从autotool迁移到cmake:编写FindLTDL.cmake FindMath.cmake)