[CMake] How to Compile with -municode for MinGW-w64

Petr Kmoch petr.kmoch at gmail.com
Wed May 30 03:25:00 EDT 2018


Hi R0b0t1,

add_definitions() is for adding preprocessor macro definitions (-D
options), not for general compilation options such as -m. You should set
the options as compilation options instead, using target_compile_options.
Also, -mwindows should probably not be passed directly; instead, use
CMake's built-in WIN32 argument in add_executable. Overall, it would look
like this:

include_directories (
  "${CMAKE_CURRENT_SOURCE_DIR}"
)

add_executable (
  mtktool
  WIN32
  mtktool.c
)

target_compile_options(
  mtktool PRIVATE -municode
)


Petr

On 30 May 2018 at 04:33, R0b0t1 <r030t1 at gmail.com> wrote:

> Hello,
>
> I pass -municode in add_definitions but GCC still complains about the
> wrong type on WinMain, citing it needs an LPSTR argument. With
> -municode set it should require a LPWSTR and should be named wWinMain.
> If I name the function wWinMain the linker complains about a missing
> WinMain, which makes no sense. This works when I create a Makefile
> myself.
>
> CMakeLists.txt as follows.
>
> cmake_minimum_required (VERSION 3.5)
> project (mtktool)
>
> list (
>   APPEND
>   CMAKE_MODULE_PATH
>   "${CMAKE_CURRENT_LIST_DIR}/cmake"
> )
>
> set (mtktool_VERSION_MAJOR 0)
> set (mtktool_VERSION_MINOR 0)
> set (mtktool_VERSION_PATCH 0)
>
> configure_file (
>   "${PROJECT_SOURCE_DIR}/config.h.in"
>   "${PROJECT_SOURCE_DIR}/config.h"
> )
>
> include_directories (
>   "${CMAKE_CURRENT_SOURCE_DIR}"
> )
>
> add_definitions (
>   -municode
>   -mwindows
> )
>
> add_executable (
>   mtktool
>   mtktool.c
> )
>
> Cheers,
>      R0b0t1
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180530/4283f8b8/attachment.html>


More information about the CMake mailing list