CMakeLists.txt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. cmake_minimum_required(VERSION 2.8.4)
  2. project(VSResource)
  3. string(REPLACE "/INCREMENTAL:YES" ""
  4. CMAKE_EXE_LINKER_FLAGS_DEBUG
  5. "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
  6. message(STATUS "CMAKE_RC_COMPILER='${CMAKE_RC_COMPILER}'")
  7. # Because of the following avoidance techniques required for windres and VS6,
  8. # we recommend using a configured header file, and defining preprocessor
  9. # symbols via #define code and including that header in the rc file. Using
  10. # add_definitions is fine for simple definitions (with no spaces and no
  11. # quoting), but requires avoidance or work-arounds beyond that...
  12. if(CMAKE_RC_COMPILER MATCHES windres)
  13. # windres rc compiler does not properly define quoted /D values as strings
  14. message(STATUS "CMAKE_RC_COMPILER MATCHES windres")
  15. add_definitions(/DCMAKE_RCDEFINE=test.txt)
  16. add_definitions(/DCMAKE_RCDEFINE_NO_QUOTED_STRINGS)
  17. if(CMAKE_CURRENT_BINARY_DIR MATCHES " ")
  18. # windres cannot handle spaces in include dir
  19. set(CMAKE_RC_NO_INCLUDE 1)
  20. endif()
  21. elseif(MSVC60)
  22. # VS6 rc compiler does not deal well with spaces in a "/D" value, but it can
  23. # handle the quoting
  24. message(STATUS "MSVC60")
  25. add_definitions(/DCMAKE_RCDEFINE="test.txt")
  26. else()
  27. # expected case -- rc compiler is "capable enough"
  28. message(STATUS
  29. "rc compiler handles quoted strings with spaces in values via /D")
  30. set(TEXTFILE_FROM_SOURCE_DIR "textfile, spaces in name, from binary dir")
  31. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test.txt
  32. "${CMAKE_CURRENT_BINARY_DIR}/test with spaces.txt" @ONLY)
  33. add_definitions(/DCMAKE_RCDEFINE="test with spaces.txt")
  34. endif()
  35. if(CMAKE_RC_NO_INCLUDE)
  36. add_definitions(/DCMAKE_RC_NO_INCLUDE)
  37. else()
  38. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include.rc.in
  39. "${CMAKE_CURRENT_BINARY_DIR}/include.rc" @ONLY)
  40. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  41. endif()
  42. add_library(ResourceLib STATIC lib.cpp lib.rc)
  43. add_executable(VSResource main.cpp test.rc)
  44. target_link_libraries(VSResource ResourceLib)
  45. if(MSVC AND NOT MSVC_VERSION VERSION_LESS 1600)
  46. set_property(SOURCE test.rc PROPERTY COMPILE_FLAGS /nologo)
  47. endif()
  48. set_property(TARGET VSResource
  49. PROPERTY VS_GLOBAL_CMakeTestVsGlobalVariable "test val")
  50. if(CMAKE_GENERATOR MATCHES "Ninja|Visual Studio")
  51. cmake_policy(PUSH)
  52. cmake_policy(SET CMP0037 OLD)
  53. add_library("My ResourceLib" lib.cpp lib.rc)
  54. cmake_policy(POP)
  55. endif()