loader: Fix cmake on win for list of normal and opt sources
authorJon Ashburn <jon@lunarg.com>
Fri, 11 Mar 2016 17:58:56 +0000 (10:58 -0700)
committerJon Ashburn <jon@lunarg.com>
Fri, 11 Mar 2016 18:13:34 +0000 (11:13 -0700)
Change-Id: I5eb7836ba0606628fc663ecfa8cd3ca4d535a8b9

loader/CMakeLists.txt

index 2b38b88a1f9a103f434726d85df344e30765e781..654c2a2ff7d96096919fd833c2cbcf1d484a8d77 100644 (file)
@@ -13,7 +13,7 @@ endif()
 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
 
-set(LOADER_SRCS
+set(NORMAL_LOADER_SRCS
     loader.c
     loader.h
     vk_loader_platform.h
@@ -26,24 +26,32 @@ set(LOADER_SRCS
     gpa_helper.h
     cJSON.c
     cJSON.h
-    dev_ext_trampoline.c
     murmurhash.c
     murmurhash.h
 )
 
+set (OPT_LOADER_SRCS
+    dev_ext_trampoline.c
+)
+
+set (LOADER_SRCS ${NORMAL_LOADER_SRCS} ${OPT_LOADER_SRCS})
 
 if (WIN32)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
-    # Build dev_ext_trampoline with -O2 to allow tail-call optimization.
-    # We have to disable Real Time Checks when we specify -O2.
-    # Unfortunately, this also disables them for all of the loader.
-    STRING (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
-    STRING (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
-    set_source_files_properties(dev_ext_trampoline.c PROPERTIES COMPILE_FLAGS -O2)
-
-    add_library(vulkan-${MAJOR} SHARED ${LOADER_SRCS} dirent_on_windows.c ${CMAKE_CURRENT_BINARY_DIR}/vulkan-${MAJOR}.def)
+    # Build dev_ext_trampoline.c with -O2 to allow tail-call optimization.
+    # Build other C files with normal options
+    # setup two Cmake targets (loader-norm and loader-opt) for the different compilation flags
+    separate_arguments(LOCAL_C_FLAGS_DBG WINDOWS_COMMAND ${CMAKE_C_FLAGS_DEBUG})
+    set(CMAKE_C_FLAGS_DEBUG " ")
+    separate_arguments(LOCAL_C_FLAGS_REL WINDOWS_COMMAND ${CMAKE_C_FLAGS_RELEASE})
+
+    add_library(loader-norm OBJECT ${NORMAL_LOADER_SRCS} dirent_on_windows.c)
+    target_compile_options(loader-norm PUBLIC "$<$<CONFIG:DEBUG>:${LOCAL_C_FLAGS_DBG}>")
+    add_library(loader-opt OBJECT ${OPT_LOADER_SRCS})
+    target_compile_options(loader-opt PUBLIC "$<$<CONFIG:DEBUG>:${LOCAL_C_FLAGS_REL}>")
+    add_library(vulkan-${MAJOR} SHARED $<TARGET_OBJECTS:loader-opt> $<TARGET_OBJECTS:loader-norm> ${CMAKE_CURRENT_BINARY_DIR}/vulkan-${MAJOR}.def)
     set_target_properties(vulkan-${MAJOR} PROPERTIES LINK_FLAGS "/DEF:${CMAKE_CURRENT_BINARY_DIR}/vulkan-${MAJOR}.def")
-    add_library(VKstatic.${MAJOR} STATIC ${LOADER_SRCS} dirent_on_windows.c)
+    add_library(VKstatic.${MAJOR} STATIC $<TARGET_OBJECTS:loader-opt> $<TARGET_OBJECTS:loader-norm>)
     set_target_properties(VKstatic.${MAJOR} PROPERTIES OUTPUT_NAME VKstatic.${MAJOR})
     target_link_libraries(vulkan-${MAJOR} shlwapi)
 else()