1
0
mirror of https://github.com/preble/libpinproc synced 2026-02-24 18:25:23 +01:00

Additional tweaks for MSVC DLL's

This commit is contained in:
Gerry Stellenberg
2011-01-16 09:36:26 -06:00
parent 9af691d70a
commit aa1d3649ba

View File

@@ -1,191 +1,236 @@
### ###
### CMake policy settings ### CMake settings
### ###
# see http://www.cmake.org/Wiki/CMake_Policies # see http://www.cmake.org/Wiki/CMake_Policies
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015 # see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015
if(POLICY CMP0015) if(POLICY CMP0015)
cmake_policy(SET CMP0015 NEW) cmake_policy(SET CMP0015 NEW)
endif() endif()
#
INCLUDE(CMakeDependentOption)
###
### Project settings
### ###
project(PINPROC) ### Project settings
###
set(PINPROC_VERSION_MAJOR "0") project(PINPROC)
set(PINPROC_VERSION_MINOR "9")
set(PINPROC_VERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}") set(PINPROC_VERSION_MAJOR "0")
set(PINPROC_VERSION_MINOR "9")
set(PINPROC_VERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}")
###
### Project options
### ###
# General stuff ### Project options
option(PINPROC_BUILD_TOOLS "Enable testing and firmware tools" ON) ###
# General stuff
# Compilation options option(PINPROC_BUILD_TOOLS "Enable testing and firmware tools" ON)
# see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS
# http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library # Compilation options
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) # see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS
# see http://msdn.microsoft.com/en-us/library/aa278396(v=vs.60).aspx # http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library
# http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=VS.71%29.aspx option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON) # see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx
option(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF) # http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx
option(MSVC_SHARED_RT "MSVC: Build with shared runtime libs (/MD)" ON)
CMAKE_DEPENDENT_OPTION(MSVC_STHREADED_RT "MSVC: Build with single-threaded static runtime libs (/ML until VS .NET 2003)" OFF
### "NOT MSVC_SHARED_RT" OFF)
### Source
###
# !!! file(GLOB) didn't work on Ubuntu 10.04 with cmake 2.8 !!! ###
#file(GLOB sources src/[a-z]*.cpp) ### Sources, headers, directories and libs
#file(GLOB public_headers include/[a-z]*.h) ###
#file(GLOB private_headers src/[a-z]*.h) # !!! file(GLOB) didn't work on Ubuntu 10.04 with cmake 2.8 !!!
set(sources "src/pinproc.cpp;src/PRDevice.cpp;src/PRHardware.cpp") #file(GLOB sources src/[a-z]*.cpp)
set(public_headers "include/pinproc.h") #file(GLOB public_headers include/[a-z]*.h)
set(private_headers "src/PRCommon.h;src/PRDevice.h;src/PRHardware.h") #file(GLOB private_headers src/[a-z]*.h)
message(STATUS "sources is ${sources}") #message(STATUS "sources: ${sources}")
message(STATUS "public_headers is ${public_headers}") #message(STATUS "public_headers: ${public_headers}")
message(STATUS "private_headers is ${private_headers}") #message(STATUS "private_headers: ${private_headers}")
set(sources "src/pinproc.cpp;src/PRDevice.cpp;src/PRHardware.cpp")
include_directories(${PINPROC_SOURCE_DIR}/include $ENV{EXTRA_INC} /usr/local/include) set(public_headers "include/pinproc.h")
link_directories($ENV{EXTRA_LINK} /usr/local/lib) set(private_headers "src/PRCommon.h;src/PRDevice.h;src/PRHardware.h")
# use -DEXTRA_INC="<path>;<path>" and -DEXTRA_LINK="<path>;<path>"
### include_directories(${PINPROC_SOURCE_DIR}/include ${EXTRA_INC} /usr/local/include)
### General compilation settings link_directories(${EXTRA_LINK} /usr/local/lib)
###
if(APPLE) set(YAML_CPP_LIB "yaml-cpp")
# set(CMAKE_OSX_ARCHITECTURES ppc;i386) # Uncomment for universal binary set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}")
endif()
if(WIN32) ###
set(libraries ftd2xx) ### General compilation settings
if(BUILD_SHARED_LIBS) ###
add_definitions(-DPINPROC_DLL) # use or build Windows DLL if(BUILD_SHARED_LIBS)
endif() set(LABEL_SUFFIX "shared")
else() else()
set(libraries usb ftdi) set(LABEL_SUFFIX "static")
endif() endif()
set(YAML_CPP_LIB "yaml-cpp") if(APPLE)
set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}") # set(CMAKE_OSX_ARCHITECTURES ppc;i386) # Uncomment for universal binary
endif()
### if(WIN32)
### General install settings set(lib_ftdi_usb ftd2xx)
### if(BUILD_SHARED_LIBS)
if(WIN32) add_definitions(-D${PROJECT_NAME}_DLL) # use or build Windows DLL
set(_library_dir bin) # .dll are in PATH, like executables endif()
else() else()
set(_library_dir lib) set(lib_ftdi_usb usb ftdi)
endif() endif()
set(INCLUDE_INSTALL_DIR include/p-roc) # GCC / MINGW specialities
set(LIB_INSTALL_DIR ${_library_dir}${LIB_SUFFIX}) if(CMAKE_COMPILER_IS_GNUCC)
if(WIN32)
set(_INSTALL_DESTINATIONS set(CMAKE_SHARED_LIBRARY_PREFIX "") # DLLs do not have a "lib" prefix
RUNTIME DESTINATION bin set(CMAKE_IMPORT_LIBRARY_PREFIX "") # same for DLL import libs
LIBRARY DESTINATION ${LIB_INSTALL_DIR} endif()
ARCHIVE DESTINATION lib${LIB_SUFFIX} endif()
)
# Microsoft VisualC++ specialities
if(MSVC)
### ### General stuff
### Library # a) Change MSVC runtime library settings (/MD[d], /MT[d], /ML[d] (single-threaded until VS 2003))
### # plus set lib suffix for later use and project label accordingly
add_library(pinproc # see http://msdn.microsoft.com/en-us/library/aa278396(v=VS.60).aspx
${sources} # http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.71).aspx
${public_headers} set(LIB_RT_SUFFIX "md") # CMake defaults to /MD for MSVC
${private_headers} set(LIB_RT_OPTION "/MD")
) #
set_target_properties(pinproc PROPERTIES if(NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
VERSION "${PINPROC_VERSION}" if(MSVC_STHREADED_RT) # User wants to have old single-threaded static runtime libraries
SOVERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}" set(LIB_RT_SUFFIX "ml")
) set(LIB_RT_OPTION "/ML")
if(NOT MSVC_VERSION LESS 1400)
# Correct MSVC for static libraries (/MD[d], /MT[d], /ML[d] (single-threaded until VS 2003)) message(FATAL_ERROR "Single-threaded static runtime libraries (/ML) only available until VS .NET 2003 (7.1).")
# see http://msdn.microsoft.com/en-us/library/aa278396(v=vs.60).aspx endif()
# http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=VS.71%29.aspx else()
if((MSVC) AND (NOT BUILD_SHARED_LIBS)) set(LIB_RT_SUFFIX "mt")
set(TMP_SUFFIX "md") # CMake defaults to /MD for MSVC set(LIB_RT_OPTION "/MT")
endif()
if (NOT MSVC_SHARED_RT) # User wants to have static runtime libraries (/MT, /ML)
if (MSVC_STHREADED_RT) # User wants to have old single-threade runtime libraries # correct linker options
set(TMP_SUFFIX "ml") foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
set(TMP_OPTION "/ML") foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
if(NOT MSVC_VERSION LESS 1400) set(var_name "${flag_var}")
message(FATAL_ERROR "Single-threaded runtime libraries (/ML) only availbe until VS .NET 2003 (7.1).") if(config_name)
endif() set(var_name "${var_name}_${config_name}")
else() endif()
set(TMP_SUFFIX "mt") string(REPLACE "/MD" "${LIB_RT_OPTION}" ${var_name} "${${var_name}}")
set(TMP_OPTION "/MT") endforeach()
endif() endforeach()
endif()
# correct linker options #
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) set(LABEL_SUFFIX "${LABEL_SUFFIX} ${LIB_RT_OPTION}")
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) # b) Change prefix for static libraries
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}) set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # to distinguish static libraries from DLL import libs
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL}) # c) Correct suffixes for static libraries
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) if(NOT BUILD_SHARED_LIBS)
string(REPLACE "/MD" "${TMP_OPTION}" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO}) ### General stuff
endif() set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}")
# correct library names ### Project stuff
set_target_properties(pinproc PROPERTIES PREFIX "lib") # correct external library names
set_target_properties(pinproc PROPERTIES DEBUG_POSTFIX "${TMP_SUFFIX}d") set(YAML_CPP_LIB "${CMAKE_STATIC_LIBRARY_PREFIX}${YAML_CPP_LIB}${LIB_RT_SUFFIX}")
set_target_properties(pinproc PROPERTIES RELEASE_POSTFIX "${TMP_SUFFIX}") set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}d")
set_target_properties(pinproc PROPERTIES MINSIZEREL_POSTFIX "${TMP_SUFFIX}") endif()
set_target_properties(pinproc PROPERTIES RELWITHDEBINFO_POSTFIX "${TMP_SUFFIX}") endif()
# correct external library names
set(YAML_CPP_LIB "lib${YAML_CPP_LIB}${TMP_SUFFIX}")
set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}d") ###
endif() ### General install settings
###
install(TARGETS pinproc ${_INSTALL_DESTINATIONS}) if(WIN32)
install( set(_library_dir bin) # .dll are in PATH, like executables
FILES ${public_headers} else()
DESTINATION ${INCLUDE_INSTALL_DIR} set(_library_dir lib)
) endif()
if(UNIX) set(INCLUDE_INSTALL_DIR include/p-roc)
set(PC_FILE ${CMAKE_BINARY_DIR}/pinproc.pc) set(LIB_INSTALL_DIR "${_library_dir}${LIB_SUFFIX}")
configure_file("pinproc.pc.cmake" ${PC_FILE} @ONLY)
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) set(_INSTALL_DESTINATIONS
endif() RUNTIME DESTINATION bin
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
### )
### Extras
###
#TODO: use add_subdirectory() and separate CMakeLists.txt ###
if(PINPROC_BUILD_TOOLS) ### Library
# Create a target for the test tool (see yaml-cpp) ###
add_executable(pinproctest add_library(pinproc
examples/pinproctest/pinproctest.cpp ${sources}
examples/pinproctest/drivers.cpp ${public_headers}
examples/pinproctest/dmd.cpp ${private_headers}
examples/pinproctest/switches.cpp )
examples/pinproctest/alphanumeric.cpp
) set_target_properties(pinproc PROPERTIES
target_link_libraries(pinproctest VERSION "${PINPROC_VERSION}"
pinproc SOVERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}"
${libraries} PROJECT_LABEL "pinproc ${LABEL_SUFFIX}"
optimized ${YAML_CPP_LIB} )
debug ${YAML_CPP_LIB_DBG}
) target_link_libraries(pinproc
${lib_ftdi_usb}
# Create a target for the firmware tool (see yaml-cpp) )
#TODO: use add_subdirectory() and separate CMakeLists.txt
add_executable(pinprocfw if(MSVC)
utils/pinprocfw/pinprocfw.cpp if(NOT BUILD_SHARED_LIBS)
utils/pinprocfw/lenval.cpp # correct library names
) set_target_properties(pinproc PROPERTIES
target_link_libraries(pinprocfw DEBUG_POSTFIX "${LIB_TARGET_SUFFIX}d"
pinproc RELEASE_POSTFIX "${LIB_TARGET_SUFFIX}"
${libraries} MINSIZEREL_POSTFIX "${LIB_TARGET_SUFFIX}"
) RELWITHDEBINFO_POSTFIX "${LIB_TARGET_SUFFIX}"
endif() )
endif()
endif()
install(TARGETS pinproc ${_INSTALL_DESTINATIONS})
install(
FILES ${public_headers}
DESTINATION ${INCLUDE_INSTALL_DIR}
)
if(UNIX)
set(PC_FILE ${CMAKE_BINARY_DIR}/pinproc.pc)
configure_file("pinproc.pc.cmake" ${PC_FILE} @ONLY)
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
endif()
###
### Extras
###
if(PINPROC_BUILD_TOOLS)
# Create a target for the test tool
#TODO: use add_subdirectory() and separate CMakeLists.txt (see yaml-cpp)
add_executable(pinproctest
examples/pinproctest/pinproctest.cpp
examples/pinproctest/drivers.cpp
examples/pinproctest/dmd.cpp
examples/pinproctest/switches.cpp
examples/pinproctest/alphanumeric.cpp
)
target_link_libraries(pinproctest
pinproc
optimized ${YAML_CPP_LIB}
debug ${YAML_CPP_LIB_DBG}
)
# Create a target for the firmware tool
#TODO: use add_subdirectory() and separate CMakeLists.txt (see yaml-cpp)
add_executable(pinprocfw
utils/pinprocfw/pinprocfw.cpp
utils/pinprocfw/lenval.cpp
)
target_link_libraries(pinprocfw
pinproc
)
endif()