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

**URL:** https://discourse.cmake.org/t/make-commands-equivalent-in-cmake-for-cplex-library-on-linux/8873
**Category:** Usage
**Tags:** os:linux, gen:makefiles
**Created:** [September 3, 2023, 11:28am UTC](https://discourse.cmake.org/t/make-commands-equivalent-in-cmake-for-cplex-library-on-linux/8873 "2023-09-03T11:28:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TryerGit](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tryergit/32/3777_2.png) [@TryerGit](https://discourse.cmake.org/u/TryerGit)
#### Post date: [September 3, 2023, 11:28am UTC](https://discourse.cmake.org/t/make-commands-equivalent-in-cmake-for-cplex-library-on-linux/8873/1 "2023-09-03T11:28:40Z")

</div>

Hello,

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](https://www.ibm.com/docs/en/icos/12.10.0?topic=cplex-setting-up-gnulinuxmacos)

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.

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

${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linux: ${OBJECTFILES}
	${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
	${LINK.cc} -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"
	$(COMPILE.cc) -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., [https://github.com/ampl/mp/blob/master/support/cmake/FindCPLEX.cmake](https://github.com/ampl/mp/blob/master/support/cmake/FindCPLEX.cmake)) 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):

`find_package(Threads)`

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

```auto
check_library_exists(m floor "" HAVE_LIBM)
  if (HAVE_LIBM)
    set(CPLEX_LINK_LIBRARIES ${CPLEX_LINK_LIBRARIES} m)
  endif ()

```

the equivalent of -lm in the make command ?

Thank you for your help.

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [September 4, 2023, 6:22am UTC](https://discourse.cmake.org/t/make-commands-equivalent-in-cmake-for-cplex-library-on-linux/8873/2 "2023-09-04T06:22:55Z")

</div>

> [@TryerGit](#):
>
> For instance, does line 99 here (of the FindCPLEX.cmake file referred to above):
> 
> `find_package(Threads)`
> 
> perform the equivalent of -lpthread?

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

> [@TryerGit](#):
>
> Also, are the lines following line 154
> 
> ```auto
> check_library_exists(m floor "" HAVE_LIBM)
> if (HAVE_LIBM)
> set(CPLEX_LINK_LIBRARIES ${CPLEX_LINK_LIBRARIES} m)
> endif ()
> 
> ```
> 
> the equivalent of -lm in the make command ?

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.

---

<div class="post-metadata">

### Author: ![TryerGit](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tryergit/32/3777_2.png) [@TryerGit](https://discourse.cmake.org/u/TryerGit)
#### Post date: [September 4, 2023, 4:12pm UTC](https://discourse.cmake.org/t/make-commands-equivalent-in-cmake-for-cplex-library-on-linux/8873/3 "2023-09-04T16:12:44Z")

</div>

Thank you. There seems to be a much simpler FindCPLEX.cmake available at [or-tools/cmake/FindCPLEX.cmake at stable · google/or-tools (github.com)](https://github.com/google/or-tools/blob/stable/cmake/FindCPLEX.cmake). 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.
