Skip to content

Commit

Permalink
Merge pull request #1 from reyoung/mac_port
Browse files Browse the repository at this point in the history
revise CMake for MAC OS
  • Loading branch information
gangliao authored Sep 12, 2016
2 parents eb5cf64 + 738b689 commit 4315a38
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ find_package(CUDA QUIET)
find_package(Protobuf REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)
find_package(PythonInterp 2.7 REQUIRED)
find_package(ZLIB REQUIRED)
find_package(NumPy)
find_package(Threads REQUIRED)
find_package(Glog)
Expand Down
4 changes: 2 additions & 2 deletions cmake/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ set(COMMON_FLAGS
-fPIC
-fno-omit-frame-pointer
-Wall
# -Wextra
# -Werror
-Wextra
-Werror
-Wnon-virtual-dtor
-Wdelete-non-virtual-dtor
-Wno-unused-parameter
Expand Down
70 changes: 42 additions & 28 deletions cmake/util.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# MAC OS does not contain start-up and whole-archive args
if(APPLE)
set(GROUP_START "")
set(GROUP_END "")

set(ARCHIVE_START "")
set(ARCHIVE_END "")
else()
set(GROUP_START "-Wl,--start-group")
set(GROUP_END "-Wl,--end-group")

set(ARCHIVE_START "-Wl,--whole-archive")
set(ARCHIVE_END "-Wl,--no-whole-archive")
endif()


# Some common routine for paddle compile.

# target_circle_link_libraries
Expand All @@ -23,17 +7,46 @@ endif()
# Rest Arguments: libraries which link together.
function(target_circle_link_libraries TARGET_NAME)
if(APPLE)
set(LIBS)
set(inArchive OFF)
set(libsInArgn)

foreach(arg ${ARGN})
list(APPEND OSX_LIBRARIES "-Wl,-force_load" "${arg}")
if(${arg} STREQUAL "ARCHIVE_START")
set(inArchive ON)
elseif(${arg} STREQUAL "ARCHIVE_END")
set(inArchive OFF)
else()
if(inArchive)
list(APPEND LIBS "-Wl,-force_load")
endif()
list(APPEND LIBS ${arg})
list(APPEND libsInArgn ${arg})
endif()
endforeach()

list(REVERSE libsInArgn)
target_link_libraries(${TARGET_NAME}
${OSX_LIBRARIES} -lz)
else()
${LIBS}
${libsInArgn})

else() # LINUX
set(LIBS)

foreach(arg ${ARGN})
if(${arg} STREQUAL "ARCHIVE_START")
list(APPEND LIBS "-Wl,--whole-archive")
elseif(${arg} STREQUAL "ARCHIVE_END")
list(APPEND LIBS "-Wl,--no-whole-archive")
else()
list(APPEND LIBS ${arg})
endif()
endforeach()

target_link_libraries(${TARGET_NAME}
${GROUP_START}
${ARGN}
-lz
${GROUP_END})
"-Wl,--start-group"
${LIBS}
"-Wl,--end-group")
endif()
endfunction()

Expand Down Expand Up @@ -65,20 +78,20 @@ function(link_paddle_exe TARGET_NAME)
if(PADDLE_WITH_INTERNAL)
set(INTERAL_LIBS paddle_internal_gserver paddle_internal_parameter)
target_circle_link_libraries(${TARGET_NAME}
${ARCHIVE_START}
ARCHIVE_START
paddle_internal_gserver
paddle_internal_owlqn
${ARCHIVE_END}
ARCHIVE_END
paddle_internal_parameter)
else()
set(INTERAL_LIBS "")
endif()

target_circle_link_libraries(${TARGET_NAME}
${ARCHIVE_START}
ARCHIVE_START
paddle_gserver
${METRIC_LIBS}
${ARCHIVE_END}
ARCHIVE_END
paddle_pserver
paddle_trainer_lib
paddle_network
Expand All @@ -92,7 +105,8 @@ function(link_paddle_exe TARGET_NAME)
${CMAKE_THREAD_LIBS_INIT}
${CBLAS_LIBS}
${CMAKE_DL_LIBS}
${INTERAL_LIBS})
${INTERAL_LIBS}
${ZLIB_LIBRARIES})

if(WITH_PYTHON)
target_link_libraries(${TARGET_NAME}
Expand Down

0 comments on commit 4315a38

Please sign in to comment.