feelfree
feelfree

Reputation: 11763

How to set CMAKE_INTDIR or CMAKE_CFG_INTDIR to remove the project configuration?

Now I am using CMake to create a VC 10 project. One issue I have found is that the path of the output library or execute program is connected with the project configuration (debug or release). In order to illustrate it, I give the following examples:

  cmake_minimum_required( VERSION 2.6 )
  project (test) 
  add_definitions (-DEXP_STL )
  add_library(lib1 SHARED lib1.cxx)
  set_target_properties(lib1 PROPERTIES LINK_INTERFACE_LIBRARIES "")
  set(LIBRARY_OUTPUT_PATH ${test_SOURCE_DIR})

The last command in the script denote that I would like to put the output library (lib1) in the directory of ${test_SOURCE_DIR}. However, the output library is located in ${test_SOURCE_DIR}/Debug instead. I was wondering how I could make sure that the output library is exactly in the path I have set. Thanks!

BWT: The reason why I raise this question is because in the Linux development environmental the output library or execute program path is exactly the path you set with set(LIBRARY_OUTPUT_PATH ...) function. I want to have a consistent result.

Upvotes: 1

Views: 3754

Answers (1)

feelfree
feelfree

Reputation: 11763

This question is regarded as duplicated, and one possible solution is as follows:

if (WIN32)
    set(myoutputdirectory ${your_source_file_SOURCE_DIR}/output/win/32)
elseif (CMAKE_COMPILER_IS_GNUCC)
    set(myoutputdirectory ${your_source_file_SOURCE_DIR}/output/linux/32)
elseif(APPLE)
    set(myoutputdirectory ${your_source_file_SOURCE_DIR}/output/mac/32)
endif (WIN32)
# set output parth
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${myoutputdirectory} )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${myoutputdirectory} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${myoutputdirectory} )
# for multi-config builds (e.g. msvc)
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
    string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
    set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${myoutputdirectory} )
    set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${myoutputdirectory} )
    set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${myoutputdirectory} )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )

Upvotes: 4

Related Questions