Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why CMAKE_LIBRARY_OUTPUT_DIRECTORY doesn't work?

Tags:

cmake

I want to build the static library on a bin subdir, but cmake seems not not doing what I want. Here is the Cmake file I wrote.

cmake_minimum_required(VERSION 3.3)
project(FancyLogger)

set(SOURCE_FILES FancyLogger.cpp)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)

add_library(FancyLogger STATIC ${SOURCE_FILES})

I made a build subdir, and ran cmake .. and make in this sub directory, hoping that the output static library will be generated on the bin library.

But the output remains in the build directory, Why?

Here is my file tree

===== |

| FancyLogger.cpp

| CMakeLists.txt

| /build

| /bin

like image 336
richard.g Avatar asked Mar 18 '16 16:03

richard.g


1 Answers

For static libraries you have to set the CMAKE_ARCHIVE_OUTPUT_DIRECTORY, not the CMAKE_LIBRARY_OUTPUT_DIRECTORY.

So you will have:

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)

See how do I make cmake output into a 'bin' dir?

By the way, it's probably not a good idea to create subfolders within the source directory, especially in an automated way.

like image 197
Antonio Avatar answered Oct 19 '22 14:10

Antonio