CMake: forced interaction between namespaces and library file names

CMake does not seem to support defining the relationship between the namespace of the exported or set target and the name of the corresponding library file.

So, for example, CMake makes it easy to create packages that contain uniquely named targets, such as MyOrg::MyLibrary(using the NAMESPACEcommand options export(EXPORT ...)and install(EXPORT ...), but the actual .a,. Lib, .so or .dll files will still have globally distinguished names, such as libMyLibrary.a: the namespace is not part of the library file name.

Of course, you can apply namespaces to your goals; in the above example, you can name your target by casting MyOrgMyLibraryto the library name, for example, libMyOrgMyLibrary.a. I think that this is normal, except that it makes the parameter NAMESPACEalmost useless (or you will fall into targets with a name MyOrg::MyOrgMyLibrary), making me think that I missed something.

Is there a way to override the name of the generated library? Or what would be the “right” way with CMake so that library files get unambiguous names?

+4
source share
2 answers

, . , . , (, Qt), , .

, , CMake, . . - , , . nameclashes . , . Unixes /usr/lib, ( @JPNotADragon ).

, , .

, , . , nameclashes - , , , .

+5

?

. . OUTPUT_NAME .

, ( , , ):

function(my_add_library NAME)
  add_library(${NAME} ${ARGN})
  set_target_properties(${NAME} PROPERTIES OUTPUT_NAME my_${NAME})
endfunction()
+2

All Articles