3

I'm a beginner in Cmake and try to compile a library with my makefile. After hours and hours of research, all is good and compiles fines in visual studio. But it stills a problem for ouput folders. I explain.

I want to have this structure of folders at the end :

-vc_2013_x64      < for platform x64 in release
--bin
---my.dll, my.lib, ...

-vc_2013_x64d     < for platform x64 in debug
--bin
---my.dll, my.lib, ...

But when i try to make this tree, CMake add some "release" and "debug" folders after my bin folder. Like this following example :

-vc_2013_x64
--bin
*---release* --> NOT WANTED FOLDER
----my.dll, my.lib, ...

How i can fix it ? or try to overide like this maybe :

-release
--vc_2013_x64
---bin
----my.dll, my.lib, ...

I've search on web but have not find any answer.

Here is my CMakeLists.txt file :

cmake_minimum_required(VERSION 2.8)

#Configuration du projet

project(core CXX)

#add definitions
set(LIBRARY_OUTPUT_PATH /vc2013_x64/bin/)
set(LIBRARY_OUTPUT_DIRECTORY ../essai)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
add_definitions(-D_UNICODE -D_USRDLL -DCORE_EXPORTS)
add_definitions("/Gm")#"/GL" "/Gy" 


#remove_definitions
add_definitions(-UCMAKE_INTDIR="Release")

#inclusions
#include_directories(include/*)
#file( GLOB_RECURSE source_files src/*)

#Configuration de la librairie
add_library(

    core

    SHARED

    src/asserts.h
    src/errors.h
    src/filepath.h
    src/memory.h
    src/resources.h
    src/stdafx.h
    src/streams.h
    src/string.h
    src/system.h
    src/variants.h

    src/filepath.cpp
    src/main.cpp
    src/memory.cpp
    src/resources.cpp
    src/stdafx.cpp
    src/streams.cpp
    src/string.cpp
    src/system.cpp      
)

And here is my structure folder :

-core
--src           -> contains my .h and .cpp files 
--win32         -> solution files of visual studios
--cmake_build   -> contains my files generated by cmake
--CMakeLists.txt

Thanks

Edit :

So i try to make something like you say, but it doesn't create folder i specifiy :

project(core CXX)

#add definitions

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
add_definitions(-D_UNICODE -D_USRDLL -DCORE_EXPORTS)
add_definitions("/Gm")#"/GL" "/Gy" 

#remove_definitions
add_definitions(-UCMAKE_INTDIR="Release")


#Configuration de la librairie
add_library(

        core

        SHARED

    src/asserts.h
    src/errors.h
    src/filepath.h
    src/memory.h
    src/resources.h
    src/stdafx.h
    src/streams.h
    src/string.h
    src/system.h
    src/variants.h

    src/filepath.cpp
    src/main.cpp
    src/memory.cpp
    src/resources.cpp
    src/stdafx.cpp
    src/streams.cpp
    src/string.cpp
    src/system.cpp      
)

set(DIR_NAME "/vc2013_x64")
set(LIBRARY_OUTPUT_PATH_RELEASE "${DIR_NAME}/bin")
set(LIBRARY_OUTPUT_PATH_DEBUG "${DIR_NAME}d/bin")
install (TARGETS core DESTINATION ${LIBRARY_OUTPUT_PATH_RELEASE} CONFIGURATIONS Release)
install (TARGETS core DESTINATION ${LIBRARY_OUTPUT_PATH_DEBUG})
Algorys
  • 1,710
  • 2
  • 25
  • 52
  • This looks similar and may help you: http://stackoverflow.com/questions/7747857/in-cmake-how-do-i-work-around-the-debug-and-release-directories-visual-studio-2 – ChrisWard1000 Dec 01 '14 at 08:47
  • do you need this at time of development or deployment? – MatthiasB Dec 01 '14 at 09:02
  • @ChrisWard1000 I try this solution but it still not mork... I think i doesn't made the good changes... – Algorys Dec 01 '14 at 09:40
  • @MatthiasB This is a renovation project in my business. They did not use CMake before, so I have to put up nightbuild . At the moment I try to reproduce the results of visual studio just a library – Algorys Dec 01 '14 at 09:45
  • I put my CMakeLists file if it may help. – Algorys Dec 01 '14 at 09:51

2 Answers2

3

So i found my answer by myself. I think i've not explain correctly for my first question. It was for just remove the folder after build. The following commands are working :

set(BIN_PATH "../path") -> define your principal path
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_PATH}/bin/" ) ->define path for archive
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_PATH}/bin/" ) ->define path for Library
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_PATH}/bin/" ) ->define path for Runtime

Normally, all the files are created in /bin.

Algorys
  • 1,710
  • 2
  • 25
  • 52
0

What you could use is the install target of CMAKE. It allows you to define a install target where you can copy your build libraries and dependent files to. For your example this could look something like this:

add_library(core SHARED
    ...
)

set(DIR_NAME "/vc2013_x64")
set(LIBRARY_OUTPUT_PATH_RELEASE "${DIR_NAME}/bin")
set(LIBRARY_OUTPUT_PATH_DEBUG "${DIR_NAME}d/bin")

install (TARGETS core DESTINATION ${LIBRARY_OUTPUT_PATH_RELEASE} CONFIGURATIONS Release)
install (TARGETS core DESTINATION ${LIBRARY_OUTPUT_PATH_DEBUG} CONFIGURATIONS Debug)

You can then just run the install target in your build environment and the files are copied where you want them to be.

MatthiasB
  • 1,759
  • 8
  • 18
  • Thanks a lot for your help. I try your solution and copy this in my CMakeLists.txt but when i "Configure" in CMake it says : CMake Error at CMakeLists.txt:21 (install): install TARGETS given target "core" which does not exist in this directory. – Algorys Dec 01 '14 at 10:08
  • Given your line number, I guess you put the install command before the `add_library` command? The target actually refers to the name defined by your `add_library` or `add_executable` command, not the project name. So you have to define your libraries and executables first before you can install them. – MatthiasB Dec 01 '14 at 10:11
  • Ok and i have to replace LIBRARY_OUTPUT_PATH_DEBUG by a relative/absolute path ? – Algorys Dec 01 '14 at 10:15
  • it is the same as `LIBRARY_OUTPUT_PATH` in your CMakeLists.txt, just seperated for your release or debug folders. – MatthiasB Dec 01 '14 at 10:17
  • I'm lost ^^ I put the command install `(TARGETS core DESTINATION ${LIBRARY_OUTPUT_PATH_DEBUG} CONFIGURATIONS Debug)` at the end of my CMakeLists but it still doesn't work. It says : CMake Error at CMakeLists.txt:59 (install): install Library TARGETS given no DESTINATION! After i try to replace "DESTINATION" with something like that "/vc2013_x64/bin/" but it doesn't change anything. Sorry for my newbie question but can you explain a little more ? (I have put my folder structure in my original question) – Algorys Dec 01 '14 at 10:35
  • I added some lines in my answer to show how to create the directory names, but I strongly recommend you to have a look at some tutorials for cmake. This will clarify everything, and prevent you from starting out with bad habits. – MatthiasB Dec 01 '14 at 10:48
  • Ok many Thx. I will try to make some test with this commands. For the tutorials i make some research on web but it's always with a small project (just one .cpp at all)... but you're right, i have to train. If you have some good address I'm interested. – Algorys Dec 01 '14 at 11:02
  • [The cmake site](http://www.cmake.org/cmake-tutorial/) is a good starting point, both for reference and tutorials. – MatthiasB Dec 01 '14 at 12:23
  • I try it and understand some things suddenly but it doesn't create the file i demand... – Algorys Dec 01 '14 at 12:26
  • I put a new version of my CMakeLists.txt to show my changes. – Algorys Dec 01 '14 at 14:10
  • did you run the install target in the end? Also there is CONFIGURATIONS Debug missing for the second line – MatthiasB Dec 01 '14 at 14:11
  • So i found my answer by myself. I think i've not explain correctly for my question. It was for just remove the folder after build. The following commands are working : set(BIN_PATH "../path") set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_PATH}/bin/" ) set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_PATH}/bin/" ) set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_PATH}/bin/" ) – Algorys Dec 01 '14 at 14:36
  • If this is what you wanted you should post it as an answer and then choose it as accepted answer. So everyone looking at this question later will find the solution easier (instead of looking at a comment). – MatthiasB Dec 01 '14 at 14:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65973/discussion-between-matthiasb-and-mestra). – MatthiasB Dec 01 '14 at 15:08