[CMake] Executable using a library (.a or .so)

J Decker d3ck0r at gmail.com
Fri Nov 13 12:53:24 EST 2015


On Fri, Nov 13, 2015 at 9:51 AM, J Decker <d3ck0r at gmail.com> wrote:
> is this library required to be separate from the executable?
> If not; it's far easier...
>
# in MyLib/CmakeLists.txt
> add_library( MyLib <STATIC/SHARED; default STATIC> libsource1.c libsource2.cpp )

# in MyExe/CmakeLists.txt
> add_exectubable( MyExe exesource1.c )
> target_link_libraries( MyExe MyLib )
>

theose can be spread ito sepatate CMakeLists... with a root
CmakeLists.txt like...

---
cmake_minimum_version(something)

add_subdirectory( mylib )
add_subdirectory( myExe)



>
> On Fri, Nov 13, 2015 at 9:28 AM, houssen <houssen at ipgp.fr> wrote:
>> Hello,
>>
>> How to write a library (myLib as .a or .so) that can be used from an
>> executable (myExe) ?
>>
>> I read the CMake doc but, obviously, I still miss some major points !... My
>> understanding is that, I need :
>> - to write a FindMyLib.cmake for myExe to find myLib (= finding
>> include/library directories, and, libraries to link with)
>> - to use find_package from myExe to find myLib
>>
>> I tried to write a mini-project (attached to this mail) to do that but it
>> doesn't work: find_package doesn't find FindMyLib.cmake although
>> CMAKE_MODULE_PATH has been updated.
>>
>> Can somebody help me on making this project to work ? (not able to find
>> FindMyLib.cmake, not sure to know the "good" way to write FindMyLib.cmake,
>> others... - I would appreciate any remarks to explain me the "good" way to
>> do thing)
>>
>> Thanks,
>>
>> Franck
>>
>> Note: I set CMAKE_MODULE_PATH in the CMakeLists.txt of myLib (doing that
>> from myExe sounds not relevant: if you know where the package is, no need to
>> call find_package).
>> Note: my understanding is that when this will work, I would be possible to
>> build myLib as a .a or a .so, am I correct ?
>> --
>>
>> 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:
>> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list