[CMake] Specifying whether a library is C or C++

Aggelos Kolaitis neoaggelos at gmail.com
Wed Nov 13 12:15:34 EST 2013


Hey CMake list,

I have kind of a problem with CMake (but I guess it's the strange way
I'm using it :p).

I use CMake to have a simple and consistent build system for my
cross-platform library. My library is written in C, but it also has an
optional wrapper C++ interface.

During the generation of makefiles, the user can choose whether or not
to build the C++ interface, and so I choose the appropriate language
for my library. The thing is, CMake will always fail if there is no
g++, even if the user disables the C++ interface. The code in
CMakeLists.txt looks like this(see the full file in context at [1])

[code]

# I don't add 'C' as the language, because I get build errors with g++
project(PROJECT_NAME)

# Option to build c++ interface
option(BUILD_CXX "Build the C++ interface" ON)

# Default c files
set(SOURCES list_of_c_sources.c)

# Add c++ interface if needed
if (BUILD_CXX)
    set(CXX_SOURCES list_of_cxx_sources.cxx)
    set_source_files_properties( CXX_SOURCES PROPERTIES LANGUAGE CXX )
    set(SOURCES ${SOURCES} ${CXX_SOURCES})
endif(BUILD_CXX)

[/code]

When I try to generate makefiles with: `cmake -DBUILD_CXX=OFF .....`,
the generation fails if it can't find a c++ compiler, even though it
isn't needed

I hope the *problem* is clear here, but I'm willing to provide more
information if needed. Thanks in advance.

-- Aggelos Kolaitis

[1]: https://bitbucket.org/sdlu/sdlu/src/79338d0f19b24c5997b87b5c318faf76627be50a/CMakeLists.txt?at=master


More information about the CMake mailing list