How to find a library with cmake?

前端 未结 1 541
我寻月下人不归
我寻月下人不归 2021-02-02 16:37

To link an executable with a library that resides in a standard location, one can do the following in a CmakeLists.txt file:

create_executable(generate_mesh gene         


        
1条回答
  •  借酒劲吻你
    2021-02-02 16:52

    You can add different directories to find_library. To use this library call cmake by cmake -DFOO_PREFIX=/some/path ....

    find_library( CPPUNIT_LIBRARY_DEBUG NAMES cppunit cppunit_dll cppunitd cppunitd_dll
                PATHS   ${FOO_PREFIX}/lib
                        /usr/lib
                        /usr/lib64
                        /usr/local/lib
                        /usr/local/lib64
                PATH_SUFFIXES debug )
    
    find_library( CPPUNIT_LIBRARY_RELEASE NAMES cppunit cppunit_dll
                PATHS   ${FOO_PREFIX}/lib
                        /usr/lib
                        /usr/lib64
                        /usr/local/lib
                        /usr/local/lib64
                PATH_SUFFIXES release )
    
    if(CPPUNIT_LIBRARY_DEBUG AND NOT CPPUNIT_LIBRARY_RELEASE)
        set(CPPUNIT_LIBRARY_RELEASE ${CPPUNIT_LIBRARY_DEBUG})
    endif(CPPUNIT_LIBRARY_DEBUG AND NOT CPPUNIT_LIBRARY_RELEASE)
    
    set( CPPUNIT_LIBRARY debug     ${CPPUNIT_LIBRARY_DEBUG}
                        optimized ${CPPUNIT_LIBRARY_RELEASE} )
    
    # ...
    target_link_libraries(foo ${CPPUNIT_LIBRARY})
    

    0 讨论(0)
提交回复
热议问题