Make command's equivalent in CMake for CPLEX library on Linux


I have so far been using make to link to the CPLEX library. This library does not offer any cmake support but they provide the following guidance to link to their library:

Setting up CPLEX on GNU/Linux/macOS - IBM Documentation

Based on this, for several years, I have been able to link to their library via the following commands in the makefile which I used to invoke via make.

# Link Libraries and Options
LDLIBSOPTIONS=-L /opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic

	${} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linux ${OBJECTFILES} ${LDLIBSOPTIONS} -lcplex -lm -lpthread -ldl -lppl -lgmp -lgmpxx

${OBJECTDIR}/_ext/ce8a225a/userfile.o: ../../../userfile.cpp
	${MKDIR} -p ${OBJECTDIR}/_ext/ce8a225a
	${RM} "$@.d"
	$( -O2 -DIL_STD -DNDEBUG -I/opt/ibm/ILOG/CPLEX_Studio1210/cplex/include -I../include -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/_ext/ce8a225a/userfile.o ../../../userfile.cpp

The above commands are easy enough for me to understand what is going on and what is expected of the compiler/linker.

I am trying to achieve the same using CMake. There are places where I have found FindCPLEX.cmake (for e.g., using which I have been able to compile and link my old CPLEX projects without using make, but now using CMake.

Now, I am trying to gain an understanding of how the old make commands have been mapped over to CMake, but I am struggling. For instance, -lcplex -lm -lpthread of the old direct make compiling and linking, which part of FindCPLEX.cmake file achieves the equivalent? Also, with -DIL_STD, where is that set in FindCPLEX.cmake?

For instance, does line 99 here (of the FindCPLEX.cmake file referred to above):


perform the equivalent of -lpthread? Also, are the lines following line 154

check_library_exists(m floor "" HAVE_LIBM)
  if (HAVE_LIBM)
  endif ()

the equivalent of -lm in the make command ?

Thank you for your help.

This line only finds out how to link a threads library.

This also only finds libm.

The real magic happens between lines 198 and 206. Everything else seems to just fill the appropriate variables that are used in that block.

Thank you. There seems to be a much simpler FindCPLEX.cmake available at or-tools/cmake/FindCPLEX.cmake at stable ยท google/or-tools ( That along with the following CML.txt setting seems to work for me now.

target_link_libraries(CMakeProject CPLEX::CPLEX m pthread dl ppl gmp gmpxx Boost::boost OpenMP::OpenMP_CXX)

It will take me a while to fully understand the CMAKE magic you allude to.