diff --git a/CMakeLists.txt b/CMakeLists.txt index 77e3712..42de8a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,20 @@ cmake_minimum_required(VERSION 3.18) project(libprof VERSION 2.2.1 LANGUAGES C) - find_package(Gint 2.2.1 REQUIRED) -add_compile_options(-Wall -Wextra -std=c11 -Os) -include_directories("${CMAKE_CURRENT_SOURCE_DIR}") +configure_file(libprof.h libprof.h) set(NAME "prof-${FXSDK_PLATFORM}") -add_library("${NAME}" STATIC libprof.c) -target_link_libraries("${NAME}" Gint::Gint) +add_library(${NAME} STATIC libprof.c) -install(TARGETS "${NAME}" DESTINATION "${FXSDK_COMPILER_INSTALL}") -install(FILES libprof.h DESTINATION "${FXSDK_COMPILER_INSTALL}/include") +target_compile_options(${NAME} PUBLIC -Wall -Wextra -std=c11 -Os) +target_include_directories(${NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") +target_link_libraries(${NAME} Gint::Gint) +install(TARGETS ${NAME} + DESTINATION "${FXSDK_COMPILER_INSTALL}") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprof.h" + DESTINATION "${FXSDK_COMPILER_INSTALL}/include") +install(FILES cmake/FindLibProf.cmake + DESTINATION "${FXSDK_CMAKE_MODULE_PATH}") diff --git a/cmake/FindLibProf.cmake b/cmake/FindLibProf.cmake new file mode 100644 index 0000000..eaa5c79 --- /dev/null +++ b/cmake/FindLibProf.cmake @@ -0,0 +1,16 @@ +include(FindSimpleLibrary) +include(FindPackageHandleStandardArgs) + +find_simple_library("libprof-${FXSDK_PLATFORM}.a" include/libprof.h + "PROF_VERSION" PATH_VAR PROF_PATH VERSION_VAR PROF_VERSION) + +find_package_handle_standard_args(LibProf + REQUIRED_VARS PROF_PATH PROF_VERSION + VERSION_VAR PROF_VERSION) + +if(LibProf_FOUND) + add_library(LibProf::LibProf UNKNOWN IMPORTED) + set_target_properties(LibProf::LibProf PROPERTIES + IMPORTED_LOCATION "${PROF_PATH}" + INTERFACE_LINK_OPTIONS -lprof-${FXSDK_PLATFORM}) +endif() diff --git a/libprof.h b/libprof.h index 2dd0db4..9ce1674 100644 --- a/libprof.h +++ b/libprof.h @@ -8,6 +8,9 @@ #include #include +/* This is substituted by CMake at compile-time */ +#define PROF_VERSION "@libprof_VERSION@" + //--- // Initialization //---