[CMake] CMAKE_<LANG>_OUTPUT_EXTENSION

Michael Wild themiwi at gmail.com
Thu Sep 5 02:22:08 EDT 2013


On 04.09.2013 20:42, Michael Wild wrote:
> Dear all
> 
> no matter when I try to set CMAKE_{C,CXX}_OUTPUT_EXTENSION, on my Linux
> box using the GNU Makefiles generator the resulting object files always
> have a .o extension. I tried setting it in the cache, before and after
> the project() call. Nothing helps.
> 
> Is this a known issue? I tried trawling the archives, but only found
> references to IDE generators ignoring this setting.
> 
> Thanks for any help
> 
> Michael
> 

Seems like commit 422dc631b by Alex kind of broke the user's ability to specify
CMAKE_<LANG>_OUTPUT_NAME by unconditionally setting it to .o on UNIX and .obj
otherwise. The only solution I can see is to provide/override platform+compiler
specific files which get loaded by CMake<LANG>Information.cmake like this:

-------<8--------

cmake_minimum_required(VERSION 2.8)
project(output_extension NONE)

# create fake system- and compiler specific file
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/cmake/Platform")
foreach(id GNU HP Intel MIPSpro PathScale PGI SunPro VisualAge XL)
  foreach(l C CXX)
    file(WRITE "${PROJECT_BINARY_DIR}/cmake/Platform/${CMAKE_SYSTEM_NAME}-${id}-${l}.cmake"
      # ====> SET EXTENSION HERE <=====
      "set(CMAKE_${l}_OUTPUT_EXTENSION .MyFancyExtension)\n"
      "include(\"${CMAKE_ROOT}/Modules/Platform/\${CMAKE_SYSTEM_NAME}-\${CMAKE_${l}_COMPILER_ID}-${l}.cmake\"\n"
      "  OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)\n"
      "if(NOT _INCLUDED_FILE)\n"
      "  INCLUDE(\"${CMAKE_ROOT}/Modules/Platform/\${CMAKE_SYSTEM_NAME}-\${CMAKE_BASE_NAME}.cmake\"\n"
      "    OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)\n"
      "endif()\n"
      "if(NOT _INCLUDED_FILE)\n"
      "  INCLUDE(\"${CMAKE_ROOT}/Modules/Platform/\${CMAKE_SYSTEM_NAME}.cmake\" OPTIONAL)\n"
      "endif()\n"
      )
  endforeach()
endforeach()
list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_BINARY_DIR}/cmake")

cmake_policy(PUSH)
cmake_policy(SET CMP0017 OLD)
enable_language(C)
enable_language(CXX)
cmake_policy(POP)

-------<8--------

Michael


More information about the CMake mailing list