[CMake] Creating a list of link directories from a variable

Salazar De Troya, Miguel salazardetro1 at llnl.gov
Fri Apr 1 13:50:11 EDT 2016


The library that I am using uses libtool for this purpose I think. This is what the Makefile to build the application looks like:

$(notdir $(target)): $(objects)
@echo "Linking "$@"..."
@$(libmesh_LIBTOOL) --tag=CXX $(LIBTOOLFLAGS) --mode=link \
$(libmesh_CXX) $(libmesh_CXXFLAGS) $(objects) -o $@ $(libmesh_LIBS) $(libmesh_LDFLAGS) $(EXTERNAL_FLAGS)

where $(libmesh_LIBTOOL) is the libtool executable, $(libmesh_CXX) is the compiler, etc. $(libmesh_LIBS) is the same I described before, I.e., all the libraries the library I am using uses.  Is there anyway I can use libtool within cmake?

Thanks
Miguel
From: Hendrik Sattler <post at hendrik-sattler.de<mailto:post at hendrik-sattler.de>>
Date: Friday, April 1, 2016 at 10:02 AM
To: Miguel Salazar <salazardetro1 at llnl.gov<mailto:salazardetro1 at llnl.gov>>, "cmake at cmake.org<mailto:cmake at cmake.org>" <cmake at cmake.org<mailto:cmake at cmake.org>>
Subject: Re: [CMake] Creating a list of link directories from a variable

Hi,

yes, exactly. The easiest way to find out is to simply try it. The linker will tell you if some symbols need to be resolved. Static libraries are not linked but only compiled, so the application or library that links to such a static library must do this step.

If that library you use would use some established method like pkg-config to expose those values, it would be much easier (if used correctly by the library author). It can differentiate between those cases.

HS


Am 1. April 2016 18:25:46 MESZ, schrieb "Salazar De Troya, Miguel" <salazardetro1 at llnl.gov<mailto:salazardetro1 at llnl.gov>>:
Hello

Thanks for your response. Is there automatic way to know which libraries my executable will need and which ones it won’t? Why is this the case for only shared libraries? Is it because the linking symbols are already in that shared library and I don’t need to link them again if I’m not using them directly?

Miguel
From: Hendrik Sattler <post at hendrik-sattler.de<mailto:post at hendrik-sattler.de>>
Date: Thursday, March 31, 2016 at 10:27 PM
To: Miguel Salazar <salazardetro1 at llnl.gov<mailto:salazardetro1 at llnl.gov>>, "cmake at cmake.org<mailto:cmake at cmake.org>" <cmake at cmake.org<mailto:cmake at cmake.org>>
Subject: Re: [CMake] Creating a list of link directories from a variable

Hi,

If the library is a shared object, try to NOT use all those libraries. If they are used in the library but are not part of its public API, you most likely don't need to link them. If you have no missing symbols when linking, you can avoid overlinking you program.

If this is a static library, you have a lot more work. For each library without -l, use find_library() and use the library dirs as hints. Do NOT use link_directories().

HS




Am 1. April 2016 00:22:09 MESZ, schrieb "Salazar De Troya, Miguel" <salazardetro1 at llnl.gov<mailto:salazardetro1 at llnl.gov>>:
Hello

I am trying to compile a program with a library that provides a bash script to generate the dependencies, libraries and the link directories for the Makefile. I want to generate a CMakeLists.txt that can handle these dependencies from that library. I have been able to come up with regexp that can extract the information and put it into a variable with the dirs or library names separated by comma, for instance:

INCLUDE_DIRS =

/g/g92/miguel/code/libmesh_2D/include;/usr/include/curl;/usr/include/glpk;/usr/local/tools/vtk-6.1.0/include/vtk-6.1;/g/g92/miguel/petsc-3.6.2/include;/g/g92/miguel/petsc-3.6.2/miguel-opt/include;/usr/local/tools/openmpi-intel-1.8.4/include/openmpi/opal/mca/hwloc/hwloc191/hwloc/include;/usr/local/tools/openmpi-intel-1.8.4/include/openmpi/opal/mca/event/libevent2021/libevent;/usr/local/tools/openmpi-intel-1.8.4/include/openmpi/opal/mca/event/libevent2021/libevent/include;/usr/local/tools/openmpi-intel-1.8.4/include;/usr/local/tools/openmpi-intel-1.8.4/include/openmpi;/usr/local/tools/boost-mpi-1.55.0//include


LIBS =

-lcurl;-lhdf5;-lglpk;-lvtkIOCore-6.1;-lvtkCommonCore-6.1;-lvtkCommonDataModel-6.1;-lvtkFiltersCore-6.1;-lvtkIOXML-6.1;-lvtkImagingCore-6.1;-lvtkIOImage-6.1;-lvtkImagingMath-6.1;-lz;-lpetsc;-lcmumps;-ldmumps;-lsmumps;-lzmumps;-lmumps_common;-lpord;-lscalapack;-lHYPRE;-lml;-llapack;-lblas;-lparmetis;-lmetis;-lX11;-lhwloc;-lssl;-lcrypto;-lmpi_usempif08;-lmpi_usempi_ignore_tkr;-lmpi_mpifh;-lifport;-lifcore;-lm;-lmpi;-limf;-lsvml;-lirng;-lipgo;-ldecimal;-lcilkrts;-lstdc++;-lgcc_s;-lirc;-lpthread;-lirc_s;-ldl;-lmesh_opt


LIB_DIRS =

/usr/lib;/lib;/usr/lib64;/usr/local/tools/vtk-6.1.0/lib;/g/g92/miguel/petsc-3.6.2/miguel-opt/lib;/usr/local/tools/openmpi-intel-1.8.4/lib;/usr/local/tools/ic-14.0.174/composer_xe_2013_sp1.3.174/compiler/lib/intel64;/usr/lib/gcc/x86_64-redhat-linux/4.4.7;/g/g92/miguel/code/libmesh_2D/lib


These are variables in my environment that I use in CMake with $ENV{VAR}. How can I use this information for the commands:

include_directories($ENV{INCLUDE_DIRS})

link_directories($ENV{LIB_DIRS})

target_link_libraries($ENV{LIBS}) ?


It seems that cmake can digest the include directories and the target_link_libraries (because they appear correctly in the compilation), but not the link_directories. Why? Also, I’ve read that it is more correct to use find_library() instead. How would I iterate over the LIBS? Can I use a single LIB_DIRS (with all the information above) in the PATHS argument of find_library()


Thanks

Miguel

--

Powered by http://secure-web.cisco.com/1SkTeDpqcSTqs7V0Q2yjUdQEsQ1huaYLleRl_DSB40mZrJmSB4Lr6utBlMnP2n8teBgjMf-JqbxyEzxRwI33xdCPfZ4V-R2DL7hRPikFqd9-Rs0WFTInnFgBOVb385LKZzSj7s6rnXOZg-2XG27MJ2-q9sNDHuOdRClebWLFsHqVgj0HGuWMrWGh1kE2S9-TyKuTes7ceD6P0h7C_OsCM_EQXdmhkDGCqyKLK6MRTupY6_HJ1roZBy2Y98SiMF_6LXWUyvKR_raD6crErzRofBLqtBN4vsNeqHBC88J3gYM2BgpkiDnNxonEQy0GonMqIPBKPG9ORW1sEj7-QXajnhYY6cXvu-1TI6aW8FSgTSzZxgdA9zvzoea-DB1

 ANk22B/http%3A%2F%2Fhttp://secure-web.cisco.com/1_G8E11DjkWSEZF1X0bDL0XQ6no1ns19oUE5HkwkJW_OM4jsX4q3ZXYR7UTOIqaoAjTR6ytCzZdu4WPPoUXG8puGesXmBd5HDxLeW3uHxWnWMJ9ykzRvQnp_V5huyOikMeviO6mRfs1PmY_g_AACDuNomxbRIczMESxWgsufu_Eg7w3TyPfXfUblqfme1zjQ9MtLTmJCkfRDWNVpUPVneOKOL8KQR1qbchCVHJp_4WJtyCaJnPclfRtqX6PPovdxb589UUDv2aAWC2KvE0JAPZX82sLJoWTy3VncHP0HfE92zxCeA2hj3lJENb55aIFfoa-FPOU8jPfh3XCptObzjorZs7oTkdxcyCtHP-kCaqSX9y0WHdZaZar7B9TUlk9R7/http%3A%2F%2Fwww.kitware.com<http://secure-web.cisco.com/1SkTeDpqcSTqs7V0Q2yjUdQEsQ1huaYLleRl_DSB40mZrJmSB4Lr6utBlMnP2n8teBgjMf-JqbxyEzxRwI33xdCPfZ4V-R2DL7hRPikFqd9-Rs0WFTInnFgBOVb385LKZzSj7s6rnXOZg-2XG27MJ2-q9sNDHuOdRClebWLFsHqVgj0HGuWMrWGh1kE2S9-TyKuTes7ceD6P0h7C_OsCM_EQXdmhkDGCqyKLK6MRTupY6_HJ1roZBy2Y98SiMF_6LXWUyvKR_raD6crErzRofBLqtBN4vsNeqHBC88J3gYM2BgpkiDnNxonEQy0GonMqIPBKPG9ORW1sEj7-QXajnhYY6cXvu-1TI6aW8FSgTSzZxgdA9zvzoea-DB1ANk22B/http%3A%2F%2Fwww.kitware.com>

Please keep messages on-topic and check the CMake FAQ at: http://secure-web.cisco.com/1lI1URY1zHkv6ht2fcVR_WzgnMfOLLtDRhnEZC_L-hBbr0MyYmRVnFbqyae-mLLDa3LRUy3jnmo1S5MImcABjqQXSzuJodnbjzHo7RWpGnMXp14ItTo608Rfa6V21U8szRc88xGOLc_ISZArzbPE2DD3soPvoiUq67hjSNnqbZKvR68LAhF7HNSupJM3L7uVCJAZyue59hncjNCKO7LW5b66INxi4gLED1GTeYz6PUStkNqnZftpECSWslK8EhtW_4COv5-9JASDmn59YbaUl4x38LuUWF9Ezhi7cldke-4fSCwVK8S364ZLxukX51JH_gTzM0pDYj_GB4683VCQ7U3MMDtQeDuU72OIst1qrSHXJWLPBn-CVHrnJPHcHM

 P8V/http%3A%2F%2Fhttp://secure-web.cisco.com/1Bkvr0G6CjmhxjbPWZjz1f9tENDvZUFASRjcU_7Q88EnpJI2XsrOFU0c5olP28krrrDUTl-hCDKmdwgP32nHMUj1foppf3czHNXklLqkXZyhEKrV-fGy-G_36c_9Y7k1WucIAXCwsYtqxJbenF4adv1-3u9LXCPKp6mpA8A_9gFGBPOZTuBWuBWyDEGDQnZi0Avju9U3NEf_FiQOymwbZNkAoDAiFgGLMAe24US9Rn4R3iYoryMbv2jhP8_to2tDnH3s8MDcOP6U0cvZIrxMI9TgLThqj0PMYaqOnJ3DjDWzmVtBjA7M5875h2gSuoxxJD9yOIyGkMDycS_MYMeeBHdqGhBSNY__IDKjLPLuzV0vlOGd4ae_32k_qphC01h_W/http%3A%2F%2Fwww.cmake.org%2FWiki%2FCMake_FAQ<http://secure-web.cisco.com/1lI1URY1zHkv6ht2fcVR_WzgnMfOLLtDRhnEZC_L-hBbr0MyYmRVnFbqyae-mLLDa3LRUy3jnmo1S5MImcABjqQXSzuJodnbjzHo7RWpGnMXp14ItTo608Rfa6V21U8szRc88xGOLc_ISZArzbPE2DD3soPvoiUq67hjSNnqbZKvR68LAhF7HNSupJM3L7uVCJAZyue59hncjNCKO7LW5b66INxi4gLED1GTeYz6PUStkNqnZftpECSWslK8EhtW_4COv5-9JASDmn59YbaUl4x38LuUWF9Ezhi7cldke-4fSCwVK8S364ZLxukX51JH_gTzM0pDYj_GB4683VCQ7U3MMDtQeDuU72OIst1qrSHXJWLPBn-CVHrnJPHcHMP8V/http%3A%2F%2Fwww.cmake.org%2FW
%20
%20iki%2FCMake_FAQ>

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://secure-web.cisco.com/1Qz3n7R5O8bw0CSRD2aEtjVRHTskP3JYupeWWW89VpWzPvN7hkb5gIWI5pJk_cTWsp8XnmQ77NFfNITi4eyz67Z65_0ZB12TnLcwPpXs20eW5MOvDECIVdKk99ysgQfzZ7UZJ9ie38Z2H0GucEIPt6GJY3PEkUAx9rlMp_-34E46uA3rSm5rJVjx2rW7FyudguAM-DSbOihI2VjG4lVa7cKjjyFUAfUHhIiiEYLhTSnyROdgTIorEIF4tzi-U18BTlI9uN1U_YuVSgTh81nQ

 f1k_AnTZRFIZxa7G8AKN_bclh1YpdXx0E-Kq06ZD1MYiTLN6o8GsSzuoUT7qAJL-FKjb_G8xgO6dBZ4ohg4_8poOqOxDdIKkTBP-nhXVkwmSe/http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Fsupport.html<http://secure-web.cisco.com/1Qz3n7R5O8bw0CSRD2aEtjVRHTskP3JYupeWWW89VpWzPvN7hkb5gIWI5pJk_cTWsp8XnmQ77NFfNITi4eyz67Z65_0ZB12TnLcwPpXs20eW5MOvDECIVdKk99ysgQfzZ7UZJ9ie38Z2H0GucEIPt6GJY3PEkUAx9rlMp_-34E46uA3rSm5rJVjx2rW7FyudguAM-DSbOihI2VjG4lVa7cKjjyFUAfUHhIiiEYLhTSnyROdgTIorEIF4tzi-U18BTlI9uN1U_YuVSgTh81nQf1k_AnTZRFIZxa7G8AKN_bclh1YpdXx0E-Kq06ZD1
%20
%20MYiTLN6o8GsSzuoUT7qAJL-FKjb_G8xgO6dBZ4ohg4_8poOqOxDdIKkTBP-nhXVkwmSe/http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Fsupport.html>
CMake Consulting: http://secure-web.cisco.com/1eWcD28ESMZFlJWUPWhkBq8KXSsdmSnpldn60uZfqFn_QMxL_1NzQMlujGfPNER7Mq9ZcH7fXFeoMPaPml0UrkV6cwY39IlPti6XF9_god65BZdUy-EULaoOU5XGEBDKEBMm2_5t20nIs6IyqaV25zOWyhVDrQEiGHa-ulvydlMGVXUZqNps1JycByTxAh6J0B8G3TAkN92MfVFbCV8vU24urymXAk1HaFgrULBn0Y-YqrnY_Vj8Tq5xS47rYuelebxpJT0BKhUxvKf-hbRboTJGRQOjgJ-C_Iu


 A5NPVvSfL-XhCDs7nzUE_E0OXyb_OJpm4Nh-b2EEC2P_tIh8opKKPQf_uC8GYwTPHj0_A4ot8h9sXj3D60fI6iw4Kbht_F/http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Fconsulting.html<http://secure-web.cisco.com/1eWcD28ESMZFlJWUPWhkBq8KXSsdmSnpldn60uZfqFn_QMxL_1NzQMlujGfPNER7Mq9ZcH7fXFeoMPaPml0UrkV6cwY39IlPti6XF9_god65BZdUy-EULaoOU5XGEBDKEBMm2_5t20nIs6IyqaV25zOWyhVDrQEiGHa-ulvydlMGVXUZqNps1JycByTxAh6J0B8G3TAkN92MfVFbCV8vU24urymXAk1HaFgrULBn0Y-YqrnY_Vj8Tq5xS47rYuelebxpJT0BKhUxvKf-hbRboTJGRQOjgJ-C_IuA5NPVvSfL-XhCDs7nzUE_E0OXyb_OJpm4Nh-b2EEC2P_tIh8opKKPQf_uC8GYwTPHj0_A4ot8h9sXj3D60fI6iw4Kbht_F/http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Fconsulting.html>
CMake Training Courses: http://secure-web.cisco.com/1Ws_Ir6UA-in34UAfzdEg4RJTGWrYp_XmGZCsUXHKnIGN43SCP64aWDni4VaNbznT489ME15yGcFiFkArpBjv6i2swZfUKM5487B2Fd0lgCDYsFtsz0GbsoVrQJmBEUGWEBUgx86fS3bn9AcvuwEXkLzQeNd-42LXR_tvlpH_bCApLEOZXMntGWBBdPvWduEtCwz3QwfNNQNiPZetW2Xkoy3q8GQDSpOZZx5gBiK17P5Kdnzvbai5Xi1YHfVfsq9QlQm365nZogVk6Tt0Vumf8BSudcoJWz5ofCP3l5sU_-


 Xks9mVhEEtHSE-qGJB1cPmquqwNP6V4LwUOkqHcYq3ZXQPF7diap-5YBfGo4eiX0Zgk6rlFdluAjtjr7wMFN7j/http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Ftraining.html<http://secure-web.cisco.com/1Ws_Ir6UA-in34UAfzdEg4RJTGWrYp_XmGZCsUXHKnIGN43SCP64aWDni4VaNbznT489ME15yGcFiFkArpBjv6i2swZfUKM5487B2Fd0lgCDYsFtsz0GbsoVrQJmBEUGWEBUgx86fS3bn9AcvuwEXkLzQeNd-42LXR_tvlpH_bCApLEOZXMntGWBBdPvWduEtCwz3QwfNNQNiPZetW2Xkoy3q8GQDSpOZZx5gBiK17P5Kdnzvbai5Xi1YHfVfsq9QlQm365nZogVk6Tt0Vumf8BSudcoJWz5ofCP3l5sU_-Xks9mVhEEtHSE-qGJB1cPmquqwNP6V4LwUOkqHcYq3ZXQPF7diap-5YBfGo4eiX0Zgk6rlFdluAjtjr7wMFN7j/http%3A%2F%2Fcmake.org%2Fcmake%2Fhelp%2Ftraining.html>

Visit other Kitware open-source projects at http://secure-web.cisco.com/1UFZr5nImcHwKfRdWsAKclNUoA9AaFYDCCASJmolI9zgJewqKij0jcFTmy6i8U1dJzggBo8KGXVnbZh7kdWcbS1hhwJikHJYfe1vEyHF6TQOOFOg8QTiF2wM4X0yiRMO4e7RAq1sx7Qsr_aLGtIgJDg9goaII8XN4MZhv2Vgta6FKYt5je-raaStpUC4iWhyoBVi63RTPMWW0fLWPKQk3f9SQK3V-p4bfFcR9Hn_aVzlI7ZaI_B5ii2NC6x2lFtAIKn1l2Uf_epptM9cCf7ZkbHl7uK-lGyPB5w7VavIVMNce4THKWnh7zwepJtS8-ddfTcE0yxEMx4lF-sp6DXCbD8FNROPz95o5pzHnw2YZQBFVA2pHT-NOnoT80NsX7JgX/http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html

Follow this link to


 subscribe/unsubscribe:
http://secure-web.cisco.com/1Jl3yAWBiPi-_Ug16DWjk5rAGVXSETXlixkdzBCZkWgB2g4RhLE2dcqHp-_dO8Wyu1_TMU3phTHeU3FfkLHBKHMd3V-qWcBkn_VrYymLV_VbH3YvRxJxPvL_3id4qazZm5B3EtDj-yJQ6bFwzqhXmhDwrqNW8sJB09iUFIF0dVxgCk3LIbTFf97iQuknZ4a5bEy0lZ6QSLE03Kyxvni93Hq0OiQhE9_aLDShnVunar9h0P7GNSGzaOT1Pi43FjhM346RUiauCsjMila62UkjlypuJR9hFaIfy7kzXiV3fA-Ej9Ac6-471fNd0BCY-AP2Ji6YoItgM04GKTBXJC1iYWMx6TDRypcnuJIhsCq324N0W9yEvpeO0Rgh4q0pgwbC3/http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fcmake

<http://secure-web.cisco.com/1Jl3yAWBiPi-_Ug16DWjk5rAGVXSETXlixkdzBCZkWgB2g4RhLE2dcqHp-_dO8Wyu1_TMU3phTHeU3FfkLHBKHMd3V-qWcBkn_VrYymLV_VbH3YvRxJxPvL_3id4qazZm5B3EtDj-yJQ6bFwzqhXmhDwrqNW8sJB09iUFIF0dVxgCk3LIbTFf97iQuknZ4a5bEy0lZ6QSLE03Kyxvni93Hq0OiQhE9_aLDShnVunar9h0P7GNSGzaOT1Pi43FjhM346RUiauCsjMila62UkjlypuJR9hFaIfy7kzXiV3fA-Ej9Ac6-471fNd0BCY-AP2Ji6YoItgM04GKTBXJC1iYWMx6TDRypcnuJIhsCq324N0W9yEvpeO0Rgh4q0pgwbC3/http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fcmake>
<http://secure-web.cisco.com/1Jl3yAWBiPi-_Ug16DWjk5rAGVXSETXlixkdzBCZkWgB2g4RhLE2dcqHp-_dO8Wyu1_TMU3phTHeU3FfkLHBKHMd3V-qWcBkn_VrYymLV_VbH3YvRxJxPvL_3id4qazZm5B3EtDj-yJQ6bFwzqhXmhDwrqNW8sJB09iUFIF0dVxgCk3LIbTFf97iQuknZ4a5bEy0lZ6QSLE03Kyxvni93Hq0OiQhE9_aLDShnVunar9h0P7GNSGzaOT1Pi43FjhM346RUiauCsjMila62UkjlypuJR9hFaIfy7kzXiV3fA-Ej9Ac6-471fNd0BCY-AP2Ji6YoItgM04GKTBXJC1iYWMx6TDRypcnuJIhsCq324N0W9yEvpeO0Rgh4q0pgwbC3/http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fcmake>
<http://secure-web.cisco.com/1Jl3yAWBiPi-_Ug16DWjk5rAGVXSETXlixkdzBCZkWgB2g4RhLE2dcqHp-_dO8Wyu1_TMU3phTHeU3FfkLHBKHMd3V-qWcBkn_VrYymLV_VbH3YvRxJxPvL_3id4qazZm5B3EtDj-yJQ6bFwzqhXmhDwrqNW8sJB09iUFIF0dVxgCk3LIbTFf97iQuknZ4a5bEy0lZ6QSLE03Kyxvni93Hq0OiQhE9_aLDShnVunar9h0P7GNSGzaOT1Pi43FjhM346RUiauCsjMila62UkjlypuJR9hFaIfy7kzXiV3fA-Ej9Ac6-471fNd0BCY-AP2Ji6YoItgM04GKTBXJC1iYWMx6TDRypcnuJIhsCq324N0W9yEvpeO0Rgh4q0pgwbC3/http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fcmake>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160401/daeb25ce/attachment-0001.html>


More information about the CMake mailing list