[CMake] try_compile question

Mark Moll mmoll at cs.rice.edu
Mon Jun 7 16:32:00 EDT 2010


On Jun 7, 2010, at 2:30 PM, Alexander Neundorf wrote:

> 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.


Thanks. That works and is much simpler. 
-- 
Mark





More information about the CMake mailing list