Re: [CMake] how to detect architecture ?
Got it, thanks. I'll do that even if Windows is not an OS I target (I guess tests will not run on Windows - run bash script like ./test.sh in which I redirect outputs with > and other stuffs the unix way). - Mail original - > De: "Konstantin Tokarev" <annu...@yandex.ru> > À: "Chuck Atkins" <chuck.atk...@kitware.com>, "Franck Houssen" > <franck.hous...@inria.fr> > Cc: "CMake Mail List" <cmake@cmake.org> > Envoyé: Vendredi 19 Janvier 2018 19:26:48 > Objet: Re: [CMake] how to detect architecture ? > > > > 19.01.2018, 21:22, "Chuck Atkins" <chuck.atk...@kitware.com>: > > Hi Franck, > > > > I'd suggest going a little more robust by using both > > CMAKE_SHARED_LIBRARY_PREFIX and CMAKE_SHARED_LIBRARY_SUFFIX to generate a > > function at configure time to resolve the correct filename. > > > > For example, util.h.in: > > > > #ifndef _UTIL_H_ > > #define _UTIL_H_ > > > > #include > > > > static inline > > void get_library_filename(char* filename, const char* libname) > > { > > sprintf(filename, > > "@CMAKE_SHARED_LIBRARY_PREFIX@%s@CMAKE_SHARED_LIBRARY_SUFFIX@", > > libname); > > } > > > > #endif /* _UTIL_H_ */ > > > > Then your CMakeLists.txt: > > > > configure_file( > > ${CMAKE_CURRENT_SOURCE_DIR}/util.h.in > > ${CMAKE_CURRENT_BINARY_DIR}/util.h > > @ONLY > > ) > > add_executable(foo main.c ${CMAKE_CURRENT_BINARY_DIR}/util.h) > > target_include_directories(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) > > > > And finally main.c: > > > > #include > > #include > > > > int main(int argc, char **argv) > > { > > char filename[256]; > > > > get_library_filename(filename, "foo"); > > > > printf("Library foo uses file %s\n", filename); > > > > return 0; > > } > > > > This will give you "libfoo.so" on Linux, "libfoo.dylib" on Apple, and > > "foo.dll" on Windows. > > Note that Windows DLLs may also happen to have to lib prefix (e.g. CMake adds > them > by default when building projects with MinGW). > > > > > -- > > Chuck Atkins > > Staff R Engineer, Scientific Computing > > Kitware, Inc. > > > > On Tue, Jan 9, 2018 at 10:04 AM, Franck Houssen <franck.hous...@inria.fr> > > wrote: > >> Thanks ! > >> > >> - Mail original - > >>> De: "Konstantin Tokarev" <annu...@yandex.ru> > >>> À: "Franck Houssen" <franck.hous...@inria.fr>, "CMake Mail List" > >>> <cmake@cmake.org> > >>> Envoyé: Mardi 9 Janvier 2018 16:00:55 > >>> Objet: Re: [CMake] how to detect architecture ? > >>> > >>> > >>> > >>> 09.01.2018, 17:58, "Franck Houssen" <franck.hous...@inria.fr>: > >>> > Is there a way to detect architecture ? > >>> > > >>> > Seems there is nothing simple since these old threads : > >>> > https://stackoverflow.com/questions/11944060/how-to-detect-target-architecture-using-cmake/12024211#12024211 > >>> > https://stackoverflow.com/questions/16796629/cmake-create-architecture-aware-makefile > >>> > > >>> > Is there a solution now ? > >>> > > >>> > My need is quite simple: I have an executable who needs dlopen. To test > >>> > it, > >>> > I planned to write a bash script that would have done "./exe > >>> > /path/to/lib.so" on linux (debian, ...) OR "./exe /path/to/lib.dylib" > >>> > on > >>> > osx. To replace correctly so/dylib in the bash script I need to know > >>> > the > >>> > architecture. Any idea how to do this ? > >>> > >>> ${CMAKE_SHARED_LIBRARY_SUFFIX} > >>> > >> > >> Oh man ! Didn't know this one : exactly what I was looking for > >> > >>> > Franck > >>> > ,-- > >>> > > >>> > Powered by www.kitware.com > >>> > > >>> > Please keep messages on-topic and check the CMake FAQ at: > >>> > http://www.cmake.org/Wiki/CMake_FAQ > >>> > > >>> > Kitware offers various services to support the CMake community. For > >>> > more > >>> > information on each offering, please visit
Re: [CMake] how to detect architecture ?
19.01.2018, 21:22, "Chuck Atkins" <chuck.atk...@kitware.com>: > Hi Franck, > > I'd suggest going a little more robust by using both > CMAKE_SHARED_LIBRARY_PREFIX and CMAKE_SHARED_LIBRARY_SUFFIX to generate a > function at configure time to resolve the correct filename. > > For example, util.h.in: > > #ifndef _UTIL_H_ > #define _UTIL_H_ > > #include > > static inline > void get_library_filename(char* filename, const char* libname) > { > sprintf(filename, > "@CMAKE_SHARED_LIBRARY_PREFIX@%s@CMAKE_SHARED_LIBRARY_SUFFIX@", libname); > } > > #endif /* _UTIL_H_ */ > > Then your CMakeLists.txt: > > configure_file( > ${CMAKE_CURRENT_SOURCE_DIR}/util.h.in > ${CMAKE_CURRENT_BINARY_DIR}/util.h > @ONLY > ) > add_executable(foo main.c ${CMAKE_CURRENT_BINARY_DIR}/util.h) > target_include_directories(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) > > And finally main.c: > > #include > #include > > int main(int argc, char **argv) > { > char filename[256]; > > get_library_filename(filename, "foo"); > > printf("Library foo uses file %s\n", filename); > > return 0; > } > > This will give you "libfoo.so" on Linux, "libfoo.dylib" on Apple, and > "foo.dll" on Windows. Note that Windows DLLs may also happen to have to lib prefix (e.g. CMake adds them by default when building projects with MinGW). > > -- > Chuck Atkins > Staff R Engineer, Scientific Computing > Kitware, Inc. > > On Tue, Jan 9, 2018 at 10:04 AM, Franck Houssen <franck.hous...@inria.fr> > wrote: >> Thanks ! >> >> - Mail original - >>> De: "Konstantin Tokarev" <annu...@yandex.ru> >>> À: "Franck Houssen" <franck.hous...@inria.fr>, "CMake Mail List" >>> <cmake@cmake.org> >>> Envoyé: Mardi 9 Janvier 2018 16:00:55 >>> Objet: Re: [CMake] how to detect architecture ? >>> >>> >>> >>> 09.01.2018, 17:58, "Franck Houssen" <franck.hous...@inria.fr>: >>> > Is there a way to detect architecture ? >>> > >>> > Seems there is nothing simple since these old threads : >>> > https://stackoverflow.com/questions/11944060/how-to-detect-target-architecture-using-cmake/12024211#12024211 >>> > https://stackoverflow.com/questions/16796629/cmake-create-architecture-aware-makefile >>> > >>> > Is there a solution now ? >>> > >>> > My need is quite simple: I have an executable who needs dlopen. To test >>> > it, >>> > I planned to write a bash script that would have done "./exe >>> > /path/to/lib.so" on linux (debian, ...) OR "./exe /path/to/lib.dylib" on >>> > osx. To replace correctly so/dylib in the bash script I need to know the >>> > architecture. Any idea how to do this ? >>> >>> ${CMAKE_SHARED_LIBRARY_SUFFIX} >>> >> >> Oh man ! Didn't know this one : exactly what I was looking for >> >>> > Franck >>> > ,-- >>> > >>> > Powered by www.kitware.com >>> > >>> > Please keep messages on-topic and check the CMake FAQ at: >>> > http://www.cmake.org/Wiki/CMake_FAQ >>> > >>> > Kitware offers various services to support the CMake community. For more >>> > information on each offering, please visit: >>> > >>> > CMake Support: http://cmake.org/cmake/help/support.html >>> > CMake Consulting: http://cmake.org/cmake/help/consulting.html >>> > CMake Training Courses: http://cmake.org/cmake/help/training.html >>> > >>> > Visit other Kitware open-source projects at >>> > http://www.kitware.com/opensource/opensource.html >>> > >>> > Follow this link to subscribe/unsubscribe: >>> > https://cmake.org/mailman/listinfo/cmake >>> >>> >>> -- >>> Regards, >>> Konstantin >>> >> -- >> >> Powered by www.kitware.com >> >> Please keep messages on-topic and check the CMake FAQ at: >> http://www.cmake.org/Wiki/CMake_FAQ >> >> Kitware offers various services to support the CMake community. For more >> information on each offering, please visit: >> >> CMake Support: http://cmake.org/cmake/help/support.html >> CMake Consulting: http://cmake.org/cmake/help/consulting.html >> CMake Training Courses: http://cmake.org/cmake/help/training.html >> >> Visit other Kitware open-source projects at >> http://www.kitware.com/opensource/opensource.html >> >> Follow this link to subscribe/unsubscribe: >> https://cmake.org/mailman/listinfo/cmake -- Regards, Konstantin -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] how to detect architecture ?
Hi Franck, I'd suggest going a little more robust by using both CMAKE_SHARED_LIBRARY_PREFIX and CMAKE_SHARED_LIBRARY_SUFFIX to generate a function at configure time to resolve the correct filename. For example, util.h.in: #ifndef _UTIL_H_ #define _UTIL_H_ #include static inline void get_library_filename(char* filename, const char* libname) { sprintf(filename, "@CMAKE_SHARED_LIBRARY_PREFIX@ %s@CMAKE_SHARED_LIBRARY_SUFFIX@", libname); } #endif /* _UTIL_H_ */ Then your CMakeLists.txt: configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/util.h.in ${CMAKE_CURRENT_BINARY_DIR}/util.h @ONLY ) add_executable(foo main.c ${CMAKE_CURRENT_BINARY_DIR}/util.h) target_include_directories(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) And finally main.c: #include #include int main(int argc, char **argv) { char filename[256]; get_library_filename(filename, "foo"); printf("Library foo uses file %s\n", filename); return 0; } This will give you "libfoo.so" on Linux, "libfoo.dylib" on Apple, and " foo.dll" on Windows. -- Chuck Atkins Staff R Engineer, Scientific Computing Kitware, Inc. On Tue, Jan 9, 2018 at 10:04 AM, Franck Houssen <franck.hous...@inria.fr> wrote: > Thanks ! > > - Mail original - > > De: "Konstantin Tokarev" <annu...@yandex.ru> > > À: "Franck Houssen" <franck.hous...@inria.fr>, "CMake Mail List" < > cmake@cmake.org> > > Envoyé: Mardi 9 Janvier 2018 16:00:55 > > Objet: Re: [CMake] how to detect architecture ? > > > > > > > > 09.01.2018, 17:58, "Franck Houssen" <franck.hous...@inria.fr>: > > > Is there a way to detect architecture ? > > > > > > Seems there is nothing simple since these old threads : > > > https://stackoverflow.com/questions/11944060/how-to- > detect-target-architecture-using-cmake/12024211#12024211 > > > https://stackoverflow.com/questions/16796629/cmake- > create-architecture-aware-makefile > > > > > > Is there a solution now ? > > > > > > My need is quite simple: I have an executable who needs dlopen. To > test it, > > > I planned to write a bash script that would have done "./exe > > > /path/to/lib.so" on linux (debian, ...) OR "./exe /path/to/lib.dylib" > on > > > osx. To replace correctly so/dylib in the bash script I need to know > the > > > architecture. Any idea how to do this ? > > > > ${CMAKE_SHARED_LIBRARY_SUFFIX} > > > > Oh man ! Didn't know this one : exactly what I was looking for > > > > Franck > > > ,-- > > > > > > Powered by www.kitware.com > > > > > > Please keep messages on-topic and check the CMake FAQ at: > > > http://www.cmake.org/Wiki/CMake_FAQ > > > > > > Kitware offers various services to support the CMake community. For > more > > > information on each offering, please visit: > > > > > > CMake Support: http://cmake.org/cmake/help/support.html > > > CMake Consulting: http://cmake.org/cmake/help/consulting.html > > > CMake Training Courses: http://cmake.org/cmake/help/training.html > > > > > > Visit other Kitware open-source projects at > > > http://www.kitware.com/opensource/opensource.html > > > > > > Follow this link to subscribe/unsubscribe: > > > https://cmake.org/mailman/listinfo/cmake > > > > > > -- > > Regards, > > Konstantin > > > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at http://www.kitware.com/ > opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] how to detect architecture ?
Thanks ! - Mail original - > De: "Konstantin Tokarev" <annu...@yandex.ru> > À: "Franck Houssen" <franck.hous...@inria.fr>, "CMake Mail List" > <cmake@cmake.org> > Envoyé: Mardi 9 Janvier 2018 16:00:55 > Objet: Re: [CMake] how to detect architecture ? > > > > 09.01.2018, 17:58, "Franck Houssen" <franck.hous...@inria.fr>: > > Is there a way to detect architecture ? > > > > Seems there is nothing simple since these old threads : > > https://stackoverflow.com/questions/11944060/how-to-detect-target-architecture-using-cmake/12024211#12024211 > > https://stackoverflow.com/questions/16796629/cmake-create-architecture-aware-makefile > > > > Is there a solution now ? > > > > My need is quite simple: I have an executable who needs dlopen. To test it, > > I planned to write a bash script that would have done "./exe > > /path/to/lib.so" on linux (debian, ...) OR "./exe /path/to/lib.dylib" on > > osx. To replace correctly so/dylib in the bash script I need to know the > > architecture. Any idea how to do this ? > > ${CMAKE_SHARED_LIBRARY_SUFFIX} > Oh man ! Didn't know this one : exactly what I was looking for > > Franck > > ,-- > > > > Powered by www.kitware.com > > > > Please keep messages on-topic and check the CMake FAQ at: > > http://www.cmake.org/Wiki/CMake_FAQ > > > > Kitware offers various services to support the CMake community. For more > > information on each offering, please visit: > > > > CMake Support: http://cmake.org/cmake/help/support.html > > CMake Consulting: http://cmake.org/cmake/help/consulting.html > > CMake Training Courses: http://cmake.org/cmake/help/training.html > > > > Visit other Kitware open-source projects at > > http://www.kitware.com/opensource/opensource.html > > > > Follow this link to subscribe/unsubscribe: > > https://cmake.org/mailman/listinfo/cmake > > > -- > Regards, > Konstantin > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] how to detect architecture ?
On Tue, Jan 9, 2018 at 6:57 AM, Franck Houssenwrote: > Is there a way to detect architecture ? > > Seems there is nothing simple since these old threads : > https://stackoverflow.com/questions/11944060/how-to- > detect-target-architecture-using-cmake/12024211#12024211 > https://stackoverflow.com/questions/16796629/cmake- > create-architecture-aware-makefile > > Is there a solution now ? > > My need is quite simple: I have an executable who needs dlopen. To test > it, I planned to write a bash script that would have done "./exe > /path/to/lib.*so*" on linux (debian, ...) OR "./exe /path/to/lib.*dylib*" > on osx. To replace correctly so/dylib in the bash script I need to know the > architecture. Any idea how to do this ? > > https://cmake.org/Wiki/CMake_Useful_Variables https://cmake.org/Wiki/CMake_Checking_Platform if( APPLE ) install( PROGRAMS apple.script.sh DESTINATION script.sh ) elseif( UNIX ) install( PROGRAMS linux.script.sh DESTINATION script.sh ) endif( ) # not sure what the correct tag in endif should be. so you can just keep 2 scripts and install approrpiately > Franck > > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at http://www.kitware.com/ > opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] how to detect architecture ?
09.01.2018, 17:58, "Franck Houssen": > Is there a way to detect architecture ? > > Seems there is nothing simple since these old threads : > https://stackoverflow.com/questions/11944060/how-to-detect-target-architecture-using-cmake/12024211#12024211 > https://stackoverflow.com/questions/16796629/cmake-create-architecture-aware-makefile > > Is there a solution now ? > > My need is quite simple: I have an executable who needs dlopen. To test it, I > planned to write a bash script that would have done "./exe /path/to/lib.so" > on linux (debian, ...) OR "./exe /path/to/lib.dylib" on osx. To replace > correctly so/dylib in the bash script I need to know the architecture. Any > idea how to do this ? ${CMAKE_SHARED_LIBRARY_SUFFIX} > Franck > ,-- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake -- Regards, Konstantin -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
[CMake] how to detect architecture ?
Is there a way to detect architecture ? Seems there is nothing simple since these old threads : https://stackoverflow.com/questions/11944060/how-to-detect-target-architecture-using-cmake/12024211#12024211 https://stackoverflow.com/questions/16796629/cmake-create-architecture-aware-makefile Is there a solution now ? My need is quite simple: I have an executable who needs dlopen. To test it, I planned to write a bash script that would have done "./exe /path/to/lib. so " on linux (debian, ...) OR "./exe /path/to/lib. dylib " on osx. To replace correctly so/dylib in the bash script I need to know the architecture. Any idea how to do this ? Franck -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake