The issue you’re encountering is that CMake does not support changing the CMAKE_GENERATOR_PLATFORM midway through a script. Setting CMAKE_GENERATOR_PLATFORM affects the entire configuration process, and changing it after the initial configuration won’t have any effect.
To achieve the goal of building both 32-bit and 64-bit versions of your project on Windows, you can create two separate build directories and configure each one for a different architecture. Below is an example of how to modify your CMake script and the necessary commands to achieve this.
First, ensure your CMake script is only responsible for defining the project structure and the source files, without attempting to set the CMAKE_GENERATOR_PLATFORM.
cmake_minimum_required(VERSION 3.26)
project(spotify_excel_test)
set(CMAKE_CXX_STANDARD 20)
# Common include directories
include_directories(include)
include_directories(include/tinf)
# Platform-specific setup
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for Mac OS X")
include_directories(include/MinXL)
include_directories(include/MinXL/Core)
include_directories(include/MinXL/Core/Implementation)
include_directories(include/MinXL/Core/Interface)
include/MinXL/Core/Implementation/Array.hpp
include/MinXL/Core/Implementation/String.hpp
include/MinXL/Core/Implementation/Variant.hpp
include/MinXL/Core/Interface/Array.hpp
include/MinXL/Core/Interface/String.hpp
include/MinXL/Core/Interface/Variant.hpp
include/MinXL/Core/Common.hpp
include/MinXL/Core/Exception.hpp
include/MinXL/Core/Types.hpp
set(ULC_SOURCES ${COMMON_SOURCES} ${MACOS_SOURCES})
include_directories(include/WindowsSpecific)
# Add your Windows-specific source files here
set(ULC_SOURCES ${COMMON_SOURCES} ${WINDOWS_SOURCES})
add_library(spotify_excel_test SHARED ${ULC_SOURCES})
set(TARGET_DYLIB "libspotify_excel_test.dylib")
set(DEPLOY_DIR "${CMAKE_SOURCE_DIR}/../../../../excel/mac/")
set(DEPLOYED_DYLIB "${DEPLOY_DIR}/${TARGET_DYLIB}")
file(MAKE_DIRECTORY ${DEPLOY_DIR})
add_custom_command(TARGET spotify_excel_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:spotify_excel_test>"
COMMENT "Copying libspotify_excel_test.dylib to deploy directory"
add_custom_command(TARGET spotify_excel_test POST_BUILD
COMMAND chmod +x "${DEPLOY_DIR}/package_sign_notarize.sh"
COMMAND "${DEPLOY_DIR}/package_sign_notarize.sh" "${DEPLOYED_DYLIB}"
WORKING_DIRECTORY ${DEPLOY_DIR}
COMMENT "Packaging and notarizing .dmg")
Next, you need to create two separate build directories and configure each for the desired architecture. This is typically done in your build process, outside of the CMake script itself.
# Create build directory for 64-bit
cmake --build . --config Release
# Create build directory for 32-bit
cmake --build . --config Release
- CMake Script: The CMake script now only defines the project, includes, and source files without attempting to set the
CMAKE_GENERATOR_PLATFORM.
- Separate Build Directories: You create two separate build directories: one for 64-bit and one for 32-bit. Each directory is configured with the appropriate platform using the
-A option in the cmake command.
- Build Commands: The
cmake --build . --config Release command is used to build the project in each configuration.
By following this approach, you ensure that each build directory is properly configured for the desired architecture, and you will end up with two separate .dll files: one for 64-bit and one for 32-bit.