I want to populate with some script files in the /bin subdirectory of CMake directory, but can not find the /bin file.
What can I give guys some advice?
Thanks
I have to disagree with gvd's answer, since CMAKE_BINARY_DIR should always point to the top level directory of the build tree. If you need the location of the build tree where the current CMakelists.txt goes to, use CMAKE_CURRENT_BINARY_DIR
CMAKE_BINARY_DIR
if you are building in-source, this is the same as CMAKE_SOURCE_DIR,
otherwise this is the top level directory of your build tree
CMAKE_CURRENT_BINARY_DIR
if you are building in-source, this is the same as CMAKE_CURRENT_SOURCE_DIR,
otherwise this is the directory where the compiled or generated files from the
current CMakeLists.txt will go to
So the answer is: cmake_binary_dir/bin points to toplevelBuilddir/bin
CMAKE_BINARY_DIR is the build folder location of your CMakeLists.txt file.
Say you have:
MyProject/application/CMakeLists.txt
and your build output is in MyProject/build
when using CMAKE_BINARY_DIR in the above CMakeLists.txt, it points to MyProject/build/application/
Have a look at this list of CMake variables for more variables.
Related
Is it possible to specify build directory within CMakeLists file? If yes, how.
My aim is to be able to call "cmake" within top level source directory and have cmake figure out the build directory.
Afaik, with CMake the build directory is always the directory from where you invoke the cmake or ccmake command. So if you want to change the build directory, you have to change directories before running CMake.
To control the location where executables, static and shared libraries are placed once finished, you can modifiy CMAKE_RUNTIME_OUTPUT_DIRECTORY, CMAKE_ARCHIVE_OUTPUT_DIRECTORY, and CMAKE_LIBRARY_OUTPUT_DIRECTORY respectively.
By design, there is not a way to specify that in CMakeLists.txt. It is designed for the user to be able to build the project in whatever directory they want. The typical workflow is:
Check out the project source code.
Go to desired build directory, or the source dir if you plan to do an in-source build.
Run cmake or ccmake to configure the project in that build directory.
Build your project.
All of the directories specified within your CMakeLists.txt should be relative to the ${PROJECT_BINARY_DIR} and ${PROJECT_SOURCE_DIR} variables. In this way, your code becomes buildable across different platforms, which is the goal of CMake.
Using CMake with ROS, one can end up with a directory tree like this:
+src
-CMakeLists.txt (symbolic link to toplevel.cmake)
-CMakeExtras.txt (I want to use this)
+computing
+perception
+per1
-CMakeLists.txt
+per2
-CMakeLists.txt
+detection
+det1
-CMakeLists.txt
+sensing
+dev1
-CMakeLists.txt
In the CMakeExtras.txt I want to set up CMake variable, load common packages just once, etc like for example:
set(CMAKE_CXX_FLAGS "-O3 -Wall ${CMAKE_CXX_FLAGS}")
find_package(Boost REQUIRED COMPONENTS thread)
How can I do this? The INCLUDE() command is obvious, but I cannot edit the root level CMakeLists.txt and there doesn't seem to be a variable that will allow something like INCLUDE("${OVERALL_SRC_DIR}/CMakeExtras.txt). I suppose:
catkin_make -DOVERALL_SRC_DIR=~/project/src
Would be one solution, but is there a neater way?
Disclaimer: the question is still a bit unclear to me, so apologies in advance if the answer does not reflect your needs.
If the problem you want to solve is that you have a lot of directories like src in which the same top-level CMakeLists.txt is linked and you want to include a specific CMakeExtras.txt that resides in each particular directory, then you can solve this by adding:
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeExtras.txt)
to your top-level CMakeLists.txt. According to the documentation:
This the full path to the source directory that is currently being processed by cmake
and should solve this issue (i.e. the variable refers to the directory being processed, not to the CMakeLists.txt where it is used).
If instead your issue is how to compute the src path, given that a link to the top level CMakelists.txt is there, then you simply want to use PROJECT_SOURCE_DIR which:
is the source directory of the most recent project() command.
Is it possible to specify build directory within CMakeLists file? If yes, how.
My aim is to be able to call "cmake" within top level source directory and have cmake figure out the build directory.
Afaik, with CMake the build directory is always the directory from where you invoke the cmake or ccmake command. So if you want to change the build directory, you have to change directories before running CMake.
To control the location where executables, static and shared libraries are placed once finished, you can modifiy CMAKE_RUNTIME_OUTPUT_DIRECTORY, CMAKE_ARCHIVE_OUTPUT_DIRECTORY, and CMAKE_LIBRARY_OUTPUT_DIRECTORY respectively.
By design, there is not a way to specify that in CMakeLists.txt. It is designed for the user to be able to build the project in whatever directory they want. The typical workflow is:
Check out the project source code.
Go to desired build directory, or the source dir if you plan to do an in-source build.
Run cmake or ccmake to configure the project in that build directory.
Build your project.
All of the directories specified within your CMakeLists.txt should be relative to the ${PROJECT_BINARY_DIR} and ${PROJECT_SOURCE_DIR} variables. In this way, your code becomes buildable across different platforms, which is the goal of CMake.
I'm writing a cmake file for a project which has the following structure
project/ (root)
libraries/ (contains (precompiled) libraries
src/
code/ (contains a set of fortran files)
My CMakeLists.txt file is currently in project/ and effectively is just
cmake_minimum_required(VERSION 2.6)
enable_language(Fortran)
project(project1)
set(projsrc src/code)
set(libdir lib/)
find_library(PROJ_LIBRARY pr10 PATHS ${libdir})
add_executable (sc1 sc1.f90)
target_link_libraries(sc1 ${PROJ_LIBRARY})
This creates my binary in the same folder as the source code, when I actually want it in the level above (i.e. in the src folder - this structure will be changed so we have a bin folder eventually), but haven't worked out how to do it.
Some answers on SO say you have to have a CMakeLists.txt file in every folder - is this correct? Is it possible to set an environment variable or use a CMake variable (e.g. http://cmake.org/cmake/help/v2.8.8/cmake.html#command:set). It's also not very clear from some answers whether the solutions they have posted are C++ specific (as that is what language CMake most often seems to be used for).
Edit
I found out that I can change it to the behaviour I want by modifying it slightly:
cmake_minimum_required(VERSION 2.6)
enable_language(Fortran)
project(project1)
set(projsrc src/code)
set(libdir lib/)
find_library(PROJ_LIBRARY pr10 PATHS ${libdir})
add_executable (src/sc1 ${projsrc}/sc1.f90)
target_link_libraries(src/sc1 ${PROJ_LIBRARY})
However, this doesn't explain why my behaviour is different to how it should be, according to arrowdodger below. I'm also still trying to work out how to display the values of environment variables; I've tried the following with no luck:
message(${RUNTIME_OUTPUT_DIRECTORY})
message($ENV{RUNTIME_OUTPUT_DIRECTORY})
message(${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
message($ENV{CMAKE_RUNTIME_OUTPUT_DIRECTORY})
By default, binaries will appear in respective subdirectory of your build dir. By respective i mean the directory that contains CMakeLists.txt with add_executable() call.
For example, if you have following CMakeLists.txt
add_executable(tgt1 src1.f90)
add_executable(tgt2 subdir/src2.f90)
in the root folder, you will get both binaries in ${CMAKE_BINARY_DIR}. So if you wish tgt2 to be in ${CMAKE_BINARY_DIR}/subdir, you need to add CMakeLists.txt there and call add_executable(tgt2 src2.f90) from there.
You can change this behavior:
CMAKE_LIBRARY_OUTPUT_DIRECTORY, CMAKE_RUNTIME_OUTPUT_DIRECTORY and others.
You can also set respective target properties.
I call CMake 2.8 from an empty bin directory to do an out-of-source build:
> make ../svn/trunk/projekt/CMakeList.txt
but instead of generating the makefiles in place, CMake puts them into the source tree.
The CMake FAQ says that in this case you should look for CMakeCache.txt files in the source tree that trigger in-source-builds, but there are none.
Explicitly setting the binary directory doesn't work neither:
> make -DCMAKE_BINARY_DIR=`pwd` ../svn/trunk/projekt/CMakeList.txt
Any ideas what I can try else?
I guess you mean cmake ../svn/trunk/projekt/CMakeList.txt rather than make ...? That's the wrong way to do it. You need to specify the path to the top level of the CMake project not the CMakeLists.txt file itself, so after having removed the CMakeCache.txt files you should run:
cmake ../svn/trunk/projekt