Are there environment variables for CMake add_library (<lib> OBJECT <src>)?
CMake 2.8.8 introduces the OBJECT library type at compilation: add_library (OBJECT). This is a useful construct that allows you to compile all classes into .o files, but not add them to the library.
However, I'm not sure which flags end up joining the command in the generated make files. Basically, when the add_library (SHARED) command is executed, it is added to any flags specified by CMAKE_SHARED_LIBRARY_CXX_FLAGS. I would like to be able to specify assembly flags for JUST OBJECT libraries without resorting to more global flags such as CMAKE_CXX_FLAGS_DEBUG and CMAKE_CXX_FLAGS_RELEASE. Does anyone have any ideas if such a flag exists or is planned?
Summary:
# has CMAKE_SHARED_LIBRARY_CXX_FLAGS to set SHARED library build flags add_library(<lib> SHARED <srcs>) # Is any environment variable available to set OBJECT library build flags? add_library(<lib> OBJECT <srcs>) I was expecting an environment variable such as CMAKE_OBJECT_LIBRARY_CXX_FLAGS to set the OBJECT assembly flags. Looking through the source code (Modules / SystemInformation.in and Modules / CMakeCXXInformation.cmake), I did not find anything similar to the OBJECT libraries.
Edit: In particular, I want to add -fPIC to the OBJECT library, but not to executable files, so I donβt want to specify a flag in CMAKE_CXX_FLAGS _ *
When using CMake 2.8.9 or later, use the POSITION_INDEPENDENT_CODE property to enable position-independent code by the compiler independently:
add_library(<lib> OBJECT <srcs>) set_target_properties(<lib> PROPERTIES POSITION_INDEPENDENT_CODE ON) For older versions of CMake, you can set the COMPILE_FLAGS property of the OBJECT_LIBRARY target:
add_library(<lib> OBJECT <srcs>) set_property(TARGET <lib> PROPERTY COMPILE_FLAGS "-fPIC")