[cmake-developers] Knowing if a C project is being built (Was Re: [CMake 0012959]: GenerateExportHeaders does not work for C)

Brad King brad.king at kitware.com
Wed Feb 22 07:21:36 EST 2012


On 2/21/2012 5:47 PM, Stephen Kelly wrote:
>> add_library(mylib mylib.c)
>> generate_export_header(mylib)
>
> I'm looking into fixing this bug, and I was wondering how to. I have never 
> built C code with CMake. 
> 
> I will need to conditionally call different check_compiles macros. Can I so 
> something like
> 
> if(CMAKE_C_PROJECT)
> check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
> else()
> check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
> endif()

Use CMAKE_<LANG>_COMPILER_LOADED to determine which
languages are enabled.  Then check both C and CXX
compilers.  If the results are the same then you
can just write the header normally.  Otherwise write
the header with #ifdef __cplusplus to distinguish
the two compilers.

-Brad



More information about the cmake-developers mailing list