移动cmake release和debug文件夹

时间:2014-11-28 14:54:11

标签: c++ makefile cmake

我是Cmake的初学者,并尝试使用我的makefile编译库。经过数小时和数小时的研究,一切都很好,并在视觉工作室编造罚款。但是对于输出文件夹来说仍然存在问题。 我解释一下。

我希望最后有这种文件夹结构:

-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, ...

但是当我尝试制作这个树时,CMake在我的bin文件夹后添加了一些“release”和“debug”文件夹。像下面这样的例子:

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

我如何解决它?或者尝试像这样覆盖:

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

我在网上搜索但没找到任何答案。

这是我的CMakeLists.txt文件:

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      
)

这是我的结构文件夹:

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

由于

编辑:

所以我尝试制作像你说的那样,但它不会创建我指定的文件夹:

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})

2 个答案:

答案 0 :(得分:2)

所以我自己找到了答案。我想我的第一个问题没有正确解释。它只是为了在构建后删除文件夹。以下命令正在运行:

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

通常,所有文件都在/ bin中创建。

答案 1 :(得分:0)

您可以使用的是CMAKE的install目标。它允许您定义安装目标,您可以在其中复制构建库和相关文件。对于您的示例,这看起来像这样:

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)

然后,您可以在构建环境中运行安装目标,并将文件复制到您希望的位置。

相关问题