Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update windows.cmake to fix common build issues on Windows #984

Merged
merged 9 commits into from
Jan 28, 2019
38 changes: 36 additions & 2 deletions cmake/platform/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ if(BUILD_SHARED_LIBS)
if(WIN32)
function(add_library library)
# Check if its an external, imported library (e.g. boost libs via cmake module definition)
list(FIND ARGN "IMPORTED" FIND_POS)
list(FIND ARGN "IMPORTED" FIND_IMPORTED)
list(FIND ARGN "ALIAS" FIND_ALIAS)
dirk-thomas marked this conversation as resolved.
Show resolved Hide resolved
_add_library(${ARGV0} ${ARGN})
if(${FIND_POS} EQUAL -1)
if(${FIND_IMPORTED} EQUAL -1 AND ${FIND_ALIAS} EQUAL -1)
set_target_properties(${ARGV0}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_BIN_DESTINATION}
Expand All @@ -54,3 +55,36 @@ if(BUILD_SHARED_LIBS)
endfunction()
endif()
endif()

# It is encouraged to follow this guide to enable exports for dll's in a cross-platform way:
# http://wiki.ros.org/win_ros/Contributing/Dll%20Exports
# however, since not every project has implemented import/export macros, enable CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS as a workaround
# https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/
if(BUILD_SHARED_LIBS)
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
endif()

# For Windows, add difinitions to exclude definitions for common names macros that cause name collision
if(WIN32)
# enable Math Constants (https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants)
add_definitions(-D_USE_MATH_DEFINES)

# do not define STRICT macros (minwindef.h or boost\winapi\basic_types.hpp)
add_definitions(-DNO_STRICT)

# do not define min/max macros
add_definitions(-DNOMINMAX)

# do not define STRICT macros (qtgui\qwindowdefs_win.h)
add_definitions(-DQ_NOWINSTRICT)

# keep minimum windows headers inclusion
add_definitions(-DWIN32_LEAN_AND_MEAN)
endif()

if(MSVC)
# https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/
add_compile_options(/Zc:__cplusplus)
endif()