Skip to content
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

[cmake] Export config properly #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
34 changes: 2 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CMAKE_MINIMUM_REQUIRED (VERSION 3.6)
project(IfcPlusPlus)
project(IFCPP LANGUAGES CXX)

# Set a default build type if none was specified https://blog.kitware.com/cmake-and-the-default-build-type/
set(default_build_type "Release")
Expand All @@ -12,9 +12,8 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

project(IFCPP)
Copy link
Author

Choose a reason for hiding this comment

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

I've merged this with previous project. There's no reason to do this twice with different names.

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "------------------------------------------------------------------------")

option(BUILD_CONSOLE_APPLICATION "Build an example CLI application" ON)
Expand All @@ -38,37 +37,8 @@ ELSE(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
ENDIF(NOT WIN32)

set(IFCPP_CONFIG_DIR "share/IFCPP/cmake")
ADD_SUBDIRECTORY (IfcPlusPlus)

# Install configuration file
#INCLUDE(CMakePackageConfigHelpers)
#set(config_file_input "${CMAKE_CURRENT_SOURCE_DIR}/cmake/IFCPPConfig.cmake.in")
#set(config_file_output "${CMAKE_CURRENT_BINARY_DIR}/cmake/IFCPPConfig.cmake")

#CONFIGURE_PACKAGE_CONFIG_FILE(
# ${config_file_input}
# ${config_file_output}
# INSTALL_DESTINATION ${IFCPP_CONFIG_DIR})

#INSTALL(
# FILES ${config_file_output}
# DESTINATION ${IFCPP_CONFIG_DIR})

#install(
# DIRECTORY src/ifcpp
# DESTINATION include
# FILES_MATCHING PATTERN "*.h"
#)

#install(
# TARGETS IfcPlusPlus
#EXPORT IfcPlusPlus
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION bin
# ARCHIVE DESTINATION bin
#)

IF(BUILD_CONSOLE_APPLICATION)
ADD_SUBDIRECTORY (examples/CreateIfcWallAndWriteFile)
ADD_SUBDIRECTORY (examples/LoadFileExample)
Expand Down
48 changes: 30 additions & 18 deletions IfcPlusPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
cmake_minimum_required (VERSION 3.6...3.9)
project(IfcPlusPlus)
project(IfcPlusPlus LANGUAGES CXX)

ADD_DEFINITIONS(-DIFCQUERY_STATIC_LIB)
ADD_DEFINITIONS(-DIFCQUERY_LIB)
Copy link
Author

Choose a reason for hiding this comment

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

-DIFCQUERY_LIB is required for dynamic builds.

ADD_DEFINITIONS(-D_HAS_AUTO_PTR_ETC=1)
ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_UNICODE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD C++17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(WIN32)
Expand Down Expand Up @@ -75,9 +74,14 @@ if (MSVC)
set_source_files_properties(src/ifcpp/IFC4X3/TypeFactory.cpp PROPERTIES COMPILE_FLAGS /bigobj)
endif()

add_library(IfcPlusPlus STATIC ${IFCPP_SOURCE_FILES})
add_library(IfcPlusPlus ${IFCPP_SOURCE_FILES})
Copy link
Author

Choose a reason for hiding this comment

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

Default is STATIC unless BUILD_SHARED_LIBS is ON - no change of behavior here.


if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(IfcPlusPlus PUBLIC IFCQUERY_STATIC_LIB)
endif()

TARGET_INCLUDE_DIRECTORIES(IfcPlusPlus
PUBLIC "$<INSTALL_INTERFACE:include;include/ifcpp/IFC4X3/include;include/ifcpp/external>"
Copy link
Author

Choose a reason for hiding this comment

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

This is required for proper INTERFACE_INCLUDE_DIRECTORIES in exported cmake config.

PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${IFCPP_SOURCE_DIR}/IfcPlusPlus/src
Expand Down Expand Up @@ -107,24 +111,32 @@ install(
DESTINATION include
FILES_MATCHING PATTERN "*.h"
)

# Install cmake config

set(IFCPP_CONFIG_DIR "share/IFCPP")

install(
TARGETS IfcPlusPlus
EXPORT IfcPlusPlus
EXPORT IFCPPTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
Copy link
Author

Choose a reason for hiding this comment

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

LIBRARY and ARCHIVE target should really be in lib.

ARCHIVE DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

set(target_output_filename IfcPlusPlus-targets.cmake)
set(target_output "${CMAKE_BINARY_DIR}/cmake/${target_output_filename}")

export(
EXPORT IfcPlusPlus
FILE ${target_output}
NAMESPACE IFCPP::)
install(
EXPORT IFCPPTargets
DESTINATION "${IFCPP_CONFIG_DIR}"
NAMESPACE IFCPP::
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/IFCPPConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/IFCPPConfig.cmake"
INSTALL_DESTINATION "${IFCPP_CONFIG_DIR}"
)
install(
EXPORT IfcPlusPlus
DESTINATION ${IFCPP_CONFIG_DIR}
FILE ${target_output_filename}
NAMESPACE IFCPP::)
FILES "${CMAKE_CURRENT_BINARY_DIR}/IFCPPConfig.cmake"
DESTINATION "${IFCPP_CONFIG_DIR}"
)
3 changes: 3 additions & 0 deletions IfcPlusPlus/IFCPPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/IFCPPTargets.cmake")