In CMake, we can write:
add_library(mylib mylib.c)
for a dynamically-linked (shared) library, and
add_library(mylib STATIC mylib.c)
for a static one. But - can we start with the first syntax, then later mark the mylib
target as static?
In CMake, we can write:
add_library(mylib mylib.c)
for a dynamically-linked (shared) library, and
add_library(mylib STATIC mylib.c)
for a static one. But - can we start with the first syntax, then later mark the mylib
target as static?
My educated guess (I feel pretty confident right now, but I don't want to come off as too confident) is that this is not possible.
For one thing, you can trace how the type argument of the add_library
command gets parsed and eventually used to set data in internal CMake structures. Then you can try to see where else that data member is modified/modifiable and then look for "vectors" (in the "attack vector" sense of the word) into that execution path. I found none. Here's the call hierarchy for what I just mentioned:
Source/cmAddLibraryCommand.cxx cmAddLibraryCommand
Source/cmMakefile.cxx cmMakefile::AddLibrary
Source/cmMakefile.cxx cmMakefile::AddNewTarget
Source/cmMakefile.cxx cmMakefile::CreateNewTarget
Source/cmTarget.cxx cmTarget::cmTarget, which does this->impl->TargetType = type;
If you search for the regex "\bTargetType\s*=[^=]
" in the rest of source code, you'll only see it in that previously mentioned cmTarget::cmTarget
constructor.
And there's the TYPE
target property, but it's read-only. You'll get an error if you attempt to modify it.
© 2022 - 2024 — McMap. All rights reserved.
BUILD_SHARED_LIBS
is set. Maybe this is exactly what you want to achieve? – Feces