How to set Visual C build options for Struct Member Alignment in CMake?

1.2k Views Asked by At

I want to know how I can set the following Visual Studio build options in my CMakeLists.txt.

Struct Member Alignment = 1 Byte (/Zp1) which is set in the Project properties (Configuration Properties -> C/C++ -> Code Generation).

1

There are 1 best solutions below

0
Kevin On

You can set this MSVC-specific compilation flag (/Zp) as a CMake compile option:

add_library(MyLib SHARED ${MY_SOURCES})

if(MSVC)
    # Add the /Zp flag for the MyLib library target.
    target_compile_options(MyLib PRIVATE /Zp1)
endif()