1

I have a directory structure in CMake as follows:

root
    CMakeLists.txt
    subproject_folder
        my_dll_library
        CMakeLists.txt
            src
                source1.cpp
                source2.cpp
            inc
                library.h
            CMakeLists.txt
        library_demo
            src
                demo.cpp
            CMakeLists.txt
    build
    bin

My root CmakeLists.txt contains this:

cmake_minimum_required(VERSION 2.8)
add_subdirectory(subproject_folder)
if(MSVC)
# Force to always compile with W4
    if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
            string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    else()
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
    elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
    # Update if necessary
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
    endif()
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

The CMakeLists in the subproject folder just contains

add_subdirectory(my_dll_library)
add_subdirectory(library_demo)

The CMakeLists in the library_demo folder contains

project(library_demo)
add_executable(librarydemo src/demo.cpp)
target_link_libraries(librarydemo my_dll_library)
install(TARGETS librarydemo DESTINATION bin)

The CMakeLists in the my_dll_library folder contains

add_library(lib_zaber SHARED src/source1.cpp src/source2.cpp)
install(TARGETS lib_zaber DESTINATION bin)

I want to have the demo executable and the library DLL copied to the bin folder, but it isn't working. What am I doing wrong?

Tim
  • 834
  • 2
  • 12
  • 31

2 Answers2

1

Try to set those variables too:

CMAKE_BINARY_DIR
CMAKE_CURRENT_BINARY_DIR

There's a whole list of variables you could try here:

http://www.cmake.org/Wiki/CMake_Useful_Variables

The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
  • Thanks, but that didn't do anything. – Tim Sep 19 '13 at 06:45
  • @Tim There are too many other directories you can try to change. You have a full list to try. If anything is going to work, it should be within that list. I did that before but I don't have the source anymore, unfortunately. Good luck! – The Quantum Physicist Sep 19 '13 at 06:57
  • 1
    EXECUTABLE_OUTPUT_PATH is the cmake variable for executables and dynamic libraries path. Set it before add_executable(...)/add_library(...) with the path you need. – Ivan Ishchenko Sep 19 '13 at 07:18
  • 1
    In general, avoid setting variables like `CMAKE_BINARY_DIR` and `CMAKE_CURRENT_BINARY_DIR`. CMake sets these for the benefit of your scripts. – John McFarlane Aug 09 '20 at 07:29
1

The command

install(.. DESTINATION <dir>)

installs to ${CMAKE_INSTALL_PREFIX}/<dir>.

You need to set CMAKE_INSTALL_PREFIX either in the CMakeLists.txt or when calling cmake:

cmake ... -DCMAKE_INSTALL_PREFIX=<dir>
tamas.kenez
  • 7,301
  • 4
  • 24
  • 34