[CMake] try_compile question

Alexander Neundorf a.neundorf-work at gmx.net
Mon Jun 7 15:30:37 EDT 2010


On Monday 07 June 2010, Mark Moll wrote:
> I must be missing something obvious, but I can’t get try_compile to work. I
> have the following file, CheckSZencoder.cpp:
>
> #include <stdlib.h>
> #include <szlib.h>
> int main(void)
> {
>     if(SZ_encoder_enabled() == 1)
>         exit(0);
>     else
>         exit(1);
> }
>
>
> I have these cmake commands:
>
> find_library(SZ_LIBRARY sz DOC "Szip library")
> find_path(SZ_INCLUDE szlib.h DOC "Szip include directory")
> message("${SZ_INCLUDE}\n${SZ_LIBRARY}")
> try_compile(SZ_ENCODER "${PROJECT_BINARY_DIR}"
> 	"${CMAKE_SOURCE_DIR}/CMakeModules/CheckSZencoder.cpp"
> 	CMAKE_FLAGS
> 	INCLUDE_DIRECTORIES ${SZ_INCLUDE}
> 	LINK_LIBRARIES ${SZ_LIBRARY}
> 	OUTPUT_VARIABLE szoutput)
> message(${szoutput})

I'd recommend not to use try_compile() directly.
Checkout whether check_include_files(), check_library_exists() or 
check_c_source_compiles() do what you need. They are much easier to use.

Alex


More information about the CMake mailing list