title: Proper CMakeLists file
body: <p>I'm trying to build a project with <a href="https://github.com/jtv/libpqxx" rel="nofollow noreferrer"><strong>LIBPQXX Github</strong></a> for <strong>PostgreSQL</strong> using <strong>CLion</strong> and <strong>CMakeFiles</strong>. Here is my simple code for this problem, the argument in the <code>pqxx::connection con();</code> function were changed on purpose for the post.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;pqxx/pqxx&gt;
  #include "project_config.h"
  
  
  int main()
  {
      pqxx::connection conn("dbname = dbname user = user password = password hostaddr = hostaddr port = port");
      std::cout &lt;&lt; "Opened database successfully: " &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>When I execute the command in the <strong>Shell</strong> </p>
  
  <pre><code>g++ -std=c++11 -I /usr/local/include/pqxx/ -L /usr/local/lib/ -I /usr/pgsql-10/include/ -L /usr/pgsql-10/lib/ main.cpp -lpqxx -lpq -o run
  </code></pre>
  
  <p>and after that <code>./run</code>, everything works as it should.</p>
  
  <p>Now, when I use those <strong>CMakeFiles</strong> settings to get the same result to run the project in <strong>CLion</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.10)
  project(project)
  
  # Set flags
  set(COMPILE_FLAGS "-std=c++11")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}")
  
  # The version number.
  set (project_VERSION_MAJOR 1)
  set (project_VERSION_MINOR 0)
  
  # Use a header file for some CMake settings in the source code
  configure_file (
          "${PROJECT_SOURCE_DIR}/project_config.h.in"
          "${PROJECT_BINARY_DIR}/project_config.h"
  )
  
  
  # Set new own names
  set(APP_DOMAIN ${PROJECT_SOURCE_DIR}/dev/hmmenc_client)
  set(PQXX /usr/local/include/pqxx)
  set(PGSQL_10 /usr/pgsql-10/include)
  
  # Find the pqxx and pq libraries
  find_library(PQXX_LIB pqxx "${PQXX}")
  find_library(PQ_LIB pq "${PGSQL_10}")
  
  
  include_directories(${PROJECT_BINARY_DIR})
  
  # Other project path includes
  include_directories(${APP_DOMAIN})
  include_directories(${PQXX})
  include_directories(${PGSQL_10})
  
  find_package(FindPQXX)
  
  set(SOURCE_FILES
  #        ${APP_DOMAIN}/db/db.h
  #        ${APP_DOMAIN}/db/db.cpp
          ${APP_DOMAIN}/main.cpp
      )
  
  add_executable(project ${SOURCE_FILES})
  target_link_libraries(${TARGET_NAME} pqxx)
  #link_directories(project ${PQXX})
  </code></pre>
  
  <p>But when I try to run it I get:</p>
  
  <pre><code>CMakeFiles/project.dir/dev/hmmenc_client/main.cpp.o: In function `pqxx::connection_base::connection_base(pqxx::connectionpolicy&amp;)':
  /usr/local/include/pqxx/connection_base.hxx:695: undefined reference to `int pqxx::internal::check_library_version&lt;6, 2&gt;()'
  /usr/local/include/pqxx/connection_base.hxx:698: undefined reference to `pqxx::connection_base::clearcaps()'
  CMakeFiles/project.dir/dev/hmmenc_client/main.cpp.o: In function `pqxx::connect_direct::connect_direct(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)':
  /usr/local/include/pqxx/connection.hxx:83: undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
  /usr/local/include/pqxx/connection.hxx:83: undefined reference to `vtable for pqxx::connect_direct'
  CMakeFiles/project.dir/dev/hmmenc_client/main.cpp.o: In function `pqxx::connect_direct::~connect_direct()':
  /usr/local/include/pqxx/connection.hxx:78: undefined reference to `vtable for pqxx::connect_direct'
  /usr/local/include/pqxx/connection.hxx:78: undefined reference to `pqxx::connectionpolicy::~connectionpolicy()'
  CMakeFiles/project.dir/dev/hmmenc_client/main.cpp.o: In function `pqxx::basic_connection&lt;pqxx::connect_direct&gt;::~basic_connection()':
  /usr/local/include/pqxx/basic_connection.hxx:66: undefined reference to `pqxx::connection_base::close()'
  CMakeFiles/project.dir/dev/hmmenc_client/main.cpp.o: In function `pqxx::basic_connection&lt;pqxx::connect_direct&gt;::basic_connection(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)':
  /usr/local/include/pqxx/basic_connection.hxx:57: undefined reference to `pqxx::connection_base::init()'
  collect2: error: ld returned 1 exit status
  gmake[3]: *** [CMakeFiles/project.dir/build.make:95: project] Error 1
  gmake[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/project.dir/all] Error 2
  gmake[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/project.dir/rule] Error 2
  gmake: *** [Makefile:118: project] Error 2
  </code></pre>
  
  <p>Can someone help me with my <strong>CMakeLists</strong> configurations to get the same results as with executing the command above in the <strong>Shell</strong>?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I tried to use the <code>FindPQXX.cmake</code> as suggested in the comments below but I'm still getting the error</p>
  
  <pre><code>CMake Warning at CMakeLists.txt:76 (find_package):
    By not providing "FindFindPQXX.cmake" in CMAKE_MODULE_PATH this project has
    asked CMake to find a package configuration file provided by "FindPQXX",
    but CMake did not find one.
  
    Could not find a package configuration file provided by "FindPQXX" with any
    of the following names:
  
      FindPQXXConfig.cmake
      findpqxx-config.cmake
  
    Add the installation prefix of "FindPQXX" to CMAKE_PREFIX_PATH or set
    "FindPQXX_DIR" to a directory containing one of the above files.  If
    "FindPQXX" provides a separate development package or SDK, be sure it has
    been installed.
  </code></pre>
  
  <p>To make things maybe a little bit clearer. Lets say that my project tree looks like this:</p>
  
  <pre><code>project # Root folder
  project/cmake-build-debug # Some cmake code
  project/dev
  project/dev/hmmenc_client/ # I write my program with all the subfolders and their classes here
  project/dev/SEAL_API/ # Some other code to use later
  </code></pre>
  
  <p>I have my <code>CMakeLists.txt</code> and the <code>FindPQXX.cmake</code> files in my <code>project</code> root folder. The <code>main.cpp</code> that I want to compile is in <code>project/dev/hmmenc_client/</code></p>
  
  <p>I have added the </p>
  
  <pre><code>find_package(FindPQXX)
  target_link_libraries(${TARGET_NAME} pqxx)
  </code></pre>
  
  <p>to my <code>CMakeFiles.txt</code>. What am I missing here and what does <code>${TARGET_NAME}</code> stands for? I had to edit the <code>FindPQXX.cmake</code> file to include the <code>/usr/pgsql-10/include/</code> and <code>/usr/pgsql-10/lib/</code> since that is where I have my postgres dev requirements. The real <strong>PostgreSQL</strong> database is on some other machine.</p>
  
  <p>I used the standard settings to install the libpqxx from Github mentioned above so the relevant folders are <code>/usr/local/include/pqxx/</code> and <code>/usr/local/lib/</code></p>
  
  <p>I'm new to the <strong>Cmake</strong> world so don't take any info out :) </p>