Unable to Build My Project Using Cmake

Thank you JetBrains for creating CLion. I think it's great! The only thing I dislike at this point is building my projects in CLion. I have not used Cmake before, and it seems overly complicated when you just want to build a simple project. For the project that I've created, I can build the project simply using a single line for g++, which is:

g++ main.cpp -I/usr/include/postgresql/ -L/usr/lib/postgresql/9.3/lib/ -lpq -o main

Unfortunately with CLion, as far as I can tell, I'm required to use cmake to build and debug my project. After spending a considerable amount of time searching the web, and trying different things, I cannot build this simple project with cmake. I honestly don't want to have to relearn another way to build and debug my project or waste a lot of time figuring out how to build the project when I am only interested in programming C++. Is there a simple way for me to build my project and move on to writing C++ code without having to learn cmake?

I have also attempted using "FindPostgreSQL.cmake" that is located in clion-140.2310.6/bin/cmake/share/cmake-3.1/Modules$, and it will not find my PostgreSQL installation. I've tried a lot of other combinations to try to tell cmake the include path and the library where to find the information needed to build my project, and without success.

Attached is my project and my final attempts to get cmake to work. Can someone help me resolve this building problem? Alternatives to cmake are welcome... :)

Update: I am using Debian Wheezy as my operating system. I believe the rest of the information needed is included in the project file.

Thank you,
Darin



Attachment(s):
test.tar.gz
7 comments
Comment actions Permalink

Hi Darin,

You're right, there's a CMake module for PostgreSQL library which can find all neccessary include and library paths (the same as -I and -L flags in your g++ command). So for your example CMakeLists.txt should be the following:

 
cmake_minimum_required(VERSION 2.8.4)
project(testprj)

find_package(PostgreSQL REQUIRED)
include_directories (${PostgreSQL_INCLUDE_DIRS})

set(SOURCES main.cpp)
add_executable(testprj ${SOURCES})
target_link_libraries(testprj ${PostgreSQL_LIBRARIES})


Of course you can write include_directory command, like in your example, specifying include path directly, then you still need to link a library in order to build the application.

Regarding your concern of CMake usage I can only say that the choice of build systems was not that easy but a must. If you're interested why CMake was chosen here you can find an explanation. We plan to consider support of another build system after 1.0

1
Comment actions Permalink

Hello Maria,

Thank you for taking the time to reply. I appreciat it!

Here is my new cmake file based on your feedback:

 
cmake_minimum_required(VERSION 3.8.4)
project(test)

find_package(PostgreSQL REQUIRED)
set(PostgreSQL_INCLUDE_DIRS, "/usr/include/postgresql/")
include_directories (${PostgreSQL_INCLUDE_DIRS})

set(SOURCES main.cpp)
add_executable(test ${SOURCES})
set(PostgreSQL_LIBRARIES, "/usr/lib/postgresql/9.3/lib/")
target_link_libraries(test ${PostgreSQL_LIBRARIES})


Unfortunately, now I am getting an error that at a minimum CMake 3.8.4 or higher is required.

/home/darin/clion-140.2310.6/bin/cmake/bin/cmake --build /home/darin/.clion10/system/cmake/generated/bb99ca7e/bb99ca7e/Debug --target test -- -j 8
-- Configuring incomplete, errors occurred!
See also "/home/darin/.clion10/system/cmake/generated/bb99ca7e/bb99ca7e/Debug/CMakeFiles/CMakeOutput.log".
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.8.4 or higher is required.  You are running version 3.1.2

make: *** [cmake_check_build_system] Error 1


Do you have another suggestion for me to be able to get my make file built? Also, I do not see anything in the make file that will take care of the -lpq. What part of the make file handles this?

Thanks,
Darin

0
Comment actions Permalink
Hi Darin.

Please change CMake version from 3.8.4 to 2.8.4.
The correct value for this parameter is:
cmake_minimum_required(VERSION 2.8.4)
0
Comment actions Permalink

Thank you Anna! A very bone head move on my part. I just need to resolve the postgresql version, then I believe this project will build.

0
Comment actions Permalink

Finally after much messing around with Cmake trying to get it to compile my project, I finally got it done today with the following:

make_minimum_required(VERSION 2.8.4)
project(pgtest)

if (PostgreSQL_TYPE_INCLUDE_DIR)
else (PostgreSQL_TYPE_INCLUDE_DIR)
set (PostgreSQL_TYPE_INCLUDE_DIR ${PostgreSQL_INCLUDE_DIR})
endif (PostgreSQL_TYPE_INCLUDE_DIR)

find_package(PostgreSQL REQUIRED)
set(PostgreSQL_INCLUDE_DIRS, "/usr/include/postgresql/")
include_directories (${PostgreSQL_INCLUDE_DIRS})

set(SOURCES main.cpp)
add_executable(pgtest ${SOURCES})
set(PostgreSQL_LIBRARIES, "/usr/lib/postgresql/9.3/lib/")
target_link_libraries(pgtest ${PostgreSQL_LIBRARIES})


What a headache! I do understand that in most cases, for people that have difficulty finding the libraries, and figuring out an appropriate Makefile that cmake could benefit them in getting the job done, but I wish JetBrains would have kept it simple for the initial releases of CLion. What I could have done with one single line in a Makefile took a considerable amount of time to resolve, and makes me question whether CLion should be used at all until make is available for the IDE. I would hate to go down this path, and find out that there are significant issues every time I need to make a build change.

0
Comment actions Permalink

Hi Darin!

In CLion 1.0 we are going to support only CMake build system. You can actually find the reasons for that explained here: http://blog.jetbrains.com/clion/2014/09/cmake-vs-the-others-round-1/

However we understand how popular and important Makefiles build system is. So we are going to support it in future versions.
Here is the feature request: https://youtrack.jetbrains.com/issue/CPP-494.
Feel free to comment and upvote. Follow to get the updates.
0
Comment actions Permalink

Thank you Anna. I understand the decision. It reduced the amount of time to release. Ok.

I starred the request. Not certain whether that means upvote or not... Thanks for the information...

Darin

0

Please sign in to leave a comment.