Skip to content

Add CMAKE install target #988

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

Merged
merged 9 commits into from
Nov 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ set(NO_LAPACK 1)
set(NO_LAPACKE 1)
endif()

if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
if(CMAKE_CONFIGURATION_TYPES) # multiconfig generator?
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE
Debug Debug
Release Release
)
else()
set(CMAKE_BUILD_TYPE Release)
if( NOT CMAKE_BUILD_TYPE )
if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
else()
set(CMAKE_BUILD_TYPE Release)
endif()
endif()
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAKE_BUILD_TYPE should control debug/release builds, not the other way around, by the way this needs to be set in the cache before the project command if not already defined

Copy link
Collaborator Author

@martin-frbg martin-frbg Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is xianyi's code from 7ac7e14, the patch only changed the indentation here.
I take it this evaluation of BUILD_DEBUG should be removed completely ?

Copy link
Collaborator Author

@martin-frbg martin-frbg Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More to the point, should this block become something like
if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE Release)
endif()
if (CMAKE_BUILD_TYPE = Debug)
set (DEBUG_POSTFIX "_d")
set(OpenBLAS_LIBNAME "${OpenBLAS_LIBNAME}_d")
else()
set (DEBUG_POSTFIX "")
endif()
which would also consolidate the definitions of DEBUG_POSTFIX as in your other comment ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reworked the PR now to query BUILD_DEBUG only if CMAKE_BUILD_TYPE is not set, and moved the conditional appending of a debug prefix to use the cmake-provided setting.
(Apologies again for the mess of incremental commits to the same file, I was working via the web interface and do not see a means of squashing the commit history there)


if(BUILD_WITHOUT_CBLAS)
Expand Down Expand Up @@ -141,8 +151,11 @@ include("${PROJECT_SOURCE_DIR}/cmake/export.cmake")

# Set output for libopenblas
set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_NAME_DEBUG "${OpenBLAS_LIBNAME}_d")

foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )

set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
set_target_properties( ${OpenBLAS_LIBNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/lib)
Expand All @@ -152,14 +165,15 @@ enable_testing()
add_subdirectory(utest)

if(NOT MSVC)
#only build shared library for MSVC
add_library(${OpenBLAS_LIBNAME}_static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS})
set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES OUTPUT_NAME ${OpenBLAS_LIBNAME})
set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)

if(SMP)
target_link_libraries(${OpenBLAS_LIBNAME} pthread)
target_link_libraries(${OpenBLAS_LIBNAME}_static pthread)
#only build shared library for MSVC

add_library(${OpenBLAS_LIBNAME}_static STATIC ${LA_SOURCES} ${LAPACKE_SOURCES} ${TARGET_OBJS})
set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES OUTPUT_NAME ${OpenBLAS_LIBNAME})
set_target_properties(${OpenBLAS_LIBNAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)

if(SMP)
target_link_libraries(${OpenBLAS_LIBNAME} pthread)
target_link_libraries(${OpenBLAS_LIBNAME}_static pthread)
endif()

#build test and ctest
Expand Down Expand Up @@ -198,3 +212,18 @@ set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
#endif
# @touch lib.grd

# Install project

# Install libraries
install(TARGETS ${OpenBLAS_LIBNAME}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib )

# Install include files
FILE(GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
install (FILES ${INCLUDE_FILES} DESTINATION include)

if(NOT MSVC)
install (TARGETS ${OpenBLAS_LIBNAME}_static DESTINATION lib)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEBUG_POSTFIX is already defined earlier, the install could be moved there to avoid duplicate code