Question

I recently switch from Autotools to CMake because CMake seems to be better for cross platform development and what I've noticed is when I build a static library of my C++ code all the files inside have a suffix .cpp.o

ar -t PA8/libgenericTZR.a 
genericTZR.cpp.o

I've looked at other libraries built by other tools and they don't do that. I'm not sure if this is really a bad thing but, how can I get CMake to build the static libraries without the .cpp added file extension?

This is my CMake File

add_executable(PA8 ISP_Charges.cpp genericTZR.cpp genericTZR.h)

set(LIBSRC genericTZR.c genericTZR.h)
add_library(genericTZR SHARED ${LIBSRC})
add_library(genericTZR SHARED $<TARGET_OBJECTS:myObjects>)

add_library(genericTZR-static STATIC ${LIBSRC})
set_target_properties(genericTZR-static PROPERTIES OUTPUT_NAME $

install (TARGETS PA8 DESTINATION bin)
install (TARGETS genericTZR genericTZR-static DESTINATION lib)
install (FILES "${PROJECT_BINARY_DIR}/PA8/genericTZR.h" DESTINA$

Thanks

Was it helpful?

Solution

According to this thread on cmake list (and I agree with it), it is not a good idea to try to change the output file names.

Consider the example gave in the link:

 add_executable(foo foo.c foo.cpp)

Generated objects would be foo.c.o and foo.cpp.o. They would conflict if you forced them to have just the .o extension.

You can try to use the non-documented, internal, might-change-in-the-future

set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)

I don't know if they're still available or if works at all. I've never used them.

As comments on your post have clarified it, the names inside the static lib aren't really used, you shouldn't worry about them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top