Skip to content

Commit

Permalink
build: win: add windows support to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
msotoflo committed Jun 12, 2017
1 parent 39274b1 commit 095d412
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,30 @@ if(UNIX OR APPLE)
endif()
endif()

set(OPENMP_FLAGS "-fopenmp")
if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
# Current implementation - OpenMP: sequential code
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} /Qopenmp_stubs")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} /Qopenmp_stubs")
elseif(UNIX OR APPLE)
set(OPENMP_FLAGS "-fopenmp")
endif()

if(HAVE_MKL)
set(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -liomp5 -Wl,--as-needed")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -liomp5 -Wl,--as-needed")
endif()
set(CCXX_WARN_FLAGS "-Wall -Werror -Wno-unknown-pragmas")

set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} ${OPENMP_FLAGS} ${CCXX_WARN_FLAGS} -DMKLDNN_DLL -DMKLDNN_DLL_EXPORTS -fvisibility=internal")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CCXX_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CCXX_FLAGS} -std=c++11 -fvisibility-inlines-hidden")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
if(UNIX OR APPLE)
set(CCXX_WARN_FLAGS "-Wall -Werror -Wno-unknown-pragmas")
endif()

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -xHOST")
endif()

Expand Down
8 changes: 6 additions & 2 deletions cmake/MKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ function(detect_mkl LIBNAME)
endif()
endfunction()

detect_mkl("libmklml_intel.so")
detect_mkl("libmkl_rt.so")
if(WIN32)
detect_mkl("mklml")
elseif(UNIX)
detect_mkl("libmklml_intel.so")
detect_mkl("libmkl_rt.so")
endif()

set(FAIL_WITHOUT_MKL)

Expand Down
8 changes: 8 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ add_test(simple-net-cpp simple-net-cpp)

add_executable(simple-training-net-c simple_training_net.c)
set_property(TARGET simple-training-net-c PROPERTY C_STANDARD 99)
if(WIN32)
target_link_libraries(simple-training-net-c ${LIB_NAME})
else()
target_link_libraries(simple-training-net-c ${LIB_NAME} m)
endif()
add_test(simple-training-net-c simple-training-net-c)

add_executable(simple-training-net-cpp simple_training_net.cpp)
set_property(TARGET simple-training-net-cpp PROPERTY CXX_STANDARD 11)
if(WIN32)
target_link_libraries(simple-training-net-cpp ${LIB_NAME})
else()
target_link_libraries(simple-training-net-cpp ${LIB_NAME} m)
endif()
add_test(simple-training-net-cpp simple-training-net-cpp)
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/common
${CMAKE_CURRENT_SOURCE_DIR}/cpu/xbyak
)

if(WIN32)
add_definitions(-D_WIN)
add_definitions(-DNOMINMAX)
# Correct 'jnl' macro/jit issue
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qlong-double")
endif()
endif()

add_library(${TARGET_NAME} SHARED ${HEADERS} ${SOURCES})
target_link_libraries(${TARGET_NAME} ${${TARGET_NAME}_LINKER_LIBS})
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 11)
Expand Down
25 changes: 15 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ set_property(TARGET api-c PROPERTY C_STANDARD 99)
target_link_libraries(api-c ${LIB_NAME})
add_test(api-c api-c)

set(test_c_symbols "${CMAKE_CURRENT_BINARY_DIR}/test_c_symbols.c")
add_executable(test_c_symbols-c ${test_c_symbols})
add_custom_command(
OUTPUT ${test_c_symbols}
COMMAND /bin/bash ${CMAKE_CURRENT_SOURCE_DIR}/generate_c_symbols_refs.sh
${CMAKE_CURRENT_SOURCE_DIR}/.. ${test_c_symbols}
)
target_link_libraries(test_c_symbols-c ${LIB_NAME})

add_test(test_c_symbols-c test_c_symbols-c)
if(UNIX OR APPLE)
set(test_c_symbols "${CMAKE_CURRENT_BINARY_DIR}/test_c_symbols.c")
add_executable(test_c_symbols-c ${test_c_symbols})
add_custom_command(
OUTPUT ${test_c_symbols}
COMMAND /bin/bash ${CMAKE_CURRENT_SOURCE_DIR}/generate_c_symbols_refs.sh
${CMAKE_CURRENT_SOURCE_DIR}/.. ${test_c_symbols}
)
target_link_libraries(test_c_symbols-c ${LIB_NAME})
add_test(test_c_symbols-c test_c_symbols-c)
# elseif(WIN32)
# No Windows support for: test_c_symbols.c
endif()





Expand Down

0 comments on commit 095d412

Please sign in to comment.