0

I am trying to make a static library, for example my_lib.a. This library is depending from a gSoap code - file2.cpp.o, which is generated because of this CMake instruction (and 2 custom commands):

add_library(${TARGET_NAME} ${SRC_FILES}
    ${GENERATED_SRC_FILES} ${GENERATED_H_FILES} ${GENERATED_RES_FILES})

file2.cpp is present in GENERATED_SRC_FILES. Everything runs fine until the moment of linking.

/usr/bin/ar cr ../lib/my_lib.a CMakeFiles/my_lib.dir/src/file1.cpp.o CMakeFiles/my_lib.dir/src/file2.cpp.o

If I let Make to use this command, the library my_lib.a will contain file1.cpp.o and file2.cpp.o. But in fact I do not need the file2.cpp.o in my *.a library.

Does anyone know how I have to manage this case in a way to obtain a my_lib.a which contains only the file1.cpp.o?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
Anton
  • 41
  • 8
  • I would write a macro that removes `file2.cpp` from `${GENERATED_SRC_FILES}` – drescherjm Jun 29 '15 at 15:55
  • Or maybe just list(REMOVE_ITEM GENERATED_SRC_FILES file2.cpp) – drescherjm Jun 29 '15 at 16:20
  • Thank you for the ideas ! :) I tried using the "list(..)" just before invoking the add_library() but it does not have a influence to the linking state... What you mean by creating a macro ? When I check the content of GENERATED_SRC_FILES, it contains the .cpp/.c files but not the object files *.o. Which means, for me, that the linking is completely different procedure... – Anton Jun 30 '15 at 08:56
  • If you remove the cpp file from the list then it will not be compiled as part of the library so you do not have to worry about .o files. – drescherjm Jun 30 '15 at 09:08
  • I saw what is a macro in CMake, I was not aware about this feature :) thank you for the idea, I will try it. – Anton Jun 30 '15 at 09:08
  • About the list remove_idem, yes I have the same thinking but unfortunately the result is not what I am expecting.. the *.o is always included in the *.a file. – Anton Jun 30 '15 at 09:10
  • I would delete the binary folder and reconfigure and regenerate in CMake and then rebuild. – drescherjm Jun 30 '15 at 09:17
  • I think I found a solution. The idea is to compile some *.o files with a different target which will not be the official one. Than in the official target you can put these files you consider as important ones. In my case I have only one file that I do not want to include in the *.a file.. So : the first target is: add_library(gSoap_files OBJECT ${GENERATED_SRC_FILES} ... ) and the official one is: add_library(${TARGET_NAME} ${SRC_FILES}) I inspired myself from this page: http://www.cmake.org/Wiki/CMake/Tutorials/Object_Library – Anton Jun 30 '15 at 13:25

1 Answers1

0

I think I found a solution. The idea is to compile some *.o files with a different target which will not be the official one. Than in the official target you can put these files you consider as important ones. In my case I have only one file that I do not want to include in the *.a file.. So :

the first target is:

add_library(gSoap_files OBJECT ${GENERATED_SRC_FILES} ... )

and the official one is:

add_library(${TARGET_NAME} ${SRC_FILES})

I inspired myself from this page:

http://www.cmake.org/Wiki/CMake/Tutorials/Object_Library

Anton
  • 41
  • 8