CMake¶
CMake
is an alternavie to make
that is more automated.
The program is installed on the Linux machine, however it's possible that the local version is too old. In this case, you can look at modules and use that instead.
One of the most common problem with CMake
is that if you use a module to change the compiler, it will not find it and will insist on using the local one whic leads to different types of problems.
In order to go around this problem, you can either use the environment variables CC and CXX (C and C++ compilers respectively) or the CMake
parameters to specify the correct ones.
In the case where you already tried a configuration, you'll have to clean the build directory and start over since it will not forget the incorrect configuration it made.
This is what it will usually look like.
cd projet1
module load cmake
module load gcc
mkdir build
cd build
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
make
Here's an example of CMakeLists.txt
for a cplex program. Don't forget to load the cplex-studio
module before configuring.
cmake_minimum_required(VERSION 3.15)
project(Projet1)
set(CPLEX_LIBRARIES ilocplex concert cplex)
set(SYSTEM_LIBRARIES m pthread dl)
add_compile_options(-Wall -DNDEBUG -DIL_STD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(cutstock cutstock.cpp)
target_link_libraries(cutstock PRIVATE ${CPLEX_LIBRARIES} ${SYSTEM_LIBRARIES})
Here's another example with gurobi. Again, don't foget to load the gurobi
module.
cmake_minimum_required(VERSION 3.15)
project(Projet1)
set(GUROBI_LIBRARIES gurobi_g++5.2 gurobi100)
add_compile_options(-Wall)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(sudoku sudoku.cpp)
target_link_libraries(sudoku PRIVATE ${GUROBI_LIBRARIES})