Skip to content

Commit

Permalink
build: add nested cmake lists for cpu and common
Browse files Browse the repository at this point in the history
  • Loading branch information
echeresh committed Mar 18, 2019
1 parent e6c7304 commit 5ec065c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 30 deletions.
35 changes: 5 additions & 30 deletions src/CMakeLists.txt
Expand Up @@ -19,17 +19,9 @@ file(GLOB_RECURSE HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/../include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/*.hpp
)
file(GLOB_RECURSE SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu/*.c
)
include_directories(
${PROJECT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/common
${CMAKE_CURRENT_SOURCE_DIR}/cpu
${CMAKE_CURRENT_SOURCE_DIR}/cpu/xbyak
)

# propagate SRC specific flags
Expand Down Expand Up @@ -71,29 +63,12 @@ if(WIN32)
endif()
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# to make computations more stable and to align the jitted code
# with the reference one use precise division and square root
# by default
file(GLOB FILES_REQUIRED_PREC_SQRT
${CMAKE_CURRENT_SOURCE_DIR}/cpu/*normalization*.cpp)
file(GLOB FILES_REQUIRED_PREC_DIV
${CMAKE_CURRENT_SOURCE_DIR}/cpu/*normalization*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu/ref_rnn.cpp)
if(WIN32)
set_source_files_properties(${FILES_REQUIRED_PREC_SQRT}
PROPERTIES COMPILE_FLAGS "/Qprec-sqrt")
set_source_files_properties(${FILES_REQUIRED_PREC_DIV}
PROPERTIES COMPILE_FLAGS "/Qprec-div")
else()
set_source_files_properties(${FILES_REQUIRED_PREC_SQRT}
PROPERTIES COMPILE_FLAGS "-prec-sqrt")
set_source_files_properties(${FILES_REQUIRED_PREC_DIV}
PROPERTIES COMPILE_FLAGS "-prec-div")
endif()
endif()
add_subdirectory(common)
add_subdirectory(cpu)

add_library(${LIB_NAME}
${MKLDNN_LIBRARY_TYPE} ${HEADERS} ${${LIB_NAME}_SUB_OBJS})

add_library(${LIB_NAME} ${MKLDNN_LIBRARY_TYPE} ${HEADERS} ${SOURCES})
set_property(TARGET ${LIB_NAME} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${LIB_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${LIB_NAME} PROPERTY VERSION "${PROJECT_VERSION}.0")
Expand Down
27 changes: 27 additions & 0 deletions src/common/CMakeLists.txt
@@ -0,0 +1,27 @@
#===============================================================================
# Copyright 2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================

file(GLOB_RECURSE SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/*.c
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)

set(OBJ_LIB ${LIB_NAME}_common)
add_library(${OBJ_LIB} OBJECT ${SOURCES})
set(${LIB_NAME}_SUB_OBJS ${${LIB_NAME}_SUB_OBJS}
$<TARGET_OBJECTS:${OBJ_LIB}> PARENT_SCOPE)
54 changes: 54 additions & 0 deletions src/cpu/CMakeLists.txt
@@ -0,0 +1,54 @@
#===============================================================================
# Copyright 2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================

file(GLOB_RECURSE SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/*.c
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/xbyak
)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# to make computations more stable and to align the jitted code
# with the reference one use precise division and square root
# by default
file(GLOB FILES_REQUIRED_PREC_SQRT
${CMAKE_CURRENT_SOURCE_DIR}/*normalization*.cpp)
file(GLOB FILES_REQUIRED_PREC_DIV
${CMAKE_CURRENT_SOURCE_DIR}/*normalization*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ref_rnn.cpp)
if(WIN32)
set_source_files_properties(${FILES_REQUIRED_PREC_SQRT}
PROPERTIES COMPILE_FLAGS "/Qprec-sqrt")
set_source_files_properties(${FILES_REQUIRED_PREC_DIV}
PROPERTIES COMPILE_FLAGS "/Qprec-div")
else()
set_source_files_properties(${FILES_REQUIRED_PREC_SQRT}
PROPERTIES COMPILE_FLAGS "-prec-sqrt")
set_source_files_properties(${FILES_REQUIRED_PREC_DIV}
PROPERTIES COMPILE_FLAGS "-prec-div")
endif()
endif()

set(OBJ_LIB ${LIB_NAME}_cpu)
add_library(${OBJ_LIB} OBJECT ${SOURCES})
set(${LIB_NAME}_SUB_OBJS ${${LIB_NAME}_SUB_OBJS}
$<TARGET_OBJECTS:${OBJ_LIB}> PARENT_SCOPE)

0 comments on commit 5ec065c

Please sign in to comment.